summaryrefslogtreecommitdiffstats
path: root/jdisc_core_test/integration_test
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jdisc_core_test/integration_test
Publish
Diffstat (limited to 'jdisc_core_test/integration_test')
-rw-r--r--jdisc_core_test/integration_test/.gitignore3
-rw-r--r--jdisc_core_test/integration_test/pom.xml291
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/AbstractApplicationTestCase.java46
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleActivatorIntegrationTest.java50
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleInstallerIntegrationTest.java192
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/GuiceRepositoryIntegrationTest.java95
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/ServerRepositoryIntegrationTest.java99
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java89
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ApplicationLoaderIntegrationTest.java155
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BootstrapDaemonIntegrationTest.java58
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ExportPackagesIntegrationTest.java36
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java223
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogManagerIntegrationTest.java30
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogServiceIntegrationTest.java62
-rw-r--r--jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/test/TestDriverIntegrationTest.java33
-rw-r--r--jdisc_core_test/integration_test/src/test/resources/config.properties1
-rw-r--r--jdisc_core_test/integration_test/src/test/resources/logger.properties1
17 files changed, 1464 insertions, 0 deletions
diff --git a/jdisc_core_test/integration_test/.gitignore b/jdisc_core_test/integration_test/.gitignore
new file mode 100644
index 00000000000..579f9d16789
--- /dev/null
+++ b/jdisc_core_test/integration_test/.gitignore
@@ -0,0 +1,3 @@
+/pom.xml.build
+/target
+/tmp
diff --git a/jdisc_core_test/integration_test/pom.xml b/jdisc_core_test/integration_test/pom.xml
new file mode 100644
index 00000000000..30263277c96
--- /dev/null
+++ b/jdisc_core_test/integration_test/pom.xml
@@ -0,0 +1,291 @@
+<?xml version="1.0"?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>parent</artifactId>
+ <version>6-SNAPSHOT</version>
+ </parent>
+ <artifactId>integration_test</artifactId>
+ <version>6-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>jdisc_core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-a</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-b-priv</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-ca</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-dj</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-ej-priv</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-f-more</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-g-act</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>app-h-log</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-a</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-b</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-ca</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-dc</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-eab</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-fac</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-gg</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-hi</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-ih</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-j-priv</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-k-pkgs</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-l1</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-l2</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-ml</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-nac</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-oa-path</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-p-jar</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-q-frag</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-rq</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-s-act</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-tp</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>cert-us</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>my-bundle-activator</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>my-guice-module</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.yahoo.vespa.jdisc_core</groupId>
+ <artifactId>my-server-provider</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <excludeTransitive>true</excludeTransitive>
+ <stripVersion>true</stripVersion>
+ </configuration>
+ </execution>
+ <execution>
+ <!-- we need an explicit copy of cert-a for the pre-install in cert-oa-path's manifest -->
+ <id>cert-a</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeGroupIds>com.yahoo.vespa.jdisc_core</includeGroupIds>
+ <includeArtifactIds>cert-a</includeArtifactIds>
+ <stripVersion>true</stripVersion>
+ <outputDirectory>${basedir}/target</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>${test.hide}</redirectTestOutputToFile>
+ <systemPropertyVariables>
+ <java.util.logging.config.file>
+ src/test/resources/logger.properties
+ </java.util.logging.config.file>
+ <jdisc.bundle.path>${project.build.directory}/dependency</jdisc.bundle.path>
+ <jdisc.cache.path>${project.build.directory}/bundlecache</jdisc.cache.path>
+ <jdisc.config.file>src/test/resources/config.properties</jdisc.config.file>
+ <jdisc.logger.level>ALL</jdisc.logger.level>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <test.hide>false</test.hide>
+ </properties>
+</project>
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/AbstractApplicationTestCase.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/AbstractApplicationTestCase.java
new file mode 100644
index 00000000000..a9d33270c20
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/AbstractApplicationTestCase.java
@@ -0,0 +1,46 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.application;
+
+import com.google.inject.Inject;
+import com.yahoo.jdisc.service.CurrentContainer;
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class AbstractApplicationTestCase {
+
+ @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());
+ }
+
+ private static class MyApplication extends AbstractApplication {
+
+ @Inject
+ public MyApplication(BundleInstaller bundleInstaller, ContainerActivator activator,
+ CurrentContainer container) {
+ super(bundleInstaller, activator, container);
+ }
+
+ @Override
+ public void start() {
+
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleActivatorIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleActivatorIntegrationTest.java
new file mode 100644
index 00000000000..7fe517fdd80
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleActivatorIntegrationTest.java
@@ -0,0 +1,50 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.application;
+
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class BundleActivatorIntegrationTest {
+
+ @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());
+ }
+
+ @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());
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleInstallerIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleInstallerIntegrationTest.java
new file mode 100644
index 00000000000..3ed84446369
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/BundleInstallerIntegrationTest.java
@@ -0,0 +1,192 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.application;
+
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class BundleInstallerIntegrationTest {
+
+ @Test
+ public void requireThatInstallWorks() 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);
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-a", bundle.getSymbolicName());
+
+ boolean found = false;
+ for (Bundle entry : driver.osgiFramework().bundles()) {
+ assertNotNull(entry);
+ if (prev.remove(entry)) {
+ continue;
+ }
+ assertFalse(found);
+ assertSame(bundle, entry);
+ found = true;
+ }
+ assertTrue(prev.isEmpty());
+ assertTrue(found);
+ driver.close();
+ }
+
+ @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();
+ }
+
+ @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();
+ }
+
+ @Test
+ public void requireThatUninstallAllWorks() throws Exception {
+ TestDriver driver = TestDriver.newSimpleApplicationInstance();
+ List<Bundle> prev = new LinkedList<>(driver.osgiFramework().bundles());
+
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ List<Bundle> bundles = installer.installAndStart(
+ "cert-a.jar",
+ "cert-b.jar");
+ assertNotNull(bundles);
+ installer.stopAndUninstall(bundles);
+
+ List<Bundle> next = new LinkedList<>(driver.osgiFramework().bundles());
+ next.removeAll(prev);
+ assertTrue(next.isEmpty());
+ driver.close();
+ }
+
+ @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();
+ }
+
+ @Test
+ public void requireThatInstallInstalledThrowsException() throws Exception {
+ TestDriver driver = TestDriver.newSimpleApplicationInstance();
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ Bundle bundle = installer.installAndStart("cert-a.jar").get(0);
+ assertNotNull(bundle);
+ try {
+ installer.installAndStart("cert-a.jar");
+ fail();
+ } catch (BundleException e) {
+ assertEquals("OSGi bundle com.yahoo.vespa.jdisc_core.cert-a already started.",
+ e.getMessage());
+ }
+ driver.close();
+ }
+
+ @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();
+ }
+
+ @Test
+ public void requireThatPrivilegedActivatorInstructionButNoRootPrivilegesKindOfWorksOnABestEffortBasis() throws Exception {
+ TestDriver driver = TestDriver.newSimpleApplicationInstance();
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ installer.installAndStart("cert-j-priv.jar");
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallExceptionContainsInstalledBundles() throws BundleException {
+ OsgiFramework osgi = TestDriver.newOsgiFramework();
+ osgi.start();
+ BundleInstaller installer = new BundleInstaller(osgi);
+ assertEquals(1, osgi.bundles().size());
+ try {
+ installer.installAndStart("cert-a.jar", "cert-tp.jar");
+ fail();
+ } catch (BundleException e) {
+ assertTrue(e instanceof BundleInstallationException);
+ List<Bundle> bundles = ((BundleInstallationException)e).installedBundles();
+ assertEquals(2, bundles.size());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-a", bundles.get(0).getSymbolicName());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-tp", bundles.get(1).getSymbolicName());
+ }
+ assertEquals(3, osgi.bundles().size()); // did not clean up the installed bundles inside the catch-block
+ osgi.stop();
+ }
+
+ @Test
+ public void requireThatStartExceptionContainsInstalledBundles() throws BundleException {
+ OsgiFramework osgi = TestDriver.newOsgiFramework();
+ osgi.start();
+ osgi.bundleContext().registerService(RuntimeException.class, new RuntimeException(), null);
+ BundleInstaller installer = new BundleInstaller(osgi);
+ assertEquals(1, osgi.bundles().size());
+ try {
+ installer.installAndStart("cert-a.jar", "cert-us.jar");
+ fail();
+ } catch (BundleException e) {
+ assertTrue(e instanceof BundleInstallationException);
+ List<Bundle> bundles = ((BundleInstallationException)e).installedBundles();
+ assertEquals(3, bundles.size());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-a", bundles.get(0).getSymbolicName());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-us", bundles.get(1).getSymbolicName());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-s-act", bundles.get(2).getSymbolicName());
+ }
+ assertEquals(4, osgi.bundles().size()); // did not clean up the installed bundles inside the catch-block
+ osgi.stop();
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/GuiceRepositoryIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/GuiceRepositoryIntegrationTest.java
new file mode 100644
index 00000000000..ba237318f20
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/GuiceRepositoryIntegrationTest.java
@@ -0,0 +1,95 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.application;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class GuiceRepositoryIntegrationTest {
+
+ @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();
+ }
+
+ @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();
+ }
+
+ @Test
+ public void requireThatInstallUnknowClassThrows() throws BundleException, ClassNotFoundException {
+ TestDriver driver = TestDriver.newSimpleApplicationInstance(new MyModule());
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ Bundle bundle = installer.installAndStart("my-guice-module.jar").get(0);
+
+ ContainerBuilder builder = driver.newContainerBuilder();
+ try {
+ builder.guiceModules().install(bundle, "class.not.Found");
+ fail();
+ } catch (ClassNotFoundException e) {
+
+ }
+ driver.close();
+ }
+
+ private static class MyModule extends AbstractModule {
+
+ final CountDownLatch initLatch = new CountDownLatch(1);
+ final CountDownLatch configLatch = new CountDownLatch(1);
+
+ @Override
+ protected void configure() {
+ bind(CountDownLatch.class).annotatedWith(Names.named("Init")).toInstance(initLatch);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Config")).toInstance(configLatch);
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/ServerRepositoryIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/ServerRepositoryIntegrationTest.java
new file mode 100644
index 00000000000..250a05f6ed9
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/application/ServerRepositoryIntegrationTest.java
@@ -0,0 +1,99 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.application;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+import com.yahoo.jdisc.service.ServerProvider;
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class ServerRepositoryIntegrationTest {
+
+ @Test
+ public void requireThatInstallFromBundleWorks() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newSimpleApplicationInstance(module);
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ Bundle bundle = installer.installAndStart("my-server-provider.jar").get(0);
+ ContainerBuilder builder = driver.newContainerBuilder();
+ builder.serverProviders().install(bundle, "com.yahoo.jdisc.bundle.MyServerProvider");
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+
+ Iterator<ServerProvider> it = builder.serverProviders().iterator();
+ assertTrue(it.hasNext());
+ ServerProvider server = it.next();
+ assertNotNull(server);
+ server.start();
+ assertTrue(module.start.await(60, TimeUnit.SECONDS));
+ server.close();
+ assertTrue(module.close.await(60, TimeUnit.SECONDS));
+ server.release();
+ assertTrue(module.destroy.await(60, TimeUnit.SECONDS));
+ assertFalse(it.hasNext());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallAllFromBundleWorks() throws Exception {
+ TestDriver driver = TestDriver.newSimpleApplicationInstance(new MyModule());
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ Bundle bundle = installer.installAndStart("my-server-provider.jar").get(0);
+ ContainerBuilder builder = driver.newContainerBuilder();
+ builder.serverProviders().installAll(bundle, Arrays.asList("com.yahoo.jdisc.bundle.MyServerProvider",
+ "com.yahoo.jdisc.bundle.MyServerProvider"));
+ Iterator<ServerProvider> it = builder.serverProviders().iterator();
+ assertTrue(it.hasNext());
+ assertNotNull(it.next());
+ assertTrue(it.hasNext());
+ assertNotNull(it.next());
+ assertFalse(it.hasNext());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallUnknownClassThrows() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newSimpleApplicationInstance(module);
+ BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
+ Bundle bundle = installer.installAndStart("my-server-provider.jar").get(0);
+ ContainerBuilder builder = driver.newContainerBuilder();
+ try {
+ builder.serverProviders().install(bundle, "class.not.Found");
+ fail();
+ } catch (ClassNotFoundException e) {
+
+ }
+ driver.close();
+ }
+
+ private static class MyModule extends AbstractModule {
+
+ final CountDownLatch init = new CountDownLatch(1);
+ final CountDownLatch start = new CountDownLatch(1);
+ final CountDownLatch close = new CountDownLatch(1);
+ final CountDownLatch destroy = new CountDownLatch(1);
+
+ @Override
+ protected void configure() {
+ bind(CountDownLatch.class).annotatedWith(Names.named("Init")).toInstance(init);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Start")).toInstance(start);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Close")).toInstance(close);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Destroy")).toInstance(destroy);
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java
new file mode 100644
index 00000000000..bcb4a0b4fd7
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java
@@ -0,0 +1,89 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.client;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.yahoo.jdisc.application.BundleInstaller;
+import com.yahoo.jdisc.application.ContainerActivator;
+import com.yahoo.jdisc.application.OsgiFramework;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class ClientDriverIntegrationTest {
+
+ @Test
+ public void requireThatApplicationClassInjectionWorks() throws Exception {
+ MyModule module = new MyModule();
+ ClientDriver.runApplicationWithOsgi("target/bundlecache_client", MyApplication.class, module);
+ assertEquals(5, module.state);
+ }
+
+ private static class MyApplication implements ClientApplication {
+
+ final Logger log = Logger.getLogger(MyApplication.class.getName());
+ final ContainerActivator activator;
+ final BundleInstaller installer;
+ final MyModule module;
+
+ @Inject
+ MyApplication(ContainerActivator activator, OsgiFramework osgi, MyModule module) {
+ this.activator = activator;
+ this.installer = new BundleInstaller(osgi);
+ this.module = module;
+ module.state = 1;
+ }
+
+ @Override
+ public void start() {
+ if (++module.state != 2) {
+ throw new IllegalStateException();
+ }
+ }
+
+ @Override
+ public void run() {
+ if (++module.state != 3) {
+ throw new IllegalStateException();
+ }
+ try {
+ List<Bundle> bundles = installer.installAndStart("cert-a.jar");
+ Class classObj = bundles.get(0).loadClass("com.yahoo.jdisc.bundle.a.CertificateA");
+ log.info("Loaded '" + classObj.getName() + "'.");
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ @Override
+ public void stop() {
+ if (++module.state != 4) {
+ throw new IllegalStateException();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ if (++module.state != 5) {
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+ private static class MyModule extends AbstractModule {
+
+ int state = 0;
+
+ @Override
+ protected void configure() {
+ bind(MyModule.class).toInstance(this);
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ApplicationLoaderIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ApplicationLoaderIntegrationTest.java
new file mode 100644
index 00000000000..99ed055fd36
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ApplicationLoaderIntegrationTest.java
@@ -0,0 +1,155 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+import com.yahoo.jdisc.test.TestDriver;
+import org.apache.felix.framework.util.FelixConstants;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class ApplicationLoaderIntegrationTest {
+
+ @Test
+ public void requireThatLifecycleWorks() throws Exception {
+ MyModule module = new MyModule();
+ ApplicationLoader loader = new ApplicationLoader(TestDriver.newOsgiFramework(),
+ Arrays.asList(module));
+ loader.init("app-a.jar", false);
+
+ assertFalse(module.init.await(100, TimeUnit.MILLISECONDS));
+ assertFalse(module.start.await(100, TimeUnit.MILLISECONDS));
+ loader.start();
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+ assertTrue(module.start.await(60, TimeUnit.SECONDS));
+
+ Iterator<Bundle> it = loader.osgiFramework().bundles().iterator();
+ assertTrue(it.hasNext());
+ Bundle bundle = it.next();
+ assertNotNull(bundle);
+ assertEquals(FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME,
+ bundle.getSymbolicName());
+ assertTrue(it.hasNext());
+ assertNotNull(bundle = it.next());
+ assertEquals("com.yahoo.vespa.jdisc_core.app-a",
+ bundle.getSymbolicName());
+ assertFalse(it.hasNext());
+
+ assertFalse(module.stop.await(100, TimeUnit.MILLISECONDS));
+ assertFalse(module.destroy.await(100, TimeUnit.MILLISECONDS));
+ loader.stop();
+ assertTrue(module.stop.await(60, TimeUnit.SECONDS));
+ assertTrue(module.destroy.await(60, TimeUnit.SECONDS));
+
+ loader.destroy();
+ }
+
+ @Test
+ public void requireThatNoApplicationInstructionThrowsException() throws Exception {
+ try {
+ TestDriver.newApplicationBundleInstance("cert-a.jar", false);
+ fail();
+ } catch (IllegalArgumentException e) {
+
+ }
+ }
+
+ @Test
+ public void requireThatMultipleApplicationInstructionsThrowException() throws Exception {
+ try {
+ TestDriver.newApplicationBundleInstance("app-f-more.jar", false);
+ fail();
+ } catch (IllegalArgumentException e) {
+
+ }
+ }
+
+ @Test
+ public void requireThatUnprivilegedBundleCanBeLoadedUnprivileged() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-a.jar", false, module);
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationA", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatUnprivilegedBundleCanBeLoadedPrivileged() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-a.jar", true, module);
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationA", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatPrivilegedBundleCanBeLoadedUnprivilegedOnABestEffortBasis() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-b-priv.jar",
+ false, module);
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationB", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatPrivilegedBundleCanBeLoadedPrivileged() throws Exception {
+ MyModule module = new MyModule();
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-b-priv.jar",
+ true, module);
+ assertTrue(module.init.await(60, TimeUnit.SECONDS));
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationB", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionWorks() throws Exception {
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-ca.jar", true);
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationC", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionDoesNotIgnorePrivilegedActivatorOfDependencies() throws Exception {
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-dj.jar", true);
+ driver.close();
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionPropagatesPrivileges() throws Exception {
+ TestDriver driver = TestDriver.newApplicationBundleInstance("app-ej-priv.jar", true);
+ assertEquals("com.yahoo.jdisc.bundle.ApplicationE", driver.application().getClass().getName());
+ driver.close();
+ }
+
+ private static class MyModule extends AbstractModule {
+
+ final CountDownLatch init = new CountDownLatch(1);
+ final CountDownLatch start = new CountDownLatch(1);
+ final CountDownLatch stop = new CountDownLatch(1);
+ final CountDownLatch destroy = new CountDownLatch(1);
+
+ @Override
+ protected void configure() {
+ bind(CountDownLatch.class).annotatedWith(Names.named("Init")).toInstance(init);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Start")).toInstance(start);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Stop")).toInstance(stop);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Destroy")).toInstance(destroy);
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BootstrapDaemonIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BootstrapDaemonIntegrationTest.java
new file mode 100644
index 00000000000..384ba0aa89d
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BootstrapDaemonIntegrationTest.java
@@ -0,0 +1,58 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.yahoo.jdisc.application.Application;
+import org.apache.commons.daemon.DaemonContext;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class BootstrapDaemonIntegrationTest {
+
+ @Test
+ public void requireThatConfigFileIsInjected() throws Exception {
+ BootstrapDaemon daemon = new BootstrapDaemon();
+
+ DaemonContext ctx = Mockito.mock(DaemonContext.class);
+ Mockito.doReturn(new String[] { MyApplication.class.getName() }).when(ctx).getArguments();
+ daemon.init(ctx);
+ daemon.start();
+
+ assertEquals("bar", ((MyApplication)((ApplicationLoader)daemon.loader()).application()).foo);
+
+ daemon.stop();
+ daemon.destroy();
+ }
+
+ public static class MyApplication implements Application {
+
+ final String foo;
+
+ @Inject
+ public MyApplication(@Named("foo") String foo) {
+ this.foo = foo;
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void stop() {
+
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ExportPackagesIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ExportPackagesIntegrationTest.java
new file mode 100644
index 00000000000..04fa085db17
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/ExportPackagesIntegrationTest.java
@@ -0,0 +1,36 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class ExportPackagesIntegrationTest {
+
+ @Test
+ public void requireThatManifestContainsExportPackage() throws BundleException {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ List<Bundle> bundles = felix.installBundle("jdisc_core.jar");
+ assertEquals(1, bundles.size());
+ Object obj = bundles.get(0).getHeaders().get("Export-Package");
+ assertTrue(obj instanceof String);
+ String str = (String)obj;
+ assertTrue(str.contains(ExportPackages.getSystemPackages()));
+ assertTrue(str.contains("com.yahoo.jdisc"));
+ assertTrue(str.contains("com.yahoo.jdisc.application"));
+ assertTrue(str.contains("com.yahoo.jdisc.handler"));
+ assertTrue(str.contains("com.yahoo.jdisc.service"));
+ felix.stop();
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java
new file mode 100644
index 00000000000..d6a77a88625
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java
@@ -0,0 +1,223 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.yahoo.jdisc.application.BundleInstallationException;
+import com.yahoo.jdisc.test.TestDriver;
+import org.apache.felix.framework.util.FelixConstants;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class FelixFrameworkIntegrationTest {
+
+ @Test
+ public void requireThatBundlesCanBeInstalled() throws BundleException {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+
+ Bundle bundle = felix.installBundle("cert-a.jar").get(0);
+ assertNotNull(bundle);
+
+ Iterator<Bundle> it = felix.bundles().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ assertEquals(FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME, it.next().getSymbolicName());
+ assertTrue(it.hasNext());
+ assertSame(bundle, it.next());
+ assertFalse(it.hasNext());
+
+ felix.stop();
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionWorks() throws Exception {
+ assertBundle("cert-ca.jar", "com.yahoo.jdisc.bundle.c.CertificateC",
+ "com.yahoo.vespa.jdisc_core.cert-ca",
+ "com.yahoo.vespa.jdisc_core.cert-a");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionResolvesTransitiveDepedencies() throws Exception {
+ assertBundle("cert-dc.jar", "com.yahoo.jdisc.bundle.d.CertificateD",
+ "com.yahoo.vespa.jdisc_core.cert-dc",
+ "com.yahoo.vespa.jdisc_core.cert-ca",
+ "com.yahoo.vespa.jdisc_core.cert-a");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionResolvesAllTransitiveDepedencies() throws Exception {
+ assertBundle("cert-eab.jar", "com.yahoo.jdisc.bundle.e.CertificateE",
+ "com.yahoo.vespa.jdisc_core.cert-eab",
+ "com.yahoo.vespa.jdisc_core.cert-a",
+ "com.yahoo.vespa.jdisc_core.cert-b");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionInstallsEachBundleOnlyOnce() throws Exception {
+ assertBundle("cert-fac.jar", "com.yahoo.jdisc.bundle.f.CertificateF",
+ "com.yahoo.vespa.jdisc_core.cert-fac",
+ "com.yahoo.vespa.jdisc_core.cert-a",
+ "com.yahoo.vespa.jdisc_core.cert-ca");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionTracksLocationInCanonicalForm() throws Exception {
+ assertBundle("cert-nac.jar", "com.yahoo.jdisc.bundle.n.CertificateN",
+ "com.yahoo.vespa.jdisc_core.cert-nac",
+ "com.yahoo.vespa.jdisc_core.cert-a",
+ "com.yahoo.vespa.jdisc_core.cert-ca");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionDetectsAutoDependency() throws Exception {
+ assertBundle("cert-gg.jar", "com.yahoo.jdisc.bundle.g.CertificateG",
+ "com.yahoo.vespa.jdisc_core.cert-gg");
+ }
+
+ @Test
+ public void requireThatInstallBundleInstructionDetectsCycles() throws Exception {
+ assertBundle("cert-hi.jar", "com.yahoo.jdisc.bundle.h.CertificateH",
+ "com.yahoo.vespa.jdisc_core.cert-hi",
+ "com.yahoo.vespa.jdisc_core.cert-ih");
+ }
+
+ @Test
+ public void requireThatSystemPackagesAreExported() throws Exception {
+ assertBundle("cert-k-pkgs.jar", "com.yahoo.jdisc.bundle.k.CertificateK",
+ "com.yahoo.vespa.jdisc_core.cert-k-pkgs");
+ }
+
+ @Test
+ public void requireThatBundlesCanBeRefreshed() throws Exception {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ Bundle bundleL = startBundle(felix, "cert-l1.jar");
+ Bundle bundleM = startBundle(felix, "cert-ml.jar");
+ assertEquals(1, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));
+ bundleL.uninstall();
+ startBundle(felix, "cert-l2.jar");
+ felix.refreshPackages();
+ assertEquals(2, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));
+ felix.stop();
+ }
+
+ @Test
+ public void requireThatBundlesCanBeRefreshedWithDisjunctRemovalClosure() throws Exception {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ Bundle bundleA = startBundle(felix, "cert-a.jar");
+ Bundle bundleL = startBundle(felix, "cert-l1.jar");
+ Bundle bundleM = startBundle(felix, "cert-ml.jar");
+ assertEquals(1, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));
+ bundleA.uninstall();
+ bundleL.uninstall();
+ startBundle(felix, "cert-l2.jar");
+ felix.refreshPackages();
+ assertEquals(2, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM"));
+ felix.stop();
+ }
+
+ @Test
+ public void requireThatJdiscBundlePathIsConfigurable() throws Exception {
+ assertBundle("cert-oa-path.jar", "com.yahoo.jdisc.bundle.o.CertificateO",
+ "com.yahoo.vespa.jdisc_core.cert-oa-path",
+ "com.yahoo.vespa.jdisc_core.cert-a");
+ }
+
+ @Test
+ public void requireThatBundleSymbolicNameIsRequired() throws Exception {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ try {
+ felix.installBundle("cert-p-jar.jar");
+ fail();
+ } catch (BundleException e) {
+ assertTrue(e.getMessage().contains("it might not be an OSGi bundle"));
+ }
+ felix.stop();
+ }
+
+ @Test
+ public void requireThatBundleInstallationExceptionContainsInstalledBundles() throws Exception {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ assertEquals(1, felix.bundles().size());
+ try {
+ felix.installBundle("cert-tp.jar");
+ fail();
+ } catch (BundleException e) {
+ assertTrue(e instanceof BundleInstallationException);
+ List<Bundle> bundles = ((BundleInstallationException)e).installedBundles();
+ assertEquals(1, bundles.size());
+ assertEquals("com.yahoo.vespa.jdisc_core.cert-tp", bundles.get(0).getSymbolicName());
+ }
+ assertEquals(2, felix.bundles().size()); // did not clean up the installed bundle inside the catch-block
+ felix.stop();
+ }
+
+ @Test
+ public void requireThatFragmentBundlesCanBeInstalled() throws Exception {
+ assertBundle("cert-q-frag.jar", null,
+ "com.yahoo.vespa.jdisc_core.cert-q-frag");
+ }
+
+ @Test
+ public void requireThatFragmentBundlesCanBePreinstalled() throws Exception {
+ assertBundle("cert-rq.jar", null,
+ "com.yahoo.vespa.jdisc_core.cert-rq",
+ "com.yahoo.vespa.jdisc_core.cert-q-frag");
+ }
+
+ private static Bundle startBundle(FelixFramework felix, String bundleLocation) throws BundleException {
+ List<Bundle> lst = felix.installBundle(bundleLocation);
+ assertEquals(1, lst.size());
+ felix.startBundles(lst, false);
+ return lst.get(0);
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private static int callClass(Bundle bundle, String className) throws Exception {
+ Class certClass = bundle.loadClass(className);
+ assertNotNull(certClass);
+ Callable<Integer> cert = (Callable<Integer>)certClass.newInstance();
+ assertNotNull(cert);
+ return cert.call();
+ }
+
+ private static void assertBundle(String bundleLocation, String className, String... expectedBundles)
+ throws Exception {
+ FelixFramework felix = TestDriver.newOsgiFramework();
+ felix.start();
+ try {
+ List<Bundle> bundles = felix.installBundle(bundleLocation);
+ List<String> actual = new LinkedList<>();
+ for (Bundle bundle : bundles) {
+ actual.add(bundle.getSymbolicName());
+ }
+ assertEquals(Arrays.asList(expectedBundles), actual);
+ felix.startBundles(bundles, false);
+ if (className != null) {
+ assertNotNull(bundles.get(0).loadClass(className).newInstance());
+ }
+ } finally {
+ felix.stop();
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogManagerIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogManagerIntegrationTest.java
new file mode 100644
index 00000000000..f6f717df7fa
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogManagerIntegrationTest.java
@@ -0,0 +1,30 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.BundleContext;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class OsgiLogManagerIntegrationTest {
+
+ @Test
+ public void requireThatRootLoggerLevelIsNotModifiedIfLoggerConfigIsGiven() {
+ Logger logger = Logger.getLogger("");
+ logger.setLevel(Level.WARNING);
+
+ OsgiLogManager.newInstance().install(Mockito.mock(BundleContext.class));
+
+ assertNotNull(System.getProperty("java.util.logging.config.file"));
+ assertEquals(Level.WARNING, logger.getLevel());
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogServiceIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogServiceIntegrationTest.java
new file mode 100644
index 00000000000..89420464f6f
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/OsgiLogServiceIntegrationTest.java
@@ -0,0 +1,62 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.core;
+
+import com.yahoo.jdisc.test.TestDriver;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogReaderService;
+
+import java.util.Enumeration;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class OsgiLogServiceIntegrationTest {
+
+ @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);
+ Enumeration<LogEntry> log = (Enumeration<LogEntry>)reader.getLog();
+
+ assertEntry(Level.INFO, "[jdk14] hello world", null, now, log);
+ assertEntry(Level.INFO, "[slf4j] hello world", null, now, log);
+ assertEntry(Level.INFO, "[log4j] hello world", null, now, log);
+ assertEntry(Level.INFO, "[jcl] hello world", null, now, log);
+
+ assertTrue(driver.close());
+ }
+
+ private static void assertEntry(Level expectedLevel, String expectedMessage, Throwable expectedException,
+ long expectedTimeGE, Enumeration<LogEntry> log)
+ {
+ assertTrue(log.hasMoreElements());
+ LogEntry entry = log.nextElement();
+ assertNotNull(entry);
+ System.err.println("log entry: "+entry.getMessage()+" bundle="+entry.getBundle());
+ assertNull(entry.getBundle());
+ assertNotNull(entry.getServiceReference());
+ assertEquals(OsgiLogHandler.toServiceLevel(expectedLevel), entry.getLevel());
+ assertEquals(expectedMessage, entry.getMessage());
+ assertEquals(expectedException, entry.getException());
+ assertTrue(expectedTimeGE <= entry.getTime());
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/test/TestDriverIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/test/TestDriverIntegrationTest.java
new file mode 100644
index 00000000000..75eed83f56b
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/test/TestDriverIntegrationTest.java
@@ -0,0 +1,33 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc.test;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+import org.junit.Test;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class TestDriverIntegrationTest {
+
+ @Test
+ public void requireThatFactoryMethodsWork() {
+ TestDriver.newApplicationBundleInstance("app-a.jar", false, new MyModule()).close();
+ TestDriver.newInstance(TestDriver.newOsgiFramework(), "app-a.jar", false, new MyModule()).close();
+ }
+
+ private static class MyModule extends AbstractModule {
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ @Override
+ protected void configure() {
+ bind(CountDownLatch.class).annotatedWith(Names.named("Init")).toInstance(latch);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Start")).toInstance(latch);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Stop")).toInstance(latch);
+ bind(CountDownLatch.class).annotatedWith(Names.named("Destroy")).toInstance(latch);
+ }
+ }
+}
diff --git a/jdisc_core_test/integration_test/src/test/resources/config.properties b/jdisc_core_test/integration_test/src/test/resources/config.properties
new file mode 100644
index 00000000000..74d0a43fccf
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/resources/config.properties
@@ -0,0 +1 @@
+foo=bar
diff --git a/jdisc_core_test/integration_test/src/test/resources/logger.properties b/jdisc_core_test/integration_test/src/test/resources/logger.properties
new file mode 100644
index 00000000000..cf5b037c599
--- /dev/null
+++ b/jdisc_core_test/integration_test/src/test/resources/logger.properties
@@ -0,0 +1 @@
+unknown.Logger.level = INFO