Search in sources :

Example 1 with RichBundleContext

use of org.apache.aries.itest.RichBundleContext in project aries by apache.

the class IsolatedCfgAdminRuntimeTest method constructApplications.

/**
 * Creates two applications, as follows:
 * <p/>
 * - helloworld-bp.eba ------
 * |
 * | This application contains a helloworld bundle which contains an interface and impl for HelloWorld. Upon being started
 * | blueprint will create a new container for this bundle and register the HelloWorld service. The service will be injected
 * | with a message coming from the ConfigurationAdmin service using the PID: helloworld-bp. As a CM property placeholder is
 * | used, a ManagedService will also be registered on the bundles behalf so that further updates can be captured. Note that
 * | the blueprint configuration is wired to reload the container on a configuration update (to allow easier tracking of when
 * | to test service contents etc).
 * |
 * | The application also contains a configuration admin bundle (pulled from Maven).
 * ---------------------------
 * <p/>
 * - helloworld-mn.eba -------
 * |
 * | This application contains a helloworld bundle containing an activator that will register itself as a ManagedService for the
 * | PID: helloworld-mn. The activator will also expose out a HelloWorld service. Upon recieving an update from the packaged
 * | Configuration Admin service, the HelloWorld service will be re-registered using the latest configuration, namely the "message".
 * |
 * | The application also contains a configuration admin bundle (pulled from Maven).
 * ---------------------------
 *
 * @throws Exception
 */
@Before
public void constructApplications() throws Exception {
    Assert.assertNotNull("Could not find Maven URL handler", (new RichBundleContext(context())).getService(URLStreamHandlerService.class, "url.handler.protocol=mvn", 300000));
    MavenArtifactProvisionOption configAdminProvisionOption = mavenBundleInTest(getClass().getClassLoader(), "org.apache.felix", "org.apache.felix.configadmin");
    Assert.assertNotNull("Unable to lookup config admin maven bundle", configAdminProvisionOption);
    URL configAdminUrl = new URL(configAdminProvisionOption.getURL());
    ZipFixture helloWorldBluePrintEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-BP.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldbp").attribute("Bundle-Version", "1.0.0").attribute("Import-Package", "org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("OSGI-INF/blueprint/blueprint.xml", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/blueprint.xml")).end();
    ZipFixture helloWorldManualEba = ArchiveFixture.newZip().binary("META-INF/APPLICATION.MF", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("isolated/config/APPLICATION-MN.MF")).binary("org.apache.felix.configadmin.jar", configAdminUrl.openStream()).jar("helloworld-bundle.jar").manifest().symbolicName("org.apache.aries.isolated.helloworldmn").attribute("Bundle-Version", "1.0.0").attribute("Bundle-Activator", "org.apache.aries.isolated.config.HelloWorldManagedServiceImpl").attribute("Import-Package", "org.osgi.framework,org.osgi.service.cm").end().binary("org/apache/aries/isolated/sample/HelloWorld.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorld.class")).binary("org/apache/aries/isolated/sample/HelloWorldImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/sample/HelloWorldImpl.class")).binary("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class", IsolatedCfgAdminRuntimeTest.class.getClassLoader().getResourceAsStream("org/apache/aries/isolated/config/HelloWorldManagedServiceImpl.class")).end();
    FileOutputStream fout = new FileOutputStream(APP_HWBP);
    helloWorldBluePrintEba.writeOut(fout);
    fout.close();
    fout = new FileOutputStream(APP_HWMN);
    helloWorldManualEba.writeOut(fout);
    fout.close();
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) RichBundleContext(org.apache.aries.itest.RichBundleContext) URLStreamHandlerService(org.osgi.service.url.URLStreamHandlerService) MavenArtifactProvisionOption(org.ops4j.pax.exam.options.MavenArtifactProvisionOption) URL(java.net.URL) Before(org.junit.Before)

Example 2 with RichBundleContext

use of org.apache.aries.itest.RichBundleContext in project aries by apache.

the class ModelledResourceManagerTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    RichBundleContext rootContext = context(getRootSubsystem());
    assertNull("Modeller is installed", rootContext.getBundleByName("org.apache.aries.application.modeller"));
    assertNull("Blueprint is installed", rootContext.getBundleByName("org.apache.aries.blueprint"));
    assertNull("Proxy is installed", rootContext.getBundleByName("org.apache.aries.proxy"));
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext)

Example 3 with RichBundleContext

use of org.apache.aries.itest.RichBundleContext in project aries by apache.

the class ConfigurationPostResolverTest method validatePostResolveTransform.

/**
 * This test validates that the transformer is correctly detecting the config admin package. Checks
 * are performed to validate that an existing import package is still honored etc.
 *
 * @throws Exception
 */
@Test
public void validatePostResolveTransform() throws Exception {
    RichBundleContext ctx = new RichBundleContext(bundleContext);
    PostResolveTransformer transformer = ctx.getService(PostResolveTransformer.class);
    Assert.assertNotNull("Unable to locate transformer", transformer);
    /**
     * Try processing deployed content that doesn't have any import for the
     * org.osgi.service.cm package, the resultant imports should be unaffected.
     */
    ApplicationMetadata mockApplicationMetadata = Skeleton.newMock(ApplicationMetadata.class);
    MockDeployedBundles originalDeployedBundles = new MockDeployedBundles();
    originalDeployedBundles.setDeployedContent(getNonConfigModelledResources());
    DeployedBundles transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
    Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
    Assert.assertEquals(originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
    /**
     * Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
     * modelled resources with an empty import package set in the mock deployed bundles instance.
     */
    originalDeployedBundles = new MockDeployedBundles();
    originalDeployedBundles.setDeployedContent(getConfigModelledResources());
    transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
    Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
    Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
    Assert.assertEquals("Missing config package", "org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
    /**
     * Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
     * modelled resources with a populated import package set in the mock deployed bundles instance.
     */
    originalDeployedBundles = new MockDeployedBundles();
    originalDeployedBundles.setDeployedContent(getConfigModelledResources());
    originalDeployedBundles.setImportPackage("org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\"");
    transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
    Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
    Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
    Assert.assertEquals("Missing config package", "org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\",org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) PostResolveTransformer(org.apache.aries.application.management.spi.resolve.PostResolveTransformer) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 4 with RichBundleContext

use of org.apache.aries.itest.RichBundleContext in project aries by apache.

the class BlueprintTest method checkBlueprint.

@Test
public void checkBlueprint() throws Exception {
    Subsystem subsystem = installSubsystemFromFile(BLUEPRINT_ESA);
    try {
        startSubsystem(subsystem);
        BundleContext bc = subsystem.getBundleContext();
        Hello h = new RichBundleContext(bc).getService(Hello.class);
        String message = h.saySomething();
        assertEquals("Wrong message back", "messageFromBlueprint", message);
    } finally {
        stopSubsystem(subsystem);
        uninstallSubsystem(subsystem);
    }
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) Hello(org.apache.aries.subsystem.itests.hello.api.Hello) Subsystem(org.osgi.service.subsystem.Subsystem) RichBundleContext(org.apache.aries.itest.RichBundleContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 5 with RichBundleContext

use of org.apache.aries.itest.RichBundleContext in project aries by apache.

the class HelloWorldTest method checkHelloSubsystem.

void checkHelloSubsystem(Subsystem helloSubsystem) throws Exception {
    helloSubsystem.start();
    BundleContext bc = helloSubsystem.getBundleContext();
    Hello h = new RichBundleContext(bc).getService(Hello.class);
    String message = h.saySomething();
    assertEquals("Wrong message back", "something", message);
    helloSubsystem.stop();
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) Hello(org.apache.aries.subsystem.itests.hello.api.Hello) RichBundleContext(org.apache.aries.itest.RichBundleContext) BundleContext(org.osgi.framework.BundleContext)

Aggregations

RichBundleContext (org.apache.aries.itest.RichBundleContext)8 Hello (org.apache.aries.subsystem.itests.hello.api.Hello)3 Test (org.junit.Test)3 BundleContext (org.osgi.framework.BundleContext)3 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)2 Subsystem (org.osgi.service.subsystem.Subsystem)2 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)1 PostResolveTransformer (org.apache.aries.application.management.spi.resolve.PostResolveTransformer)1 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)1 HelloWorld (org.apache.aries.isolated.sample.HelloWorld)1 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 ZipFixture (org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture)1 Before (org.junit.Before)1 MavenArtifactProvisionOption (org.ops4j.pax.exam.options.MavenArtifactProvisionOption)1 ServiceReference (org.osgi.framework.ServiceReference)1 Configuration (org.osgi.service.cm.Configuration)1 ManagedService (org.osgi.service.cm.ManagedService)1 URLStreamHandlerService (org.osgi.service.url.URLStreamHandlerService)1