Search in sources :

Example 11 with NonWorkingRequestHandler

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

the class BindingRepositoryTestCase method requireThatPatternCannotBeStolen.

@Test
public void requireThatPatternCannotBeStolen() {
    final String pattern = "http://host/path";
    final RequestHandler originallyBoundHandler = new NonWorkingRequestHandler();
    BindingRepository<Object> bindings = new BindingRepository<>();
    bindings.bind(pattern, originallyBoundHandler);
    bindings.bind(pattern, new PatternStealingRequestHandler());
    BindingSet<?> bindingSet = bindings.activate();
    assertEquals(originallyBoundHandler, bindingSet.resolve(URI.create(pattern)));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Test(org.junit.Test)

Example 12 with NonWorkingRequestHandler

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

the class ServerTestDriverTestCase method requireThatFactoryMethodsWork.

@Test
public void requireThatFactoryMethodsWork() throws ListenFailedException {
    ServerTestDriver driver = ServerTestDriver.newInstance(new NonWorkingRequestHandler());
    assertNotNull(driver);
    assertTrue(driver.close());
    driver = ServerTestDriver.newInstanceWithProtocol(new SimpleProtocol(), new NonWorkingRequestHandler());
    assertNotNull(driver);
    assertTrue(driver.close());
    Slobrok slobrok = new Slobrok();
    driver = ServerTestDriver.newInstanceWithExternSlobrok(slobrok.configId(), new NonWorkingRequestHandler());
    assertNotNull(driver);
    assertTrue(driver.close());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) Slobrok(com.yahoo.jrt.slobrok.server.Slobrok) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Test(org.junit.Test)

Example 13 with NonWorkingRequestHandler

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

the class ActiveContainerTestCase method requireThatClientBindingAccessorWorks.

@Test
public void requireThatClientBindingAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler foo = new NonWorkingRequestHandler();
    RequestHandler bar = new NonWorkingRequestHandler();
    builder.clientBindings().bind("http://host/foo", foo);
    builder.clientBindings("bar").bind("http://host/bar", bar);
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.clientBindings();
    assertNotNull(bindings);
    assertEquals(2, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertNotNull(set);
    Iterator<Map.Entry<UriPattern, RequestHandler>> it = set.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());
    assertFalse(it.hasNext());
    assertNotNull(set = bindings.get("bar"));
    assertNotNull(it = set.iterator());
    assertTrue(it.hasNext());
    assertNotNull(entry = it.next());
    assertEquals(new UriPattern("http://host/bar"), entry.getKey());
    assertSame(bar, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(bindings = container.serverBindings());
    assertEquals(1, bindings.size());
    assertNotNull(set = bindings.get(BindingSet.DEFAULT));
    assertNotNull(it = set.iterator());
    assertFalse(it.hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) UriPattern(com.yahoo.jdisc.application.UriPattern) TestDriver(com.yahoo.jdisc.test.TestDriver) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Map(java.util.Map) Test(org.junit.Test)

Example 14 with NonWorkingRequestHandler

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

the class BindingSetTestCase method requireThatPatternResolutionWorksForWildCards.

@Test
public void requireThatPatternResolutionWorksForWildCards() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host:*/bar"), foo);
    RequestHandler bob = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://*abc:*/*bar"), bob);
    RequestHandler car = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("*://*:21/*"), car);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host:8080/bar"));
    assertNotNull(match);
    assertEquals(1, match.groupCount());
    assertEquals("8080", match.group(0));
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host:8080/bar")));
    match = bindings.match(URI.create("http://host:8080/foo/bar"));
    assertNull(match);
    match = bindings.match(URI.create("http://xyzabc:8080/pqrbar"));
    assertNotNull(match);
    assertSame(bob, match.target());
    match = bindings.match(URI.create("ftp://lmn:21/abc"));
    assertNotNull(match);
    assertSame(car, match.target());
}
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 15 with NonWorkingRequestHandler

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

the class BindingSetTestCase method requireThatTreeSplitCanBeBoundForWildcards.

@Test
public void requireThatTreeSplitCanBeBoundForWildcards() {
    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:708/foo"), foo80);
    handlers.put(new UriPattern("http://host:80/foobar"), foobar);
    handlers.put(new UriPattern("http://hos*:708/foo"), foopqrbar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    assertNotNull(bindings);
    assertSame(foopqrbar, bindings.resolve(URI.create("http://hostabc:708/foo")));
    assertSame(foo80, bindings.resolve(URI.create("http://host:708/foo")));
    assertSame(foo8080, bindings.resolve(URI.create("http://host:8080/foo")));
}
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)

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