Search in sources :

Example 11 with ApplicationMetadata

use of org.apache.aries.application.ApplicationMetadata in project aries by apache.

the class AriesApplicationManagerImplTest method testCreateAndConversion.

@Test
public void testCreateAndConversion() throws Exception {
    AriesApplication app = createApplication(CONVERSION_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "conversion.eba");
    assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
    assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(2, appContent.size());
    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
    assertTrue(appContent.contains(fbw));
    assertTrue(appContent.contains(mbl));
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
    assertEquals(2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl("hello.world.jar;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.0");
    DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue(dcList.contains(dc1));
    assertTrue(dcList.contains(dc2));
    dcList = dm.getApplicationProvisionBundles();
    assertEquals(1, dcList.size());
    assertTrue(dcList.contains(dc3));
    assertEquals(2, app.getBundleInfo().size());
    BundleInfo info;
    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
    assertNotNull(info);
    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
    assertNotNull(info);
    assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
    assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 12 with ApplicationMetadata

use of org.apache.aries.application.ApplicationMetadata 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)12 Test (org.junit.Test)8 Content (org.apache.aries.application.Content)7 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)5 Version (org.osgi.framework.Version)5 InputStream (java.io.InputStream)3 Manifest (java.util.jar.Manifest)3 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)3 BundleInfo (org.apache.aries.application.management.BundleInfo)3 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ApplicationMetadataFactory (org.apache.aries.application.ApplicationMetadataFactory)2 DeploymentContent (org.apache.aries.application.DeploymentContent)2 ContentImpl (org.apache.aries.application.impl.ContentImpl)2 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 ResolverException (org.apache.aries.application.management.ResolverException)2