Search in sources :

Example 1 with Route

use of org.springframework.cloud.netflix.zuul.filters.Route in project spring-boot-admin by codecentric.

the class ApplicationRouteLocatorTest method getRoutes_healthOnly.

@Test
public void getRoutes_healthOnly() {
    when(registry.getApplications()).thenReturn(singletonList(Application.create("app1").withHealthUrl("http://localhost/health").withId("1234").build()));
    assertEquals(1, locator.getRoutes().size());
    assertEquals(asList(new Route("1234-health", "/**", "http://localhost/health", "/api/applications/1234/health", false, null)), locator.getRoutes());
    Route matchingRoute = locator.getMatchingRoute("/api/applications/1234/health");
    assertEquals(new Route("1234-health", "", "http://localhost/health", "/api/applications/1234/health", false, null), matchingRoute);
    assertNull(locator.getMatchingRoute("/api/applications/1234/danger"));
}
Also used : Route(org.springframework.cloud.netflix.zuul.filters.Route) Test(org.junit.Test)

Example 2 with Route

use of org.springframework.cloud.netflix.zuul.filters.Route in project spring-boot-admin by codecentric.

the class ApplicationRouteLocatorTest method getRoutes.

@Test
public void getRoutes() {
    when(registry.getApplications()).thenReturn(singletonList(Application.create("app1").withHealthUrl("http://localhost/health").withManagementUrl("http://localhost").withId("1234").build()));
    assertEquals(2, locator.getRoutes().size());
    assertEquals(asList(new Route("1234-health", "/**", "http://localhost/health", "/api/applications/1234/health", false, null), new Route("1234-env", "/**", "http://localhost/env", "/api/applications/1234/env", false, null)), locator.getRoutes());
    Route matchingHealth = locator.getMatchingRoute("/api/applications/1234/health");
    assertEquals(new Route("1234-health", "", "http://localhost/health", "/api/applications/1234/health", false, null), matchingHealth);
    Route matchingEnv = locator.getMatchingRoute("/api/applications/1234/env/reset");
    assertEquals(new Route("1234-env", "/reset", "http://localhost/env", "/api/applications/1234/env", false, null), matchingEnv);
    assertNull(locator.getMatchingRoute("/api/applications/1234/danger"));
}
Also used : Route(org.springframework.cloud.netflix.zuul.filters.Route) Test(org.junit.Test)

Example 3 with Route

use of org.springframework.cloud.netflix.zuul.filters.Route in project spring-boot-admin by codecentric.

the class TurbineRouteLocator method getMatchingRoute.

@Override
public Route getMatchingRoute(String path) {
    Route route = super.getMatchingRoute(path);
    if (route == null) {
        return route;
    }
    String location = route.getLocation();
    if (!(location.startsWith("http:") || location.startsWith("https:"))) {
        location = resolveServiceId(location);
    }
    String targetPath = route.getPath() + "/turbine.stream";
    return new Route(route.getId(), targetPath, location, route.getPrefix(), route.getRetryable(), route.getSensitiveHeaders());
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Route(org.springframework.cloud.netflix.zuul.filters.Route)

Example 4 with Route

use of org.springframework.cloud.netflix.zuul.filters.Route in project spring-boot-admin by codecentric.

the class TurbineRouteLocatorTest method test_route_service_location.

@Test
public void test_route_service_location() {
    ZuulRoute route = new ZuulRoute("/path/**", "turbine");
    DiscoveryClient discovery = mock(DiscoveryClient.class);
    when(discovery.getInstances("turbine")).thenReturn(Arrays.<ServiceInstance>asList(new DefaultServiceInstance("turbine", "example.com", 80, false)));
    TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), discovery);
    Route matchingRoute = locator.getMatchingRoute("/path/foo");
    assertThat(matchingRoute.getLocation(), is("http://example.com:80"));
    assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) DiscoveryClient(org.springframework.cloud.client.discovery.DiscoveryClient) NoopDiscoveryClient(org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient) Route(org.springframework.cloud.netflix.zuul.filters.Route) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Test(org.junit.Test)

Example 5 with Route

use of org.springframework.cloud.netflix.zuul.filters.Route in project spring-boot-admin by codecentric.

the class TurbineRouteLocatorTest method test_route_http_location.

@Test
public void test_route_http_location() {
    ZuulRoute route = new ZuulRoute("/path/**", "http://example.com/target");
    TurbineRouteLocator locator = new TurbineRouteLocator(route, "", new ZuulProperties(), null);
    assertThat(locator.getRoutes().size(), is(1));
    assertThat(locator.getRoutes().get(0).getPath(), is("/**"));
    assertThat(locator.getRoutes().get(0).getPrefix(), is("/path"));
    assertThat(locator.getRoutes().get(0).getLocation(), is("http://example.com/target"));
    Route matchingRoute = locator.getMatchingRoute("/path/foo");
    assertThat(matchingRoute.getLocation(), is("http://example.com/target"));
    assertThat(matchingRoute.getPath(), is("/foo/turbine.stream"));
    assertThat(locator.getMatchingRoute("/404/foo"), nullValue());
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) Route(org.springframework.cloud.netflix.zuul.filters.Route) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) Test(org.junit.Test)

Aggregations

Route (org.springframework.cloud.netflix.zuul.filters.Route)5 Test (org.junit.Test)4 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)3 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)2 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 DiscoveryClient (org.springframework.cloud.client.discovery.DiscoveryClient)1 NoopDiscoveryClient (org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient)1