Search in sources :

Example 61 with TestDriver

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

the class OsgiLogServiceIntegrationTest method requireThatAllSupportedLogFrameworksAreConfigured.

@Test
@SuppressWarnings("unchecked")
public void requireThatAllSupportedLogFrameworksAreConfigured() throws Exception {
    // need to explicitly set log level of root logger since integration suite now provides a logger config file,
    // which disables that setLevel() call of the OsgiLogManager.
    Logger.getLogger("").setLevel(Level.INFO);
    long now = System.currentTimeMillis();
    TestDriver driver = TestDriver.newApplicationBundleInstance("app-h-log.jar", false);
    BundleContext ctx = driver.osgiFramework().bundleContext();
    ServiceReference<?> ref = ctx.getServiceReference(LogReaderService.class.getName());
    LogReaderService reader = (LogReaderService) ctx.getService(ref);
    ArrayList<LogEntry> logEntries = Collections.list(reader.getLog());
    assertTrue(logEntries.size() >= 4);
    assertLogContainsEntry("[jdk14] hello world", logEntries, now);
    assertLogContainsEntry("[slf4j] hello world", logEntries, now);
    assertLogContainsEntry("[log4j] hello world", logEntries, now);
    assertLogContainsEntry("[jcl] hello world", logEntries, now);
    assertTrue(driver.close());
}
Also used : LogReaderService(org.osgi.service.log.LogReaderService) TestDriver(com.yahoo.jdisc.test.TestDriver) LogEntry(org.osgi.service.log.LogEntry) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 62 with TestDriver

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

the class ContainerNotReadyTestCase method requireThatExceptionIsThrown.

@Test
public void requireThatExceptionIsThrown() throws BindingSetNotFoundException {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    try {
        driver.newReference(URI.create("http://host"));
        fail();
    } catch (ContainerNotReadyException e) {
    }
    driver.close();
}
Also used : TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 63 with TestDriver

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

the class NoBindingSetSelectedTestCase method requireThatNoBindingSetSelectedIsThrown.

@Test
public void requireThatNoBindingSetSelectedIsThrown() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(BindingSetSelector.class).toInstance(new MySelector());
        }
    });
    driver.activateContainer(driver.newContainerBuilder());
    URI uri = URI.create("http://host");
    try {
        driver.newReference(uri);
        fail();
    } catch (NoBindingSetSelectedException e) {
        assertEquals(uri, e.uri());
    }
    driver.close();
}
Also used : URI(java.net.URI) TestDriver(com.yahoo.jdisc.test.TestDriver) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 64 with TestDriver

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

the class AbstractApplicationTestCase method requireThatBundleInstallerCanBeAccessed.

@Test
public void requireThatBundleInstallerCanBeAccessed() throws BundleException {
    TestDriver driver = TestDriver.newInjectedApplicationInstance(MyApplication.class);
    MyApplication app = (MyApplication) driver.application();
    List<Bundle> lst = app.installAndStartBundle("cert-a.jar");
    assertEquals(1, lst.size());
    assertEquals("com.yahoo.vespa.jdisc_core.cert-a", lst.get(0).getSymbolicName());
    app.stopAndUninstallBundle(lst.get(0));
    assertTrue(driver.close());
}
Also used : Bundle(org.osgi.framework.Bundle) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 65 with TestDriver

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

the class BundleInstallerIntegrationTest method requireThatUninstallWorks.

@Test
public void requireThatUninstallWorks() throws Exception {
    TestDriver driver = TestDriver.newSimpleApplicationInstance();
    List<Bundle> prev = new LinkedList<>(driver.osgiFramework().bundles());
    BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
    Bundle bundle = installer.installAndStart("cert-a.jar").get(0);
    assertNotNull(bundle);
    installer.stopAndUninstall(bundle);
    for (Bundle entry : driver.osgiFramework().bundles()) {
        assertTrue(prev.remove(entry));
    }
    assertTrue(prev.isEmpty());
    driver.close();
}
Also used : Bundle(org.osgi.framework.Bundle) 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