@Test public void testWildCardMatchingWithQuery() throws Exception { final HttpRequestHandler h1 = Mockito.mock(HttpRequestHandler.class); final HttpRequestHandler h2 = Mockito.mock(HttpRequestHandler.class); final HttpRequestHandler def = Mockito.mock(HttpRequestHandler.class); final UriPatternMatcher<HttpRequestHandler> matcher = Mockito.spy(new UriPatternMatcher<HttpRequestHandler>()); final UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper(matcher); registry.register("*", def); registry.register("*.view", h1); registry.register("*.form", h2); HttpRequestHandler h; h = registry.lookup(new BasicHttpRequest("GET", "/that.view?param=value")); Assert.assertNotNull(h); Assert.assertTrue(h1 == h); h = registry.lookup(new BasicHttpRequest("GET", "/that.form?whatever")); Assert.assertNotNull(h); Assert.assertTrue(h2 == h); h = registry.lookup(new BasicHttpRequest("GET", "/whatever")); Assert.assertNotNull(h); Assert.assertTrue(def == h); }
@Test public void testLookup() throws Exception { final UriPatternMatcher<HttpRequestHandler> matcher = Mockito.spy(new UriPatternMatcher<HttpRequestHandler>()); final UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper(matcher); final HttpRequest request = new BasicHttpRequest("GET", "/"); registry.lookup(request); registry.unregister("/h1"); Mockito.verify(matcher).lookup("/"); }