|
| 1 | +/* |
| 2 | + * Copyright 2012-2015 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.test; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.runner.RunWith; |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.boot.test.SpringApplicationIntegrationTestTests.Config; |
| 23 | +import org.springframework.core.env.Environment; |
| 24 | +import org.springframework.test.context.TestPropertySource; |
| 25 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 26 | +import org.springframework.test.context.web.WebAppConfiguration; |
| 27 | + |
| 28 | +import static org.hamcrest.Matchers.equalTo; |
| 29 | +import static org.junit.Assert.assertThat; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests for {@link IntegrationTest} with {@link TestPropertySource} locations. |
| 33 | + * |
| 34 | + * @author Phillip Webb |
| 35 | + */ |
| 36 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 37 | +@SpringApplicationConfiguration(classes = Config.class) |
| 38 | +@WebAppConfiguration |
| 39 | +@IntegrationTest({ "server.port=0", "value1=123" }) |
| 40 | +@TestPropertySource(properties = "value2=456", locations = "classpath:/test-property-source-annotation.properties") |
| 41 | +public class SpringApplicationIntegrationTestPropertyLocationTests { |
| 42 | + |
| 43 | + @Autowired |
| 44 | + private Environment environment; |
| 45 | + |
| 46 | + @Test |
| 47 | + public void loadedProperties() throws Exception { |
| 48 | + assertThat(this.environment.getProperty("value1"), equalTo("123")); |
| 49 | + assertThat(this.environment.getProperty("value2"), equalTo("456")); |
| 50 | + assertThat(this.environment.getProperty("annotation-referenced"), |
| 51 | + equalTo("fromfile")); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments