Search in sources :

Example 1 with StyxObjectReference

use of com.hotels.styx.routing.config.StyxObjectReference 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);
}
Also used : RoutingObject(com.hotels.styx.routing.RoutingObject) StyxObjectReference(com.hotels.styx.routing.config.StyxObjectReference) Test(org.junit.jupiter.api.Test)

Example 2 with StyxObjectReference

use of com.hotels.styx.routing.config.StyxObjectReference 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);
}
Also used : RoutingObject(com.hotels.styx.routing.RoutingObject) StyxObjectReference(com.hotels.styx.routing.config.StyxObjectReference) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 3 with StyxObjectReference

use of com.hotels.styx.routing.config.StyxObjectReference 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);
}
Also used : RoutingObject(com.hotels.styx.routing.RoutingObject) StyxObjectReference(com.hotels.styx.routing.config.StyxObjectReference) Test(org.junit.jupiter.api.Test)

Aggregations

RoutingObject (com.hotels.styx.routing.RoutingObject)3 StyxObjectReference (com.hotels.styx.routing.config.StyxObjectReference)3 Test (org.junit.jupiter.api.Test)2 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1