From 61f2a96c19e225c15e616694999477e8c7ce424d Mon Sep 17 00:00:00 2001 From: Dennis Menge Date: Tue, 23 Jul 2019 19:54:07 +0200 Subject: [PATCH] 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 d5ee4b2d0..ffc69c745 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(); + } } }