Search in sources :

Example 11 with ExportedPackage

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

the class AbstractBundleResourceTest method testBundleResource.

@Test
public void testBundleResource() throws Exception {
    assertEquals("The bundle symbolic name is wrong.", "test.bundle1", bundleResource.getSymbolicName());
    assertEquals("The bundle version is wrong.", "2.0.0.build-121", bundleResource.getVersion().toString());
    assertEquals("The bundle presentation name is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    int count = 0;
    for (ImportedPackage ip : bundleResource.getImportedPackages()) {
        String filter = ip.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ip.getPackageName().equals("org.osgi.framework")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "org.osgi.framework");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.3.0");
        } else if (ip.getPackageName().equals("aries.ws.kernel.file")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.kernel.file");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.application.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.application.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Company wrong", parsedFilterElements.get("company"), "yang");
            assertTrue("mandatory filter missing", filter.contains("(mandatory:<*company)"));
        } else if (ip.getPackageName().equals("aries.ws.ffdc")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.ffdc)(version>=0.0.0))", ip.getAttributeFilter());
            assertTrue("Optional import not correctly represented", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.app.framework.plugin")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.app.framework.plugin");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0)");
        } else if (ip.getPackageName().equals("aries.ejs.ras")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ejs.ras");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.event")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.event");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.app.container.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.app.container.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("bundle-symbolic-name"), "B");
            assertEquals("Wrong bundle version", parsedFilterElements.get("bundle-version"), "[1.2.0,2.2.0)");
        } else if (ip.getPackageName().equals("aries.ws.eba.bla")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bla");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.launcher")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.launcher");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0]");
            assertTrue("Dynamic-ImportPackage should be optional", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle4")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle4");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle5")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle5");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle6")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle6");
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle6)(version>=0.0.0))", ip.getAttributeFilter());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle7")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle7)(version>=0.0.0))", ip.getAttributeFilter());
        }
    }
    for (ImportedBundle ib : bundleResource.getRequiredBundles()) {
        String filter = ib.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ib.getSymbolicName().equals("com.acme.facade")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.facade");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ib.getSymbolicName().equals("com.acme.bar")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.bar");
        } else if (ib.getSymbolicName().equals("aries.ws.eba.framework")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "aries.ws.eba.framework");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "(3.0.0,4.0.0)");
        } else if (ib.getSymbolicName().equals("com.de.ba")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.de.ba");
        } else if (ib.getSymbolicName().equals("com.ab.de")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.ab.de");
        }
    }
    for (ImportedService svc : bundleResource.getImportedServices()) {
        if (svc.getInterface().equals("aries.ws.eba.import")) {
            count++;
            String filter = svc.getAttributeFilter();
            Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
            assertEquals("Wrong object class", parsedFilterElements.get("objectClass"), "aries.ws.eba.import");
            assertTrue("(service=service) should be present", svc.getAttributeFilter().contains("(service=service)"));
            assertTrue("(mandatory:<*service) should be present", svc.getAttributeFilter().contains("(mandatory:<*service)"));
        }
    }
    assertEquals("Not all requirements are listed.", bundleResource.getImportedPackages().size() + bundleResource.getImportedServices().size() + bundleResource.getRequiredBundles().size(), count);
    //verify the capability
    int verifiedExport = 0;
    for (ExportedPackage cap : bundleResource.getExportedPackages()) {
        if (cap.getPackageName().equals("aries.ws.eba.bundle1")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "2.2.0", cap.getVersion());
            assertEquals("The export package is not expected.", "test.bundle1", cap.getAttributes().get("bundle-symbolic-name"));
            assertEquals("The export package is not expected.", "2.0.0.build-121", cap.getAttributes().get("bundle-version").toString());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle2")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle3")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        }
    }
    assertEquals("The number of exports are not expected.", bundleResource.getExportedPackages().size(), verifiedExport);
    // bundle resource
    assertEquals("The bundle resource is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    assertEquals("The bundle resource is wrong.", "2.0.0.build-121", bundleResource.getExportedBundle().getVersion());
    assertEquals("The bundle resource is wrong.", "test.bundle1", bundleResource.getExportedBundle().getSymbolicName());
    for (ExportedService svc : bundleResource.getExportedServices()) {
        assertEquals("The export service is wrong", "aries.ws.eba.export", svc.getInterfaces().iterator().next());
    }
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) ImportedService(org.apache.aries.application.modelling.ImportedService) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle) Test(org.junit.Test)

Example 12 with ExportedPackage

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

the class DeployedBundlesImpl method getImportPackage.

/**
   * Get the value corresponding to the Import-Package header in the deployment.mf. 
   * @return a manifest entry, or an empty string if there is no content.
   * @throws ResolverException if the requirements could not be resolved.
   */
public String getImportPackage() throws ResolverException {
    logger.debug(LOG_ENTRY, "getImportPackage");
    String result = cachedImportPackage;
    if (result == null) {
        Collection<ImportedPackage> externalReqs = new ArrayList<ImportedPackage>(getExternalPackageRequirements());
        //Validate that we don't have attributes that will break until RFC138 is used
        validateOtherImports(externalReqs);
        // Find the matching capabilities from bundles in use bundle, and prune
        // matched requirements out of the external requirements collection.
        Map<ImportedPackage, ExportedPackage> useBundlePkgs = new HashMap<ImportedPackage, ExportedPackage>();
        for (Iterator<ImportedPackage> iter = externalReqs.iterator(); iter.hasNext(); ) {
            ImportedPackage req = iter.next();
            ExportedPackage match = getPackageMatch(req, deployedUseBundle);
            if (match != null) {
                useBundlePkgs.put(req, match);
                iter.remove();
            }
        }
        StringBuilder useBundleImports = new StringBuilder();
        for (Map.Entry<ImportedPackage, ExportedPackage> entry : useBundlePkgs.entrySet()) {
            useBundleImports.append(entry.getValue().toDeploymentString());
            ImportedPackage key = entry.getKey();
            if (key.isOptional())
                useBundleImports.append(";" + Constants.RESOLUTION_DIRECTIVE + ":=" + Constants.RESOLUTION_OPTIONAL);
            useBundleImports.append(",");
        }
        result = useBundleImports.toString() + createManifestString(externalReqs);
        if (result.endsWith(","))
            result = result.substring(0, result.length() - 1);
        cachedImportPackage = result;
    }
    logger.debug(LOG_EXIT, "getImportPackage", result);
    return result;
}
Also used : HashMap(java.util.HashMap) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with ExportedPackage

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

the class ExportedPackageImpl method equals.

@Override
public boolean equals(Object thing) {
    if (thing == this) {
        return true;
    } else {
        if (thing instanceof ExportedPackage) {
            ExportedPackage otherPackage = (ExportedPackage) thing;
            if (!this.getPackageName().equals(otherPackage.getPackageName())) {
                return false;
            }
            if (!this.getVersion().equals(otherPackage.getVersion())) {
                return false;
            }
            if (!this.getPackageName().equals(otherPackage.getPackageName())) {
                return false;
            }
            // We'll pick up the bundle comparisons in the attributes
            Map<String, Object> otherAttributes = otherPackage.getAttributes();
            if (!attributesAreEqual(otherAttributes)) {
                return false;
            }
        }
        return true;
    }
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage)

Example 14 with ExportedPackage

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

the class ExportedPackageTest method testEqualsForTrivialPackagesWithDifferentVersion.

@Test
public void testEqualsForTrivialPackagesWithDifferentVersion() {
    String packageName = "package.name";
    ExportedPackage package1 = instantiatePackage(packageName, "1.0.0");
    ExportedPackage package2 = instantiatePackage(packageName, "1.0.1");
    assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Test(org.junit.Test)

Example 15 with ExportedPackage

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

the class ExportedPackageTest method testEqualsForTrivialPackagesWithDifferentName.

@Test
public void testEqualsForTrivialPackagesWithDifferentName() {
    String version = "1.0.0";
    ExportedPackage package1 = instantiatePackage("package.name", version);
    ExportedPackage package2 = instantiatePackage("other.package.name", version);
    assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Test(org.junit.Test)

Aggregations

ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)15 Test (org.junit.Test)8 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)6 ModelledResource (org.apache.aries.application.modelling.ModelledResource)6 ArrayList (java.util.ArrayList)5 ResolverException (org.apache.aries.application.management.ResolverException)4 List (java.util.List)3 Content (org.apache.aries.application.Content)3 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 ImportedService (org.apache.aries.application.modelling.ImportedService)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2 HashSet (java.util.HashSet)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 AriesApplication (org.apache.aries.application.management.AriesApplication)1 PreResolveHook (org.apache.aries.application.management.spi.resolve.PreResolveHook)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1