Search in sources :

Example 91 with TestDriver

use of com.yahoo.jdisc.test.TestDriver 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 92 with TestDriver

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

the class ActiveContainerTestCase method requireThatDefaultBindingsAreAlwaysCreated.

@Test
public void requireThatDefaultBindingsAreAlwaysCreated() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
    assertNotNull(bindings);
    assertEquals(1, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertFalse(set.iterator().hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 93 with TestDriver

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

the class BundleInstallerIntegrationTest method requireThatUninstallUninstalledThrowsException.

@Test
public void requireThatUninstallUninstalledThrowsException() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance();
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    Bundle bundle = installer.installAndStart("cert-a.jar").get(0);
    assertNotNull(bundle);
    installer.stopAndUninstall(bundle);
    try {
        installer.stopAndUninstall(bundle);
        fail();
    } catch (BundleException e) {
        assertEquals("OSGi bundle com.yahoo.vespa.jdisc_core.cert-a not started.", e.getMessage());
    }
    driver.close();
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 94 with TestDriver

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

the class BundleInstallerIntegrationTest method requireThatApplicationInstructionThrowsException.

@Test
public void requireThatApplicationInstructionThrowsException() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance();
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    try {
        installer.installAndStart("app-a.jar");
        fail();
    } catch (BundleException e) {
        assertEquals("OSGi header 'X-JDisc-Application' not allowed for non-application bundle " + "com.yahoo.vespa.jdisc_core.app-a.", e.getMessage());
    }
    driver.close();
}
Also used : BundleException(org.osgi.framework.BundleException) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 95 with TestDriver

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

the class BundleInstallerIntegrationTest method requireThatInstallAllWorks.

@Test
public void requireThatInstallAllWorks() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance();
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    List<Bundle> bundles = installer.installAndStart("cert-a.jar", "cert-b.jar");
    assertNotNull(bundles);
    assertEquals(2, bundles.size());
    driver.close();
}
Also used : Bundle(org.osgi.framework.Bundle) 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