Search in sources :

Example 1 with NonWorkingRequestHandler

use of com.yahoo.jdisc.test.NonWorkingRequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatSimpleResolutionWorks.

@Test
public void requireThatSimpleResolutionWorks() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/foo"), foo);
    RequestHandler bar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/bar"), bar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host/foo"));
    assertNotNull(match);
    assertEquals(0, match.groupCount());
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host/foo")));
    assertNotNull(match = bindings.match(URI.create("http://host/bar")));
    assertEquals(0, match.groupCount());
    assertSame(bar, match.target());
    assertSame(bar, bindings.resolve(URI.create("http://host/bar")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with NonWorkingRequestHandler

use of com.yahoo.jdisc.test.NonWorkingRequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatPatternResolutionWorks.

@Test
public void requireThatPatternResolutionWorks() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/*"), foo);
    RequestHandler bar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/path"), bar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host/anon"));
    assertNotNull(match);
    assertEquals(1, match.groupCount());
    assertEquals("anon", match.group(0));
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host/anon")));
    assertNotNull(match = bindings.match(URI.create("http://host/path")));
    assertEquals(0, match.groupCount());
    assertSame(bar, match.target());
    assertSame(bar, bindings.resolve(URI.create("http://host/path")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with NonWorkingRequestHandler

use of com.yahoo.jdisc.test.NonWorkingRequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatTreeSplitCanBeBoundForPorts.

@Test
public void requireThatTreeSplitCanBeBoundForPorts() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo8080 = new NonWorkingRequestHandler();
    RequestHandler foo80 = new NonWorkingRequestHandler();
    RequestHandler foobar = new NonWorkingRequestHandler();
    RequestHandler foopqrbar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host:8080/foo"), foo8080);
    handlers.put(new UriPattern("http://host:70/foo"), foo80);
    handlers.put(new UriPattern("http://hostpqr:70/foo"), foopqrbar);
    handlers.put(new UriPattern("http://host:80/foobar"), foobar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    assertNotNull(bindings);
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with NonWorkingRequestHandler

use of com.yahoo.jdisc.test.NonWorkingRequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatTreeWorksForURIWithQueryOrFragments.

@Test
public void requireThatTreeWorksForURIWithQueryOrFragments() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://*/application/v1/session"), foo);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    assertNotNull(bindings);
    assertSame(foo, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v1/session?name=base")));
    assertSame(foo, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v1/session#application")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with NonWorkingRequestHandler

use of com.yahoo.jdisc.test.NonWorkingRequestHandler in project vespa by vespa-engine.

the class BindingSetTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/foo"), foo);
    RequestHandler bar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/bar"), bar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    Iterator<Map.Entry<UriPattern, RequestHandler>> it = bindings.iterator();
    assertNotNull(it);
    assertTrue(it.hasNext());
    Map.Entry<UriPattern, RequestHandler> entry = it.next();
    assertNotNull(entry);
    assertEquals(new UriPattern("http://host/foo"), entry.getKey());
    assertSame(foo, entry.getValue());
    assertTrue(it.hasNext());
    assertNotNull(entry = it.next());
    assertEquals(new UriPattern("http://host/bar"), entry.getKey());
    assertSame(bar, entry.getValue());
    assertFalse(it.hasNext());
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)23 Test (org.junit.Test)23 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)22 LinkedHashMap (java.util.LinkedHashMap)19 Map (java.util.Map)3 BindingSet (com.yahoo.jdisc.application.BindingSet)2 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 TestDriver (com.yahoo.jdisc.test.TestDriver)2 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)1 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)1