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)));
}
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());
}
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();
}
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());
}
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")));
}
Aggregations