Search in sources :

Example 36 with TestDriver

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

the class ContainerSnapshotTestCase method requireThatActiveInjectorIsUsed.

@Test
public void requireThatActiveInjectorIsUsed() {
    final Object obj = new Object();
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Object.class).toInstance(obj);
            bind(String.class).annotatedWith(Names.named("foo")).toInstance("foo");
        }
    });
    ActiveContainer active = new ActiveContainer(driver.newContainerBuilder());
    ContainerSnapshot snapshot = new ContainerSnapshot(active, null, null);
    assertSame(obj, snapshot.getInstance(Object.class));
    assertEquals("foo", snapshot.getInstance(Key.get(String.class, Names.named("foo"))));
    snapshot.release();
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 37 with TestDriver

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

the class ContainerSnapshotTestCase method requireThatClientBindingsAreUsed.

@Test
public void requireThatClientBindingsAreUsed() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.clientBindings().bind("http://host/path", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://host/path"));
    assertNull(request.container().resolveHandler(request));
    request.setServerRequest(false);
    assertNotNull(request.container().resolveHandler(request));
    request.release();
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 38 with TestDriver

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

the class ContainerSnapshotTestCase method requireThatBindingMatchIsSetByResolveHandler.

@Test
public void requireThatBindingMatchIsSetByResolveHandler() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    builder.serverBindings().bind("http://*/*", MyRequestHandler.newInstance());
    driver.activateContainer(builder);
    Request request = new Request(driver, URI.create("http://localhost:69/status.html"));
    assertNotNull(request.container().resolveHandler(request));
    BindingMatch<RequestHandler> match = request.getBindingMatch();
    assertNotNull(match);
    assertEquals(3, match.groupCount());
    assertEquals("localhost", match.group(0));
    assertEquals("69", match.group(1));
    assertEquals("status.html", match.group(2));
    request.release();
    assertTrue(driver.close());
}
Also used : ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 39 with TestDriver

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

the class ContainerSnapshotTestCase method requireThatNewRequestHasSameSnapshot.

@Test
public void requireThatNewRequestHasSameSnapshot() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    driver.activateContainer(driver.newContainerBuilder());
    Request foo = new Request(driver, URI.create("http://host/foo"));
    Request bar = new Request(foo, URI.create("http://host/bar"));
    assertSame(foo.container(), bar.container());
    foo.release();
    bar.release();
    assertTrue(driver.close());
}
Also used : Request(com.yahoo.jdisc.Request) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 40 with TestDriver

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

the class ApplicationLoaderTestCase method requireThatDestroyDoesNotFailWithActiveContainer.

@Test
public void requireThatDestroyDoesNotFailWithActiveContainer() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    assertNull(driver.activateContainer(driver.newContainerBuilder()));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Aggregations

TestDriver (com.yahoo.jdisc.test.TestDriver)134 Test (org.junit.Test)128 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)39 Request (com.yahoo.jdisc.Request)22 Bundle (org.osgi.framework.Bundle)14 AbstractModule (com.google.inject.AbstractModule)13 ByteBuffer (java.nio.ByteBuffer)12 Response (com.yahoo.jdisc.Response)10 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)10 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)6 Executor (java.util.concurrent.Executor)6 LinkedList (java.util.LinkedList)5 BundleContext (org.osgi.framework.BundleContext)4 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ServerProvider (com.yahoo.jdisc.service.ServerProvider)3 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)3 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BundleException (org.osgi.framework.BundleException)3 Module (com.google.inject.Module)2