Search in sources :

Example 11 with ImportedPackage

use of org.apache.aries.application.modelling.ImportedPackage 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 ImportedPackage

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

the class PackageRequirementMergerTest method testMergeValidAdditionalAttributes.

@Test
public void testMergeValidAdditionalAttributes() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0", "foo=bar"));
    reqs.add(newImportedPackage("a", "2.0.0", "foo=bar"));
    PackageRequirementMerger merger = new PackageRequirementMerger(reqs);
    Assert.assertTrue(merger.isMergeSuccessful());
    Assert.assertTrue(merger.getInvalidRequirements().isEmpty());
    Collection<ImportedPackage> result = merger.getMergedRequirements();
    Collection<ImportedPackage> expected = new ArrayList<ImportedPackage>();
    expected.add(newImportedPackage("a", "2.0.0", "foo=bar"));
    Assert.assertTrue(result.toString(), isEqual(result, expected));
}
Also used : ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) Test(org.junit.Test)

Example 13 with ImportedPackage

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

the class ImportedPackageTest method testEqualsForEqualPackagesWithDifferentAttributes.

@Test
public void testEqualsForEqualPackagesWithDifferentAttributes() throws InvalidAttributeException {
    String packageName = "package.name";
    String version = "1.0.0";
    ImportedPackage package1 = instantiatePackage(packageName, version, "att=something");
    ImportedPackage package2 = instantiatePackage(packageName, version, "att=something.else");
    assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Also used : ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) Test(org.junit.Test)

Example 14 with ImportedPackage

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

the class ImportedPackageTest method testEqualsForTrivialPackagesWithDifferentName.

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

Example 15 with ImportedPackage

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

the class ImportedPackageTest method testEqualsForTrivialPackagesWithDifferentVersionRanges.

@Test
public void testEqualsForTrivialPackagesWithDifferentVersionRanges() throws InvalidAttributeException {
    String packageName = "package.name";
    ImportedPackage package1 = instantiatePackage(packageName, "[1.0.0, 4.4.4)");
    ImportedPackage package2 = instantiatePackage(packageName, "[1.0.0, 4.4.2)");
    assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Also used : ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) Test(org.junit.Test)

Aggregations

ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)23 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 PackageRequirementMerger (org.apache.aries.application.modelling.internal.PackageRequirementMerger)7 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)6 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 ResolverException (org.apache.aries.application.management.ResolverException)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)3 Map (java.util.Map)2 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 ImportedService (org.apache.aries.application.modelling.ImportedService)2 VersionRange (org.apache.aries.util.VersionRange)2 List (java.util.List)1 Content (org.apache.aries.application.Content)1 PreResolveHook (org.apache.aries.application.management.spi.resolve.PreResolveHook)1 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1 ImportedPackageImpl (org.apache.aries.application.modelling.impl.ImportedPackageImpl)1