diff options
Diffstat (limited to 'jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java')
-rw-r--r-- | jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/client/ClientDriverIntegrationTest.java | 89 |
1 files changed, 89 insertions, 0 deletions
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); + } + } +} |