use of com.hotels.styx.routing.RoutingObject in project styx by ExpediaGroup.
the class PathPrefixRouterTest method root_handler_handles_sub_paths.
@Test
public void root_handler_handles_sub_paths() throws Exception {
RoutingObject rootHandler = mock(RoutingObject.class);
routingObjects.put(new StyxObjectReference("rootHandler"), rootHandler);
PathPrefixRouter router = buildRouter(singletonMap("/", "rootHandler"));
testRequestRoute(router, "/", rootHandler);
testRequestRoute(router, "/foo/bar", rootHandler);
}
use of com.hotels.styx.routing.RoutingObject in project styx by ExpediaGroup.
the class PathPrefixRouterTest method buildRouter.
private PathPrefixRouter buildRouter(Map<String, String> prefixRoutes) {
PathPrefixRouter.PrefixRoute[] routes = new PathPrefixRouter.PrefixRoute[prefixRoutes.size()];
int i = 0;
for (Map.Entry<String, String> entry : prefixRoutes.entrySet()) {
String path = entry.getKey();
String route = entry.getValue();
RoutingObject routingObject = requireNonNull(routingObjects.get(new StyxObjectReference(route)), "No reouting object for " + route);
routes[i++] = new PathPrefixRouter.PrefixRoute(path, routingObject);
}
return new PathPrefixRouter(routes);
}
use of com.hotels.styx.routing.RoutingObject in project styx by ExpediaGroup.
the class PathPrefixRouterTest method most_specific_path_is_chosen.
@Test
public void most_specific_path_is_chosen() throws Exception {
RoutingObject rootHandler = mock(RoutingObject.class);
RoutingObject fooFileHandler = mock(RoutingObject.class);
RoutingObject fooPathHandler = mock(RoutingObject.class);
RoutingObject fooBarFileHandler = mock(RoutingObject.class);
RoutingObject fooBarPathHandler = mock(RoutingObject.class);
RoutingObject fooBazFileHandler = mock(RoutingObject.class);
routingObjects.put(new StyxObjectReference("rootHandler"), rootHandler);
routingObjects.put(new StyxObjectReference("fooFileHandler"), fooFileHandler);
routingObjects.put(new StyxObjectReference("fooPathHandler"), fooPathHandler);
routingObjects.put(new StyxObjectReference("fooBarFileHandler"), fooBarFileHandler);
routingObjects.put(new StyxObjectReference("fooBarPathHandler"), fooBarPathHandler);
routingObjects.put(new StyxObjectReference("fooBazFileHandler"), fooBazFileHandler);
PathPrefixRouter router = buildRouter(Map.of("/", "rootHandler", "/foo", "fooFileHandler", "/foo/", "fooPathHandler", "/foo/bar", "fooBarFileHandler", "/foo/bar/", "fooBarPathHandler", "/foo/baz", "fooBazFileHandler"));
testRequestRoute(router, "/", rootHandler);
testRequestRoute(router, "/foo", fooFileHandler);
testRequestRoute(router, "/foo/x", fooPathHandler);
testRequestRoute(router, "/foo/", fooPathHandler);
testRequestRoute(router, "/foo/bar", fooBarFileHandler);
testRequestRoute(router, "/foo/bar/x", fooBarPathHandler);
testRequestRoute(router, "/foo/bar/", fooBarPathHandler);
testRequestRoute(router, "/foo/baz/", fooBazFileHandler);
testRequestRoute(router, "/foo/baz/y", fooBazFileHandler);
}
Aggregations