sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [sling-whiteboard] branch master updated: [Feature Model] Remove BundleDescriptorImpl ctor that was only used by test
Date Thu, 26 Apr 2018 13:28:13 GMT
This is an automated email from the ASF dual-hosted git repository.

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a84f34  [Feature Model] Remove BundleDescriptorImpl ctor that was only used by test
3a84f34 is described below

commit 3a84f34bb23bbc471b7eca06a85e1fcb70796386
Author: David Bosschaert <david.bosschaert@gmail.com>
AuthorDate: Thu Apr 26 14:27:25 2018 +0100

    [Feature Model] Remove BundleDescriptorImpl ctor that was only used by test
---
 .../feature/scanner/impl/BundleDescriptorImpl.java |  22 +----
 .../resolver/impl/BundleResourceImplTest.java      | 110 +++++++++------------
 2 files changed, 49 insertions(+), 83 deletions(-)

diff --git a/featuremodel/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
b/featuremodel/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
index d93b89c..d933060 100644
--- a/featuremodel/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
+++ b/featuremodel/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import java.util.stream.Collectors;
@@ -34,8 +33,6 @@ import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.scanner.BundleDescriptor;
 import org.apache.sling.feature.scanner.PackageInfo;
 import org.osgi.framework.Constants;
-import org.osgi.resource.Capability;
-import org.osgi.resource.Requirement;
 
 /**
  * Information about a bundle
@@ -77,23 +74,6 @@ public class BundleDescriptorImpl
         this.lock();
     }
 
-    public BundleDescriptorImpl(final Artifact artifact,
-            final Set<PackageInfo> pcks,
-            final Set<Requirement> reqs,
-            final Set<Capability> caps) throws IOException {
-        this.artifact = artifact;
-        this.artifactFile = null;
-        this.startLevel = 0;
-
-        this.symbolicName = Constants.SYSTEM_BUNDLE_SYMBOLICNAME;
-        this.bundleVersion = artifact.getId().getOSGiVersion().toString();
-        this.getExportedPackages().addAll(pcks);
-        this.getRequirements().addAll(reqs);
-        this.getCapabilities().addAll(caps);
-        this.manifest = null;
-        this.lock();
-    }
-
     /**
      * Get the bundle symbolic name.
      * @return The bundle symbolic name
@@ -211,4 +191,4 @@ public class BundleDescriptorImpl
     public static List<PackageInfo> extractDynamicImportedPackages(final Manifest m)
{
         return extractPackages(m, Constants.DYNAMICIMPORT_PACKAGE, null, false);
     }
-}
\ No newline at end of file
+}
diff --git a/featuremodel/feature-resolver/src/test/java/org/apache/sling/feature/resolver/impl/BundleResourceImplTest.java
b/featuremodel/feature-resolver/src/test/java/org/apache/sling/feature/resolver/impl/BundleResourceImplTest.java
index c829958..0bd9b7d 100644
--- a/featuremodel/feature-resolver/src/test/java/org/apache/sling/feature/resolver/impl/BundleResourceImplTest.java
+++ b/featuremodel/feature-resolver/src/test/java/org/apache/sling/feature/resolver/impl/BundleResourceImplTest.java
@@ -23,10 +23,7 @@ import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.resolver.FeatureResource;
 import org.apache.sling.feature.scanner.BundleDescriptor;
-import org.apache.sling.feature.scanner.Descriptor;
 import org.apache.sling.feature.scanner.impl.BundleDescriptorImpl;
-import org.apache.sling.feature.scanner.PackageInfo;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.Constants;
@@ -41,13 +38,10 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.lang.reflect.Field;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
@@ -59,42 +53,45 @@ import static org.junit.Assert.assertTrue;
 
 public class BundleResourceImplTest {
     @Test
-    public void testResource() {
-        Map<String, List<Capability>> caps = new HashMap<>();
+    public void testResource() throws Exception {
+        String bmf = "Bundle-SymbolicName: foobar\n"
+            + "Bundle-Version: 1.2.3\n"
+            + "Bundle-ManifestVersion: 2\n"
+            + "Provide-Capability: ns.1;ns.1=\"c1\",ns.1;ns.1=\"c2\",ns.2;ns.2=\"c3\"\n"
+            + "Require-Capability: ns.1;mydir:=\"myvalue\"\n";
+        File f = createBundle(bmf);
 
-        Capability c1 = new CapabilityImpl(null, "ns.1", null,
+        Artifact artifact = new Artifact(new ArtifactId("grp", "a.b.c", "1.2.3", null, null));
+        BundleDescriptor bd = new BundleDescriptorImpl(artifact, f, 1);
+        Feature feat = Mockito.mock(Feature.class);
+        FeatureResource res = new BundleResourceImpl(bd, feat);
+
+        Capability c1 = new CapabilityImpl(res, "ns.1", null,
                 Collections.singletonMap("ns.1", "c1"));
-        Capability c2 = new CapabilityImpl(null, "ns.1", null,
+        Capability c2 = new CapabilityImpl(res, "ns.1", null,
                 Collections.singletonMap("ns.1", "c2"));
-        List<Capability> capLst1 = Arrays.asList(c1, c2);
-        caps.put("ns.1", capLst1);
-        Capability c3 = new CapabilityImpl(null, "ns.2", null,
+        List<Capability> expectedCaps1 = Arrays.asList(c1, c2);
+
+        Capability c3 = new CapabilityImpl(res, "ns.2", null,
                 Collections.singletonMap("ns.2", "c3"));
-        List<Capability> capLst2 = Collections.singletonList(c3);
-        caps.put("ns.2", capLst2);
+        List<Capability> expectedCaps2 = Collections.singletonList(c3);
 
-        Requirement r1 = new RequirementImpl(null, "ns.1",
+        Requirement r1 = new RequirementImpl(res, "ns.1",
                 Collections.singletonMap("mydir", "myvalue"), null);
-        List<Requirement> reqList = Collections.singletonList(r1);
-        Artifact art = Mockito.mock(Artifact.class);
-        Feature feat = Mockito.mock(Feature.class);
-        FeatureResource res = new BundleResourceImpl("a.b.c", "1.2.3", art, feat, caps,
-                Collections.singletonMap("ns.1", reqList));
+        List<Requirement> expectedReqs = Collections.singletonList(r1);
 
         assertEquals(0, res.getCapabilities("nonexistent").size());
         assertEquals(0, res.getRequirements("ns.2").size());
-        assertEquals(capLst1, res.getCapabilities("ns.1"));
-        assertEquals(reqList, res.getRequirements("ns.1"));
+        assertEquals(expectedCaps1, res.getCapabilities("ns.1"));
+        assertEquals(expectedReqs, res.getRequirements("ns.1"));
 
         List<Capability> mergedCaps = res.getCapabilities(null);
-        assertEquals(3, mergedCaps.size());
-        assertTrue(mergedCaps.containsAll(capLst1));
-        assertTrue(mergedCaps.containsAll(capLst2));
-        assertEquals(reqList, res.getRequirements(null));
+        assertTrue(mergedCaps.containsAll(expectedCaps1));
+        assertTrue(mergedCaps.containsAll(expectedCaps2));
+        assertEquals(expectedReqs, res.getRequirements(null));
 
-        assertEquals("a.b.c", res.getId());
+        assertEquals("foobar", res.getId());
         assertEquals(new Version("1.2.3"), res.getVersion());
-        assertSame(art, res.getArtifact());
         assertSame(feat, res.getFeature());
     }
 
@@ -108,14 +105,11 @@ public class BundleResourceImplTest {
             + "Bundle-ManifestVersion: 2\n"
             + "Export-Package: org.foo.a;version=0.0.1.SNAPSHOT\n"
             + "Import-Package: org.bar;version=\"[1,2)\",org.tar;resolution:=\"optional\"\n";
-
         File f = createBundle(bmf);
 
-
         BundleDescriptor bd = new BundleDescriptorImpl(artifact, f, 1);
-
-
         Resource res = new BundleResourceImpl(bd, null);
+
         assertNotNull(
                 getCapAttribute(res, BundleNamespace.BUNDLE_NAMESPACE, BundleNamespace.BUNDLE_NAMESPACE));
         assertEquals(new Version("1.2.3"),
@@ -157,43 +151,41 @@ public class BundleResourceImplTest {
 
     @Test
     public void testBundleResourceGenericCapReq() throws Exception {
+        String bmf = "Bundle-SymbolicName: org.apache.someartifact\n"
+            + "Bundle-Version: 0.0.0\n"
+            + "Bundle-ManifestVersion: 2\n"
+            + "Provide-Capability: org.example.cap1;intAttr=\"999\";somedir:=\"mydir\"\n"
+            + "Require-Capability: org.example.req1;adir:=\"aval\";verAttr=\"1.2.3\","
+                + "org.example.req2;adir:=\"aval2\";verAttr=\"3.2.1\"\n";
+        File f = createBundle(bmf);
+
         ArtifactId id = new ArtifactId("org.apache", "org.apache.someartifact", "0.0.0",
null, null);
         Artifact artifact = new Artifact(id);
 
-        Capability cap = new CapabilityImpl(null, "org.example.cap1",
+        BundleDescriptorImpl bd = new BundleDescriptorImpl(artifact, f, 1);
+        Resource res = new BundleResourceImpl(bd, null);
+
+        Capability cap = new CapabilityImpl(res, "org.example.cap1",
                 Collections.singletonMap("somedir", "mydir"),
-                Collections.singletonMap("intAttr", 999));
+                Collections.singletonMap("intAttr", "999"));
         Set<Capability> caps = Collections.singleton(cap);
 
-        Requirement req1 = new RequirementImpl(null, "org.example.req1",
+        Requirement req1 = new RequirementImpl(res, "org.example.req1",
                 Collections.singletonMap("adir", "aval"),
-                Collections.singletonMap("boolAttr", true));
-        Requirement req2 = new RequirementImpl(null, "org.example.req2",
+                Collections.singletonMap("verAttr", "1.2.3"));
+        Requirement req2 = new RequirementImpl(res, "org.example.req2",
                 Collections.singletonMap("adir", "aval2"),
-                Collections.singletonMap("boolAttr", false));
-        Set<Requirement> reqs = new HashSet<>(Arrays.asList(req1, req2));
-        BundleDescriptorImpl bd = new BundleDescriptorImpl(artifact, Collections.emptySet(),
reqs, caps);
-
-        Resource res = new BundleResourceImpl(bd, null);
-
-        Set<Capability> caps2 = new HashSet<>();
-        for (Capability c : res.getCapabilities("org.example.cap1")) {
-            caps2.add(new CapabilityImpl(null, c));
-        }
-        assertEquals(caps, caps2);
+                Collections.singletonMap("verAttr", "3.2.1"));
+        assertEquals(caps, new HashSet<>(res.getCapabilities("org.example.cap1")));
 
-        // For comparison create an expected requirement that has the resource set in it.
-        RequirementImpl expectedReq1 = new RequirementImpl(res.getRequirements("org.example.req1").get(0).getResource(),
req1);
-        assertEquals(Collections.singleton(expectedReq1),
+        assertEquals(Collections.singleton(req1),
                 new HashSet<>(res.getRequirements("org.example.req1")));
-        RequirementImpl expectedReq2 = new RequirementImpl(res.getRequirements("org.example.req2").get(0).getResource(),
req2);
-        assertEquals(Collections.singleton(expectedReq2),
+        assertEquals(Collections.singleton(req2),
                 new HashSet<>(res.getRequirements("org.example.req2")));
-        assertEquals(new HashSet<>(Arrays.asList(expectedReq1, expectedReq2)),
+        assertEquals(new HashSet<>(Arrays.asList(req1, req2)),
                 new HashSet<>(res.getRequirements(null)));
     }
 
-
     private File createBundle(String manifest) throws IOException
     {
         File f = File.createTempFile("bundle", ".jar");
@@ -213,10 +205,4 @@ public class BundleResourceImplTest {
         Capability cap = caps.iterator().next();
         return cap.getAttributes().get(attr);
     }
-
-    private void setField(Class<?> cls, String field, Object obj, Object val) throws
Exception {
-        Field f = cls.getDeclaredField(field);
-        f.setAccessible(true);
-        f.set(obj, val);
-    }
 }

-- 
To stop receiving notification emails like this one, please contact
davidb@apache.org.

Mime
View raw message