diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java index d34b7913..7087d32c 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java @@ -107,7 +107,7 @@ public class ConfigServicePropertySourceLocatorTests { new ByteArrayInputStream("{}".getBytes())); this.locator.setRestTemplate(restTemplate); this.expected.expectCause(IsInstanceOf - . instanceOf(HttpServerErrorException.class)); + .instanceOf(IllegalArgumentException.class)); this.expected.expectMessage("fail fast property is set"); this.locator.locate(this.environment); } @@ -135,7 +135,7 @@ public class ConfigServicePropertySourceLocatorTests { Mockito.when(response.getBody()).thenReturn( new ByteArrayInputStream("".getBytes())); this.locator.setRestTemplate(restTemplate); - this.expected.expectCause(IsNull.nullValue(Throwable.class)); + this.expected.expectCause(IsInstanceOf.instanceOf(IllegalArgumentException.class)); this.expected.expectMessage("fail fast property is set"); this.locator.locate(this.environment); } diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 975c0c16..dc531183 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -44,7 +44,7 @@ UTF-8 sample.Application - 1.7 + 1.8 diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java index 28c056c0..ecde51b8 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java @@ -1,7 +1,5 @@ package sample; -import java.io.IOException; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -15,7 +13,12 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; -import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @RunWith(SpringRunner.class) @@ -23,7 +26,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen // Normally spring.cloud.config.enabled:true is the default but since we have the config // server on the classpath we need to set it explicitly properties = { "spring.cloud.config.enabled:true", - "management.security.enabled=false" }, webEnvironment = RANDOM_PORT) + "management.security.enabled=false", "endpoints.default.web.enabled=true" }, webEnvironment = RANDOM_PORT) public class ApplicationTests { private static int configPort = SocketUtils.findAvailableTcpPort(); @@ -57,10 +60,18 @@ public class ApplicationTests { } @Test + @SuppressWarnings("unchecked") public void contextLoads() { - String foo = new TestRestTemplate() - .getForObject("http://localhost:" + port + "/application/env/info.foo", String.class); - assertEquals("{\"info.foo\":\"bar\"}", foo); + Map res = new TestRestTemplate() + .getForObject("http://localhost:" + port + "/application/env/info.foo", Map.class); + assertThat(res).containsKey("propertySources"); + List> sources = (List>) res.get("propertySources"); + Optional> properties = sources.stream() + .map(map -> (Map) map.get("properties")) + .filter(map -> map.containsKey("info.foo")) + .map(map -> (Map) map.get("info.foo")) + .findFirst(); + assertThat(properties.get()).containsEntry("value", "bar"); } public static void main(String[] args) throws IOException {