Search in sources :

Example 11 with Content

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

the class DeploymentGeneratorTest method checkBasicCircularDependenciesDetected.

@Test
public void checkBasicCircularDependenciesDetected() throws Exception {
    // Override Resolver behaviour. 
    //ImportedBundle isolated = new ImportedBundleImpl ("test.isolated" , "1.0.0"); 
    // When we resolve isolated, we're going to get another bundle which has a dependency on isolated. 
    Collection<ModelledResource> cmr = new ArrayList<ModelledResource>();
    ExportedPackage testIsolatedPkg = createExportedPackage("test.isolated", "1.0.0", new String[] { "test.shared" }, new String[] { "test.isolated.pkg" });
    cmr.add(testIsolatedPkg.getBundle());
    ExportedPackage testSharedPkg = createExportedPackage("test.shared", "1.0.0", new String[] { "test.isolated.pkg" }, new String[] { "test.shared" });
    cmr.add(testSharedPkg.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.isolated", "1.0.0")));
    try {
        DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, new ArrayList<ModelledResource>(), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    } catch (ResolverException rx) {
        List<String> usr = rx.getUnsatisfiedRequirements();
        assertEquals("One unsatisfied requirement expected, not " + usr.size(), usr.size(), 1);
        String chkMsg = "Shared bundle test.shared_1.0.0 has a dependency for package " + "test.shared which is exported from application bundle [test.isolated_1.0.0]";
        assertTrue(chkMsg + " expected, not " + usr, usr.contains(chkMsg));
        return;
    }
    fail("ResolverException expected");
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) 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 12 with Content

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndProvisionContentButNothingSharedToIsolatedContent.

/**
   * Similar to the checkBundleInAppContentAndProvisionContent scenario. However, this time the provisioned bundle does not provide
   * a package or service to the isolated content, so there is no problem.
   * @throws Exception
   */
@Test
public void checkBundleInAppContentAndProvisionContentButNothingSharedToIsolatedContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.util", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.bundle", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.1.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provisioned", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.util", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    // 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.util", "1.1.0"), mockContent("test.bundle", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(1) }), new ArrayList<Content>());
    Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.util;deployed-version=1.1.0"));
    assertTrue(mf.getMainAttributes().getValue("Provision-Bundle").contains("test.util;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) 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)

Example 13 with Content

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndUseContent.

@Test
public void checkBundleInAppContentAndUseContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    // 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.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "1.0.0")));
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(mockContent("test.api", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
    Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    mf.write(System.out);
    assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.api;deployed-version=1.1.0"));
    assertTrue(mf.getMainAttributes().getValue("Deployed-Use-Bundle").contains("test.api;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) 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)

Example 14 with Content

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndProvisionContent.

@Test
public void checkBundleInAppContentAndProvisionContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    // 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.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "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[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
        fail("Expected exception because we can't provision an isolated bundle twice");
    } catch (ResolverException rx) {
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ResolverException(org.apache.aries.application.management.ResolverException) Content(org.apache.aries.application.Content) 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) Test(org.junit.Test)

Example 15 with Content

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

the class DeploymentManifestManagerImpl method toImportedBundle.

/**
   * Covert a collection of contents to a collection of ImportedBundle objects
   * @param content a collection of content
   * @return a collection of ImportedBundle objects
   * @throws ResolverException
   */
private Set<ImportedBundle> toImportedBundle(Collection<Content> content) throws ResolverException {
    _logger.debug(LOG_ENTRY, "toImportedBundle", new Object[] { content });
    Set<ImportedBundle> result = new HashSet<ImportedBundle>();
    for (Content c : content) {
        try {
            result.add(modellingManager.getImportedBundle(c.getContentName(), c.getVersion().toString()));
        } catch (InvalidAttributeException iax) {
            ResolverException rx = new ResolverException(iax);
            _logger.debug(LOG_EXIT, "toImportedBundle", new Object[] { rx });
            throw rx;
        }
    }
    _logger.debug(LOG_EXIT, "toImportedBundle", new Object[] { result });
    return result;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Content(org.apache.aries.application.Content) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle) HashSet(java.util.HashSet)

Aggregations

Content (org.apache.aries.application.Content)27 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ModelledResource (org.apache.aries.application.modelling.ModelledResource)9 AriesApplication (org.apache.aries.application.management.AriesApplication)8 ResolverException (org.apache.aries.application.management.ResolverException)8 Version (org.osgi.framework.Version)8 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)7 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 DeploymentContent (org.apache.aries.application.DeploymentContent)5 HashMap (java.util.HashMap)4 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4 VersionRange (org.apache.aries.util.VersionRange)4 List (java.util.List)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)3