Search in sources :

Example 56 with TestDriver

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

the class ThreadedRequestHandlerTestCase method requireThatNotImplementedHandlerDoesNotPreventShutdown.

@Test
public void requireThatNotImplementedHandlerDoesNotPreventShutdown() throws Exception {
    TestDriver driver = newTestDriver("http://localhost/", new ThreadedRequestHandler(newExecutor()) {
    });
    assertEquals(Response.Status.NOT_IMPLEMENTED, dispatchRequest(driver, "http://localhost/", ByteBuffer.wrap(new byte[] { 69 })).get(600, TimeUnit.SECONDS).getStatus());
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 57 with TestDriver

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

the class BundleActivatorIntegrationTest method requireThatBundleActivatorHasAccessToCurrentContainer.

@Test
public void requireThatBundleActivatorHasAccessToCurrentContainer() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance();
    OsgiFramework osgi = driver.osgiFramework();
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    Bundle bundle = installer.installAndStart("my-bundle-activator.jar").get(0);
    Class<?> serviceClass = bundle.loadClass("com.yahoo.jdisc.bundle.MyService");
    assertNotNull(serviceClass);
    BundleContext ctx = osgi.bundleContext();
    ServiceReference<?> serviceRef = ctx.getServiceReference(serviceClass.getName());
    assertNotNull(serviceRef);
    Object service = ctx.getService(serviceRef);
    assertNotNull(service);
    assertTrue(serviceClass.isInstance(service));
    assertTrue(driver.close());
}
Also used : Bundle(org.osgi.framework.Bundle) TestDriver(com.yahoo.jdisc.test.TestDriver) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 58 with TestDriver

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

the class BundleActivatorIntegrationTest method requireThatApplicationBundleActivatorHasAccessToCurrentContainer.

@Test
public void requireThatApplicationBundleActivatorHasAccessToCurrentContainer() throws Exception {
    TestDriver driver = TestDriver.newApplicationBundleInstance("app-g-act.jar", false);
    OsgiFramework osgi = driver.osgiFramework();
    Class<?> serviceClass = osgi.bundles().get(1).loadClass("com.yahoo.jdisc.bundle.MyService");
    assertNotNull(serviceClass);
    BundleContext ctx = osgi.bundleContext();
    ServiceReference<?> serviceRef = ctx.getServiceReference(serviceClass.getName());
    assertNotNull(serviceRef);
    Object service = ctx.getService(serviceRef);
    assertNotNull(service);
    assertTrue(serviceClass.isInstance(service));
    assertTrue(driver.close());
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 59 with TestDriver

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

the class GuiceRepositoryIntegrationTest method requireThatInstallFromBundleWorks.

@Test
public void requireThatInstallFromBundleWorks() throws Exception {
    MyModule module = new MyModule();
    TestDriver driver = TestDriver.newSimpleApplicationInstance(module);
    ContainerBuilder builder = driver.newContainerBuilder();
    List<Module> prev = new LinkedList<>(builder.guiceModules().collection());
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    Bundle bundle = installer.installAndStart("my-guice-module.jar").get(0);
    builder.guiceModules().install(bundle, "com.yahoo.jdisc.bundle.MyGuiceModule");
    List<Module> next = new LinkedList<>(builder.guiceModules().collection());
    next.removeAll(prev);
    assertEquals(1, next.size());
    assertTrue(module.initLatch.await(60, TimeUnit.SECONDS));
    assertNotNull(builder.guiceModules().getInstance(Injector.class));
    assertTrue(module.configLatch.await(60, TimeUnit.SECONDS));
    driver.close();
}
Also used : Bundle(org.osgi.framework.Bundle) Injector(com.google.inject.Injector) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) TestDriver(com.yahoo.jdisc.test.TestDriver) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 60 with TestDriver

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

the class GuiceRepositoryIntegrationTest method requireThatInstallAllFromBundleWorks.

@Test
public void requireThatInstallAllFromBundleWorks() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance(new MyModule());
    ContainerBuilder builder = driver.newContainerBuilder();
    List<Module> prev = new LinkedList<>(builder.guiceModules().collection());
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    Bundle bundle = installer.installAndStart("my-guice-module.jar").get(0);
    builder.guiceModules().installAll(bundle, Arrays.asList("com.yahoo.jdisc.bundle.MyGuiceModule", "com.yahoo.jdisc.bundle.MyGuiceModule"));
    List<Module> next = new LinkedList<>(builder.guiceModules().collection());
    next.removeAll(prev);
    assertEquals(2, next.size());
    driver.close();
}
Also used : Bundle(org.osgi.framework.Bundle) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) TestDriver(com.yahoo.jdisc.test.TestDriver) LinkedList(java.util.LinkedList) 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