sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [sling-org-apache-sling-feature-modelconverter] 17/40: Support comparing extensions in the conversion tests
Date Fri, 27 Apr 2018 10:01:35 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-org-apache-sling-feature-modelconverter.git

commit c0e97bad492f89c0390813172c25f0dba5d8a095
Author: David Bosschaert <david.bosschaert@gmail.com>
AuthorDate: Thu Mar 22 12:03:25 2018 +0000

    Support comparing extensions in the conversion tests
---
 .../modelconverter/impl/ModelConverterTest.java    | 52 ++++++++++++++-
 src/test/resources/repoinit.json                   | 74 ++++++++++++++++++++
 src/test/resources/repoinit.txt                    | 78 ++++++++++++++++++++++
 3 files changed, 201 insertions(+), 3 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
b/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
index 194d95c..2c0567c 100644
--- a/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
@@ -18,6 +18,8 @@ package org.apache.sling.feature.modelconverter.impl;
 
 import org.apache.sling.feature.Bundles;
 import org.apache.sling.feature.Configurations;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.Extensions;
 import org.apache.sling.feature.support.ArtifactManager;
 import org.apache.sling.feature.support.ArtifactManagerConfig;
 import org.apache.sling.feature.support.FeatureUtil;
@@ -96,7 +98,7 @@ public class ModelConverterTest {
     }
 
     @Test
-    public void testOakProvModel() throws Exception {
+    public void testOakToProvModel() throws Exception {
         testConvertToProvisioningModel("/oak.json", "/oak.txt");
     }
 
@@ -110,6 +112,21 @@ public class ModelConverterTest {
         testConvertFromProvModelRoundTrip("/oak.txt");
     }
 
+    @Test
+    public void testRepoinitToProvModel() throws Exception {
+        testConvertToProvisioningModel("/repoinit.json", "/repoinit.txt");
+    }
+
+    @Test
+    public void testRepoinitToFeature() throws Exception {
+        testConvertToFeature("/repoinit.txt", "/repoinit.json");
+    }
+
+    @Test
+    public void testRepoinitRoundtrip() throws Exception {
+        testConvertFromProvModelRoundTrip("/repoinit.txt");
+    }
+
     public void testConvertFromProvModelRoundTrip(String orgProvModel) throws Exception {
         File inFile = new File(getClass().getResource(orgProvModel).toURI());
         File outJSONFile = new File(tempDir.toFile(), orgProvModel + ".json.generated");
@@ -176,8 +193,9 @@ public class ModelConverterTest {
         assertBundlesEqual(expected.getBundles(), actual.getBundles());
         assertConfigurationsEqual(expected.getConfigurations(), actual.getConfigurations(),
expected.getBundles(), actual.getBundles());
         assertFeatureKVMapEquals(expected.getFrameworkProperties(), actual.getFrameworkProperties());
+        assertExtensionEqual(expected.getExtensions(), actual.getExtensions());
 
-        // Ignore caps and reqs, includes and extensions here since they cannot come from
the prov model.
+        // Ignore caps and reqs, includes and here since they cannot come from the prov model.
     }
 
     private void assertBundlesEqual(Bundles expected, Bundles actual) {
@@ -440,6 +458,33 @@ public class ModelConverterTest {
         assertEquals(featureKvToMap(expected), featureKvToMap(actual));
     }
 
+    private void assertExtensionEqual(Extensions expected, Extensions actual) {
+        assertEquals(expected.size(), actual.size());
+
+        for (int i=0; i<expected.size(); i++) {
+            // TODO support the fact that they may be out of order
+            Extension ex = expected.get(i);
+            Extension ac = actual.get(i);
+
+            assertEquals(ex.getType(), ac.getType());
+            assertEquals(ex.getName(), ac.getName());
+            assertEquals(ex.isRequired(), ac.isRequired());
+
+            String exTxt = ex.getText().replaceAll("\\s+", "");
+            String acTxt = ac.getText().replaceAll("\\s+", "");
+            assertEquals(exTxt, acTxt);
+
+            /* TODO reinstantiate for Artifacts extentions
+            assertEquals(ex.getArtifacts().size(), ac.getArtifacts().size());
+            for (int j = 0; j<ex.getArtifacts().size(); j++) {
+                org.apache.sling.feature.Artifact exa = ex.getArtifacts().get(j);
+                org.apache.sling.feature.Artifact aca = ac.getArtifacts().get(j);
+                assertEquals(exa.getId().toMvnId(), aca.getId().toMvnId());
+            }
+            */
+        }
+    }
+
     private void assertSectionsEqual(List<Section> expected, List<Section> actual)
{
         assertEquals(expected.size(), actual.size());
 
@@ -447,7 +492,8 @@ public class ModelConverterTest {
             Section esec = expected.get(i);
             Section asec = actual.get(i);
             assertEquals(esec.getName(), asec.getName());
-            assertEquals(esec.getContents(), asec.getContents());
+            assertEquals(esec.getContents().replaceAll("\\s+", ""),
+                    asec.getContents().replaceAll("\\s+", ""));
             assertEquals(esec.getAttributes(), asec.getAttributes());
         }
     }
diff --git a/src/test/resources/repoinit.json b/src/test/resources/repoinit.json
new file mode 100644
index 0000000..01d3b16
--- /dev/null
+++ b/src/test/resources/repoinit.json
@@ -0,0 +1,74 @@
+{
+    "#": "this is a comment",
+
+    "id": "org.apache.sling.simple/repoinit/1.0.0",
+    "bundles": [
+        {
+            "id": "org.apache.sling/org.apache.sling.repoinit.parser/1.2.0",
+            "start-level": 20
+        },
+        {
+            "id": "org.apache.sling/org.apache.sling.jcr.repoinit/1.1.6",
+            "start-level": 20
+        },
+        {
+            "id": "org.apache.sling/org.apache.sling.provisioning.model/1.8.4",
+            "start-level": 20
+        }
+    ],
+    "configurations": {
+        "org.apache.sling.jcr.repoinit.impl.RepositoryInitializer": {
+            "references":"model@repoinit:context:/resources/provisioning/model.txt"
+        }
+    },
+    "repoinit:TEXT|false": [
+        "# general",
+        "create path (sling:OrderedFolder) /content",
+        "set ACL for everyone",
+        "    allow   jcr:read	on /content",
+        "end",
+
+        "# sling-mapping",
+        "create service user sling-mapping",
+
+        "set ACL for sling-mapping",
+        "    allow   jcr:read    on /",
+        "end",
+
+        "# sling-readall",
+        "create service user sling-readall",
+
+        "set ACL for sling-readall",
+        "    allow   jcr:read    on /",
+        "end",
+
+        "# sling-xss",
+        "create service user sling-xss",
+
+        "create path (sling:Folder) /libs/sling/xss",
+        "create path (sling:Folder) /apps/sling/xss",
+
+        "set ACL for sling-xss",
+        "    deny    jcr:all     on /",
+        "    allow   jcr:read    on /libs/sling/xss,/apps/sling/xss",
+        "end",
+
+        "# sling-i18n",
+        "create service user sling-i18n",
+
+        "set ACL for sling-i18n",
+        "    allow   jcr:read    on /",
+        "end",
+
+        "# sling-jcr-install",
+        "create service user sling-jcr-install",
+
+        "# used for config OSGi writeback",
+        "create path (sling:Folder) /apps/sling/install",
+
+        "set ACL for sling-jcr-install",
+        "    allow	jcr:read	on	/",
+        "    allow	rep:write	on /apps/sling/install",
+        "end"
+    ]
+}
diff --git a/src/test/resources/repoinit.txt b/src/test/resources/repoinit.txt
new file mode 100644
index 0000000..9e1227b
--- /dev/null
+++ b/src/test/resources/repoinit.txt
@@ -0,0 +1,78 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+[feature name=repoinit]
+
+[artifacts]
+  org.apache.sling/org.apache.sling.repoinit.parser/1.2.0
+  org.apache.sling/org.apache.sling.jcr.repoinit/1.1.6
+  org.apache.sling/org.apache.sling.provisioning.model/1.8.4
+
+[:repoinit]
+    # general
+    create path (sling:OrderedFolder) /content
+    set ACL for everyone
+        allow   jcr:read	on /content
+    end
+
+    # sling-mapping
+    create service user sling-mapping
+
+    set ACL for sling-mapping
+        allow   jcr:read    on /
+    end
+
+    # sling-readall
+    create service user sling-readall
+
+    set ACL for sling-readall
+        allow   jcr:read    on /
+    end
+
+    # sling-xss
+    create service user sling-xss
+
+    create path (sling:Folder) /libs/sling/xss
+    create path (sling:Folder) /apps/sling/xss
+
+    set ACL for sling-xss
+        deny    jcr:all     on /
+        allow   jcr:read    on /libs/sling/xss,/apps/sling/xss
+    end
+
+    # sling-i18n
+    create service user sling-i18n
+
+    set ACL for sling-i18n
+        allow   jcr:read    on /
+    end
+
+    # sling-jcr-install
+    create service user sling-jcr-install
+
+    # used for config OSGi writeback
+    create path (sling:Folder) /apps/sling/install
+
+    set ACL for sling-jcr-install
+        allow	jcr:read	on	/
+        allow	rep:write	on /apps/sling/install
+    end
+
+[configurations]
+  org.apache.sling.jcr.repoinit.impl.RepositoryInitializer
+    references="model@repoinit:context:/resources/provisioning/model.txt"

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

Mime
View raw message