Update routes endpoint to new endpoint infrastructure.

fixes gh-2318
parent 6f2fc1de
...@@ -1715,7 +1715,7 @@ routes: ...@@ -1715,7 +1715,7 @@ routes:
Additional route details can be requested by adding the `?format=details` query Additional route details can be requested by adding the `?format=details` query
string to `/routes`. This will produce the following output: string to `/routes`. This will produce the following output:
.GET /routes?format=details .GET /routes/details
[source,json] [source,json]
---- ----
{ {
......
...@@ -23,6 +23,7 @@ import java.util.Set; ...@@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator; import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
...@@ -44,6 +45,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; ...@@ -44,6 +45,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
public class RoutesEndpoint implements ApplicationEventPublisherAware { public class RoutesEndpoint implements ApplicationEventPublisherAware {
static final String ID = "routes"; static final String ID = "routes";
static final String FORMAT_DETAILS = "details";
private RouteLocator routes; private RouteLocator routes;
...@@ -84,17 +86,14 @@ public class RoutesEndpoint implements ApplicationEventPublisherAware { ...@@ -84,17 +86,14 @@ public class RoutesEndpoint implements ApplicationEventPublisherAware {
/** /**
* Expose Zuul {@link Route} information with details. * Expose Zuul {@link Route} information with details.
*/ */
//FIXME 2.0.x @ReadOperation
/*@GetMapping(params = "format", produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, public Object invokeRouteDetails(@Selector String format) {
MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public Object invokeRouteDetails(@RequestParam String format) {
if (FORMAT_DETAILS.equalsIgnoreCase(format)) { if (FORMAT_DETAILS.equalsIgnoreCase(format)) {
return endpoint.invokeRouteDetails(); return invokeRouteDetails();
} else { } else {
return super.invoke(); return invoke();
} }
}*/ }
/** /**
* Container for exposing Zuul {@link Route} details as JSON. * Container for exposing Zuul {@link Route} details as JSON.
......
...@@ -21,19 +21,25 @@ package org.springframework.cloud.netflix.zuul; ...@@ -21,19 +21,25 @@ package org.springframework.cloud.netflix.zuul;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator; import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/** /**
* @author Ryan Baxter * @author Ryan Baxter
...@@ -41,7 +47,7 @@ import static org.mockito.Mockito.spy; ...@@ -41,7 +47,7 @@ import static org.mockito.Mockito.spy;
*/ */
@SpringBootTest @SpringBootTest
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class RoutesMvcEndpointTests { public class RoutesEndpointDetailsTests {
private RouteLocator locator; private RouteLocator locator;
private RoutesEndpoint endpoint; private RoutesEndpoint endpoint;
@Mock @Mock
...@@ -73,28 +79,24 @@ public class RoutesMvcEndpointTests { ...@@ -73,28 +79,24 @@ public class RoutesMvcEndpointTests {
@Test @Test
public void reset() throws Exception { public void reset() throws Exception {
//FIXME: 2.0.x this.endpoint.setApplicationEventPublisher(publisher);
/*RoutesMvcEndpoint mvcEndpoint = new RoutesMvcEndpoint(endpoint, locator); Map<String, String> result = new HashMap<>();
mvcEndpoint.setApplicationEventPublisher(publisher);
Map<String, String> result = new HashMap<String, String>();
for(Route r : locator.getRoutes()) { for(Route r : locator.getRoutes()) {
result.put(r.getFullPath(), r.getLocation()); result.put(r.getFullPath(), r.getLocation());
} }
assertEquals(result , mvcEndpoint.reset()); assertEquals(result , endpoint.reset());
verify(endpoint, times(1)).invoke(); verify(endpoint, times(1)).invoke();
verify(publisher, times(1)).publishEvent(isA(RoutesRefreshedEvent.class));*/ verify(publisher, times(1)).publishEvent(isA(RoutesRefreshedEvent.class));
} }
@Test @Test
public void routeDetails() throws Exception { public void routeDetails() throws Exception {
//FIXME: 2.0.x
/*RoutesMvcEndpoint mvcEndpoint = new RoutesMvcEndpoint(endpoint, locator);
Map<String, RoutesEndpoint.RouteDetails> results = new HashMap<>(); Map<String, RoutesEndpoint.RouteDetails> results = new HashMap<>();
for (Route route : locator.getRoutes()) { for (Route route : locator.getRoutes()) {
results.put(route.getFullPath(), new RoutesEndpoint.RouteDetails(route)); results.put(route.getFullPath(), new RoutesEndpoint.RouteDetails(route));
} }
assertEquals(results, mvcEndpoint.invokeRouteDetails(RoutesMvcEndpoint.FORMAT_DETAILS)); assertEquals(results, this.endpoint.invokeRouteDetails(RoutesEndpoint.FORMAT_DETAILS));
verify(endpoint, times(1)).invokeRouteDetails();*/ verify(endpoint, times(1)).invokeRouteDetails();
} }
} }
\ No newline at end of file
...@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.zuul; ...@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.zuul;
import java.util.Map; import java.util.Map;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -60,14 +59,12 @@ public class RoutesEndpointIntegrationTests { ...@@ -60,14 +59,12 @@ public class RoutesEndpointIntegrationTests {
private SimpleZuulProxyApplication.RoutesRefreshListener refreshListener; private SimpleZuulProxyApplication.RoutesRefreshListener refreshListener;
@Test @Test
@Ignore // FIXME: 2.0.x
public void getRoutesTest() { public void getRoutesTest() {
Map<String, String> routes = restTemplate.getForObject("/admin/routes", Map.class); Map<String, String> routes = restTemplate.getForObject("/admin/routes", Map.class);
assertEquals("https://localhost:8443", routes.get("/sslservice/**")); assertEquals("https://localhost:8443", routes.get("/sslservice/**"));
} }
@Test @Test
@Ignore // FIXME: 2.0.x
public void postRoutesTest() { public void postRoutesTest() {
Map<String, String> routes = restTemplate.postForObject("/admin/routes", null, Map.class); Map<String, String> routes = restTemplate.postForObject("/admin/routes", null, Map.class);
assertEquals("https://localhost:8443", routes.get("/sslservice/**")); assertEquals("https://localhost:8443", routes.get("/sslservice/**"));
...@@ -75,10 +72,9 @@ public class RoutesEndpointIntegrationTests { ...@@ -75,10 +72,9 @@ public class RoutesEndpointIntegrationTests {
} }
@Test @Test
@Ignore // FIXME: 2.0.x
public void getRouteDetailsTest() { public void getRouteDetailsTest() {
ResponseEntity<Map<String, RoutesEndpoint.RouteDetails>> responseEntity = restTemplate.exchange( ResponseEntity<Map<String, RoutesEndpoint.RouteDetails>> responseEntity = restTemplate.exchange(
"/admin/routes?format=details", HttpMethod.GET, null, new ParameterizedTypeReference<Map<String, RoutesEndpoint.RouteDetails>>() { "/admin/routes/details", HttpMethod.GET, null, new ParameterizedTypeReference<Map<String, RoutesEndpoint.RouteDetails>>() {
}); });
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK)); assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
......
...@@ -24,13 +24,13 @@ import java.util.Collections; ...@@ -24,13 +24,13 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator; import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* @author Ryan Baxter * @author Ryan Baxter
...@@ -83,16 +83,4 @@ public class RoutesEndpointTests { ...@@ -83,16 +83,4 @@ public class RoutesEndpointTests {
assertEquals(results, endpoint.invokeRouteDetails()); assertEquals(results, endpoint.invokeRouteDetails());
} }
//FIXME 2.0.x
/*@Test
public void testId() {
RoutesEndpoint endpoint = new RoutesEndpoint(locator);
assertEquals("routes", endpoint.getId());
}
@Test
public void testIsSensitive() {
RoutesEndpoint endpoint = new RoutesEndpoint(locator);
assertTrue(endpoint.isSensitive());
}*/
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment