Author: cziegeler
Date: Mon Jul 31 14:29:24 2017
New Revision: 1803540

URL: http://svn.apache.org/viewvc?rev=1803540&view=rev
Log:
Don't use JSON reader in builder test

Removed:
    sling/whiteboard/cziegeler/feature/src/test/resources/features/process/
Modified:
    
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/FeatureBuilderTest.java

Modified: 
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/FeatureBuilderTest.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/FeatureBuilderTest.java?rev=1803540&r1=1803539&r2=1803540&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/FeatureBuilderTest.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/FeatureBuilderTest.java
 Mon Jul 31 14:29:24 2017
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -31,21 +32,38 @@ import org.apache.sling.feature.Capabili
 import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.Include;
 import org.apache.sling.feature.Requirement;
-import org.apache.sling.feature.json.U;
 import org.junit.Test;
 
 public class FeatureBuilderTest {
 
+    private static final Map<String, Feature> FEATURES = new HashMap<>();
+
+    static {
+        final Feature f1 = new Feature(ArtifactId.fromMvnId("g/a/1"));
+
+        f1.getFrameworkProperties().put("foo", "2");
+        f1.getFrameworkProperties().put("bar", "X");
+
+        f1.getBundles().add(3, new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/foo-bar/4.5.6")));
+        f1.getBundles().add(5, new 
Artifact(ArtifactId.fromMvnId("group/testnewversion_low/2")));
+        f1.getBundles().add(5, new 
Artifact(ArtifactId.fromMvnId("group/testnewversion_high/2")));
+        f1.getBundles().add(5, new 
Artifact(ArtifactId.fromMvnId("group/testnewstartlevel/1")));
+        f1.getBundles().add(5, new 
Artifact(ArtifactId.fromMvnId("group/testnewstartlevelandversion/1")));
+
+        final Configuration c1 = new Configuration("org.apache.sling.foo");
+        c1.getProperties().put("prop", "value");
+        f1.getConfigurations().add(c1);
+
+        FEATURES.put(f1.getId().toMvnId(), f1);
+    }
+
     private final FeatureProvider provider = new FeatureProvider() {
 
         @Override
         public Feature provide(final ArtifactId id) {
-            try {
-                return U.readFeature("process/" + id.getGroupId() + "-" + 
id.getArtifactId() + "-" + id.getVersion());
-            } catch (Exception e) {
-                return null;
-            }
+            return FEATURES.get(id.getGroupId() + "/" + id.getArtifactId() + 
"/" + id.getVersion());
         }
     };
 
@@ -155,7 +173,43 @@ public class FeatureBuilderTest {
     }
 
     @Test public void testNoIncludesNoUpgrade() throws Exception {
-        final Feature base = U.readFeature("process/base");
+        final Feature base = new 
Feature(ArtifactId.fromMvnId("org.apache.sling/test-feature/1.1"));
+
+        final Requirement r1 = new Requirement("osgi.contract");
+        r1.getDirectives().put("filter", 
"(&(osgi.contract=JavaServlet)(version=3.1))");
+        base.getRequirements().add(r1);
+
+        final Capability c1 = new Capability("osgi.implementation");
+        c1.getAttributes().put("osgi.implementation", "osgi.http");
+        c1.getAttributes().put("version:Version", "1.1");
+        c1.getDirectives().put("uses", 
"javax.servlet,javax.servlet.http,org.osgi.service.http.context,org.osgi.service.http.whiteboard");
+        base.getCapabilities().add(c1);
+        final Capability c2 = new Capability("osgi.service");
+        c2.getAttributes().put("objectClass:List<String>", 
"org.osgi.service.http.runtime.HttpServiceRuntime");
+        c2.getDirectives().put("uses", 
"org.osgi.service.http.runtime,org.osgi.service.http.runtime.dto");
+        base.getCapabilities().add(c2);
+
+        base.getFrameworkProperties().put("foo", "1");
+        base.getFrameworkProperties().put("brave", "something");
+        base.getFrameworkProperties().put("org.apache.felix.scr.directory", 
"launchpad/scr");
+
+        final Artifact a1 = new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/oak-server/1.0.0"));
+        a1.getMetadata().put("hash", "4632463464363646436");
+        base.getBundles().add(1, a1);
+        base.getBundles().add(1,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/application-bundle/2.0.0")));
+        base.getBundles().add(1,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/another-bundle/2.1.0")));
+        base.getBundles().add(2,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/foo-xyz/1.2.3")));
+
+        final Configuration co1 = new Configuration("my.pid");
+        co1.getProperties().put("foo", 5L);
+        co1.getProperties().put("bar", "test");
+        co1.getProperties().put("number", 7);
+        base.getConfigurations().add(co1);
+
+        final Configuration co2 = new Configuration("my.factory.pid", "name");
+        co2.getProperties().put("a.value", "yeah");
+        base.getConfigurations().add(co2);
+
         assertFalse(base.isAssembled());
 
         final Feature assembled = FeatureBuilder.assemble(base, provider);
@@ -164,11 +218,60 @@ public class FeatureBuilderTest {
     }
 
     @Test public void testSingleInclude() throws Exception {
-        final Feature base = U.readFeature("process/include-1");
+        final Feature base = new 
Feature(ArtifactId.fromMvnId("org.apache.sling/test-feature/1.1"));
+        final Include i1 = new Include(ArtifactId.fromMvnId("g/a/1"));
+        base.getIncludes().add(i1);
+
+        final Requirement r1 = new Requirement("osgi.contract");
+        r1.getDirectives().put("filter", 
"(&(osgi.contract=JavaServlet)(version=3.1))");
+        base.getRequirements().add(r1);
+
+        final Capability c1 = new Capability("osgi.implementation");
+        c1.getAttributes().put("osgi.implementation", "osgi.http");
+        c1.getAttributes().put("version:Version", "1.1");
+        c1.getDirectives().put("uses", 
"javax.servlet,javax.servlet.http,org.osgi.service.http.context,org.osgi.service.http.whiteboard");
+        base.getCapabilities().add(c1);
+
+        base.getFrameworkProperties().put("foo", "1");
+        base.getFrameworkProperties().put("brave", "something");
+        base.getFrameworkProperties().put("org.apache.felix.scr.directory", 
"launchpad/scr");
+
+        final Artifact a1 = new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/oak-server/1.0.0"));
+        a1.getMetadata().put("hash", "4632463464363646436");
+        base.getBundles().add(1, a1);
+        base.getBundles().add(1,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/application-bundle/2.0.0")));
+        base.getBundles().add(1,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/another-bundle/2.1.0")));
+        base.getBundles().add(2,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/foo-xyz/1.2.3")));
+        base.getBundles().add(5,  new 
Artifact(ArtifactId.fromMvnId("group/testnewversion_low/1")));
+        base.getBundles().add(5,  new 
Artifact(ArtifactId.fromMvnId("group/testnewversion_high/5")));
+        base.getBundles().add(10,  new 
Artifact(ArtifactId.fromMvnId("group/testnewstartlevel/1")));
+        base.getBundles().add(10,  new 
Artifact(ArtifactId.fromMvnId("group/testnewstartlevelandversion/2")));
+
+        final Configuration co1 = new Configuration("my.pid");
+        co1.getProperties().put("foo", 5L);
+        co1.getProperties().put("bar", "test");
+        co1.getProperties().put("number", 7);
+        base.getConfigurations().add(co1);
+
+        final Configuration co2 = new Configuration("my.factory.pid", "name");
+        co2.getProperties().put("a.value", "yeah");
+        base.getConfigurations().add(co2);
+
         assertFalse(base.isAssembled());
 
+        // create the expected result
+        final Feature result = base.copy();
+        result.getIncludes().remove(0);
+        result.getFrameworkProperties().put("bar", "X");
+        result.getBundles().add(3,  new 
Artifact(ArtifactId.fromMvnId("org.apache.sling/foo-bar/4.5.6")));
+        final Configuration co3 = new Configuration("org.apache.sling.foo");
+        co3.getProperties().put("prop", "value");
+        result.getConfigurations().add(co3);
+
+        // assemble
         final Feature assembled = FeatureBuilder.assemble(base, provider);
 
-        equals(U.readFeature("process/result-1"), assembled);
+        // and test
+        equals(result, assembled);
     }
 }


Reply via email to