Search in sources :

Example 21 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_rfc138PreventsBundleVersionWorking.

@Test
public void testGetImportPackage_rfc138PreventsBundleVersionWorking() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.NONE, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=1.0.0;bundle-version=1.0.0"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", new ArrayList<String>(), Arrays.asList("package.b;version=2.0.0")));
    // Check that the bundle-symbolic-name attribute for a bundle outside use-bundle causes an exception.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
        Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
    } catch (ResolverException e) {
    // We expect to reach this point if the test passes.
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 22 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_ValidDuplicates.

@Test
public void testGetImportPackage_ValidDuplicates() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.CONTENT);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.d;version=\"[1.0.0,3.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.d;version=\"2.0.0\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", Arrays.asList("package.d;version=\"1.0.0\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.d", "1.0.0", new ArrayList<String>(), Arrays.asList("package.d;version=2.0.1")));
    // Check that package D is not duplicated in Import-Package, and that the version range
    // has been narrowed to the intersection of the original requirements.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    String expectedResult = "package.d;version=\"[2.0.0,3.0.0)\"";
    Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 23 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testImportedService.

@Test
public void testImportedService() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.NONE, ternary.NONE);
    deployedBundles.addBundle(createModelledServiceBundle("bundle.a", "1.0.0", Collections.singleton("java.util.List"), Collections.<String>emptyList()));
    deployedBundles.addBundle(createModelledServiceBundle("bundle.b", "1.0.0", Collections.singleton("java.util.Set"), Collections.singleton("java.util.List")));
    deployedBundles.addBundle(createModelledServiceBundle("bundle.c", "1.0.0", Collections.<String>emptyList(), Collections.singleton("java.util.Set")));
    assertEquals("(objectClass=java.util.List)", deployedBundles.getDeployedImportService());
}
Also used : DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 24 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_InvalidDuplicatesWithAttributes.

@Test
public void testGetImportPackage_InvalidDuplicatesWithAttributes() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.c;version=1.0.0;was_internal=true"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c;version=2.0.0"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", new ArrayList<String>(), Arrays.asList("package.c;version=2.0.0;was_internal=true")));
    // Check that the incompatible package requirement attributes cause an exception.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
        Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
    } catch (ResolverException e) {
    // We expect to reach this point if the test passes.
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 25 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeploymentGeneratorTest method testResolve.

@Test
public void testResolve() throws Exception {
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("aries.test.a", "1.0.0"), mockContent("aries.test.b", "[1.0.0, 2.0.0)")));
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(BUNDLE_C, BUNDLE_D));
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, new ArrayList<ModelledResource>(), Collections.<Content>emptyList());
    Manifest man = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    Attributes attrs = man.getMainAttributes();
    assertEquals("aries.test", attrs.getValue(AppConstants.APPLICATION_SYMBOLIC_NAME));
    assertEquals("1.0.0", attrs.getValue(AppConstants.APPLICATION_VERSION));
    String content = attrs.getValue(AppConstants.DEPLOYMENT_CONTENT);
    String useBundle = attrs.getValue(AppConstants.DEPLOYMENT_USE_BUNDLE);
    String provisioned = attrs.getValue(AppConstants.DEPLOYMENT_PROVISION_BUNDLE);
    assertTrue(content.contains("aries.test.a;deployed-version=1.0.0"));
    assertTrue(content.contains("aries.test.b;deployed-version=1.1.0"));
    assertTrue(useBundle.contains("aries.test.c;deployed-version=1.0.5"));
    assertFalse(useBundle.contains("aries.test.d"));
    assertTrue(provisioned.contains("aries.test.e;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Attributes(java.util.jar.Attributes) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Aggregations

DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)26 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 ResolverException (org.apache.aries.application.management.ResolverException)17 ModelledResource (org.apache.aries.application.modelling.ModelledResource)10 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)8 Content (org.apache.aries.application.Content)7 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)4 AriesApplication (org.apache.aries.application.management.AriesApplication)4 List (java.util.List)3 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)3 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)2 ServiceUnavailableException (org.osgi.service.blueprint.container.ServiceUnavailableException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Attributes (java.util.jar.Attributes)1 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)1