Search in sources :

Example 1 with PostResolveTransformer

use of org.apache.aries.application.management.spi.resolve.PostResolveTransformer 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)

Aggregations

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 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 RichBundleContext (org.apache.aries.itest.RichBundleContext)1 Test (org.junit.Test)1