From 61f2a96c19e225c15e616694999477e8c7ce424d Mon Sep 17 00:00:00 2001 From: Dennis Menge Date: Tue, 23 Jul 2019 19:54:07 +0200 Subject: [PATCH 1/2] Adds test case for route specific actuator endpoint --- .../GatewayControllerEndpointTests.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java index d5ee4b2d..ffc69c74 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java @@ -27,7 +27,10 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; @@ -61,11 +64,28 @@ public class GatewayControllerEndpointTests { }); } + @Test + public void testGetSpecificRoute() { + testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routes/test-service") + .exchange().expectStatus().isOk().expectBodyList(Map.class) + .consumeWith(result -> { + List responseBody = result.getResponseBody(); + assertThat(responseBody).isNotNull(); + assertThat(responseBody.size()).isEqualTo(1); + assertThat(responseBody).isNotEmpty(); + }); + } + @SpringBootConfiguration @EnableAutoConfiguration @Import(PermitAllSecurityConfiguration.class) static class TestConfig { - + @Bean + RouteLocator testRouteLocator(RouteLocatorBuilder routeLocatorBuilder) { + return routeLocatorBuilder.routes() + .route("test-service", routePredicate -> routePredicate.path("/test-service/**").uri("lb://test-service")) + .build(); + } } } From 807509abfe234568413bb52e6dba399057e2eacd Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Tue, 23 Jul 2019 15:54:12 -0400 Subject: [PATCH 2/2] Runs test with verbose mode --- .../actuate/GatewayControllerEndpointTests.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java index ffc69c74..ff7e7730 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/actuate/GatewayControllerEndpointTests.java @@ -39,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @RunWith(SpringRunner.class) -@SpringBootTest(properties = "management.endpoints.web.exposure.include=*", webEnvironment = RANDOM_PORT) +@SpringBootTest(properties = { "management.endpoints.web.exposure.include=*", + "spring.cloud.gateway.actuator.verbose.enabled=true" }, webEnvironment = RANDOM_PORT) public class GatewayControllerEndpointTests { @Autowired @@ -66,7 +67,8 @@ public class GatewayControllerEndpointTests { @Test public void testGetSpecificRoute() { - testClient.get().uri("http://localhost:" + port + "/actuator/gateway/routes/test-service") + testClient.get() + .uri("http://localhost:" + port + "/actuator/gateway/routes/test-service") .exchange().expectStatus().isOk().expectBodyList(Map.class) .consumeWith(result -> { List responseBody = result.getResponseBody(); @@ -80,12 +82,15 @@ public class GatewayControllerEndpointTests { @EnableAutoConfiguration @Import(PermitAllSecurityConfiguration.class) static class TestConfig { + @Bean RouteLocator testRouteLocator(RouteLocatorBuilder routeLocatorBuilder) { return routeLocatorBuilder.routes() - .route("test-service", routePredicate -> routePredicate.path("/test-service/**").uri("lb://test-service")) + .route("test-service", + r -> r.path("/test-service/**").uri("lb://test-service")) .build(); } + } }