Update routes endpoint to new endpoint infrastructure.

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