Search in sources :

Example 16 with ImportedPackage

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

the class ImportedPackageTest method testEqualsForIdenticalPackages.

@Test
public void testEqualsForIdenticalPackages() throws InvalidAttributeException {
    String packageName = "package.name";
    String version = "1.0.0";
    ImportedPackage package1 = instantiatePackage(packageName, version);
    // I should hope so!
    assertEquals(package1, package1);
}
Also used : ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) Test(org.junit.Test)

Example 17 with ImportedPackage

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

the class ImportedPackageTest method testEqualsForEqualPackagesWithVersionRange.

@Test
public void testEqualsForEqualPackagesWithVersionRange() throws InvalidAttributeException {
    String packageName = "package.name";
    String version = "[1.0.0, 1.6.3)";
    ImportedPackage package1 = instantiatePackage(packageName, version);
    ImportedPackage package2 = instantiatePackage(packageName, version);
    assertEquals(package1, package2);
}
Also used : ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) Test(org.junit.Test)

Example 18 with ImportedPackage

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

the class PackageRequirementMergerTest method testMergeMandatoryResolution.

@Test
public void testMergeMandatoryResolution() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0", true));
    reqs.add(newImportedPackage("a", "2.0.0", false));
    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"));
    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 19 with ImportedPackage

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

the class PackageRequirementMergerTest method testMergeInvalidAdditionalAttributes.

@Test
public void testMergeInvalidAdditionalAttributes() 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=blah"));
    reqs.add(newImportedPackage("b", "1.0.0"));
    PackageRequirementMerger merger = new PackageRequirementMerger(reqs);
    Assert.assertFalse(merger.isMergeSuccessful());
    try {
        merger.getMergedRequirements();
        Assert.fail("getMergedRequirements should throw IllegalStateException.");
    } catch (IllegalStateException e) {
    }
    Set<String> result = merger.getInvalidRequirements();
    Set<String> expected = new HashSet<String>();
    expected.add("a");
    Assert.assertEquals(expected, result);
}
Also used : ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with ImportedPackage

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

the class PackageRequirementMergerTest method isEqual.

private static boolean isEqual(Collection<ImportedPackage> reqs1, Collection<ImportedPackage> reqs2) {
    boolean result = true;
    if (reqs1.size() != reqs2.size()) {
        result = false;
    } else {
        for (ImportedPackage r1 : reqs1) {
            boolean foundMatch = false;
            for (ImportedPackage r2 : reqs2) {
                if (!r1.getPackageName().equals(r2.getPackageName())) {
                    continue;
                }
                if (r1.isOptional() != r2.isOptional()) {
                    continue;
                }
                Map<String, String> attribs1 = new HashMap<String, String>(r1.getAttributes());
                Map<String, String> attribs2 = new HashMap<String, String>(r2.getAttributes());
                VersionRange v1 = ManifestHeaderProcessor.parseVersionRange(attribs1.remove(Constants.VERSION_ATTRIBUTE));
                VersionRange v2 = ManifestHeaderProcessor.parseVersionRange(attribs2.remove(Constants.VERSION_ATTRIBUTE));
                if (!v1.equals(v2)) {
                    continue;
                }
                if (!attribs1.equals(attribs2)) {
                    continue;
                }
                foundMatch = true;
                break;
            }
            if (!foundMatch) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) VersionRange(org.apache.aries.util.VersionRange)

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