Search in sources :

Example 16 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeploymentGeneratorTest method checkMultipleCircularDependenciesDetected.

/**
   * This method checks that the a more complicated circular dependency issues the correct error message
   * and checks that the details listed in the exception are correct. 
   * @throws Exception
   */
@Test
public void checkMultipleCircularDependenciesDetected() throws Exception {
    Collection<ModelledResource> cmr = new ArrayList<ModelledResource>();
    ExportedPackage testIsolated1 = createExportedPackage("test.isolated1", "1.0.0", new String[] { "test.isolated1", "test.isolated2" }, new String[] { "test.shared1", "test.shared2" });
    cmr.add(testIsolated1.getBundle());
    ExportedPackage testIsolated2 = createExportedPackage("test.isolated2", "1.0.0", new String[] { "test.isolated1", "test.isolated2" }, new String[] { "test.shared1", "test.shared2" });
    cmr.add(testIsolated2.getBundle());
    ExportedPackage testShared1 = createExportedPackage("test.shared1", "1.0.0", new String[] { "test.shared1", "test.shared2" }, new String[] { "test.isolated1", "test.isolated2" });
    cmr.add(testShared1.getBundle());
    ExportedPackage testShared2 = createExportedPackage("test.shared2", "1.0.0", new String[] { "test.shared1", "test.shared2" }, new String[] { "test.isolated1", "test.isolated2" });
    cmr.add(testShared2.getBundle());
    _resolver.addResult(cmr);
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.isolated1", "1.0.0"), mockContent("test.isolated2", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    try {
        DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { testIsolated1.getBundle(), testIsolated2.getBundle() }), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    } catch (ResolverException rx) {
        // Get the unsatisfied Requirements
        List<String> unsatisfiedReqs = rx.getUnsatisfiedRequirements();
        // Ensure we've got 4 unsatisfied Requirements
        assertEquals("4 unsatisfied requirements expected, but got " + Arrays.toString(unsatisfiedReqs.toArray()), 4, unsatisfiedReqs.size());
        List<String> checkMessages = new ArrayList<String>();
        // Now load an array with the expected messages.
        checkMessages.add("Shared bundle test.shared1_1.0.0 has a dependency for package test.isolated1 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared1_1.0.0 has a dependency for package test.isolated2 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared2_1.0.0 has a dependency for package test.isolated1 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared2_1.0.0 has a dependency for package test.isolated2 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        // because some unsatisfied reqs have spaces at the end of the string.
        for (String unsatisfiedReq : unsatisfiedReqs) {
            assertTrue(unsatisfiedReq + " is not an expected msg", checkMessages.contains(unsatisfiedReq.trim()));
        }
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 17 with ResolverException

use of org.apache.aries.application.management.ResolverException 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 18 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_ValidDuplicatesWithAttributes.

@Test
public void testGetImportPackage_ValidDuplicatesWithAttributes() 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;was_internal=true"), 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 package C 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.c;was_internal=\"true\";version=\"2.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 19 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetRequiredUseBundle_RedundantEntry.

@Test
public void testGetRequiredUseBundle_RedundantEntry() throws Exception {
    // Bundle A requires package B from bundle B with no version requirement.
    // Bundle B requires package C from bundle C with no version requirement.
    // Bundle C requires package B from bundle B with explicit version requirement.
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.USES);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c"), Arrays.asList("package.b;version=1.0.0")));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", Arrays.asList("package.b;version=1.0.0"), Arrays.asList("package.c;version=1.0.0")));
    // Check the redundant use-bundle entry is identified.
    // Bundle C is not required by app content, although it is specified in use-bundle.
    Collection<ModelledResource> requiredUseBundle = null;
    try {
        requiredUseBundle = deployedBundles.getRequiredUseBundle();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    Assert.assertTrue("RequiredUseBundle=" + requiredUseBundle, requiredUseBundle.size() == 1);
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 20 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_rfc138PreventsBundleSymbolicNameWorking.

@Test
public void testGetImportPackage_rfc138PreventsBundleSymbolicNameWorking() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=1.0.0;bundle-symbolic-name=bundle.b"), 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)

Aggregations

ResolverException (org.apache.aries.application.management.ResolverException)26 ArrayList (java.util.ArrayList)20 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)17 Test (org.junit.Test)15 ModelledResource (org.apache.aries.application.modelling.ModelledResource)11 Content (org.apache.aries.application.Content)8 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)6 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)5 HashSet (java.util.HashSet)4 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)4 List (java.util.List)3 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)3 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)3 MethodCall (org.apache.aries.unittest.mocks.MethodCall)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Manifest (java.util.jar.Manifest)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)2