You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/01/21 12:12:50 UTC

[sling-org-apache-sling-jcr-repoinit] branch master updated (52c923f -> d07f175)

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git.


    from 52c923f  [maven-release-plugin] prepare for next development iteration
     new 421f8b2  SLING-9015 - refactor tests
     new 2a55298  SLING-9015 - RepositoryInitializerFactoryIT implemented but fails semi-randomly
     new 5e1cfd4  SLING-9015 - RepositoryInitializerFactoryIT works, with one test commented out
     new d07f175  SLING-9015 - fix null/empty checks and activate corresponding test

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  10 +-
 .../impl/RepositoryInitializerFactory.java         |   6 ++
 .../sling/jcr/repoinit/it/RepoInitTestSupport.java |  94 +++++++++++++++--
 .../sling/jcr/repoinit/it/RepoInitTextIT.java      |  16 +--
 .../it/RepositoryInitializerFactoryIT.java         | 111 +++++++++++++++++++++
 .../jcr/repoinit/it/RepositoryInitializerIT.java   |  45 +++------
 .../{repoinit-path-1.txt => repoinit-path-3.txt}   |   2 +-
 .../{repoinit-path-1.txt => repoinit-path-4.txt}   |   2 +-
 .../{repoinit-path-1.txt => repoinit-path-5.txt}   |   2 +-
 9 files changed, 230 insertions(+), 58 deletions(-)
 create mode 100644 src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
 copy src/test/resources/{repoinit-path-1.txt => repoinit-path-3.txt} (96%)
 copy src/test/resources/{repoinit-path-1.txt => repoinit-path-4.txt} (96%)
 copy src/test/resources/{repoinit-path-1.txt => repoinit-path-5.txt} (96%)


[sling-org-apache-sling-jcr-repoinit] 02/04: SLING-9015 - RepositoryInitializerFactoryIT implemented but fails semi-randomly

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2a5529806f863158f15443f6221b9afa1125abbe
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jan 21 09:34:13 2020 +0100

    SLING-9015 - RepositoryInitializerFactoryIT implemented but fails semi-randomly
---
 pom.xml                                            |   8 +-
 .../sling/jcr/repoinit/it/RepoInitTestSupport.java |  81 +++++++++++-
 .../sling/jcr/repoinit/it/RepoInitTextIT.java      |  16 +--
 .../it/RepositoryInitializerFactoryIT.java         | 137 +++++++++++++++++++++
 .../jcr/repoinit/it/RepositoryInitializerIT.java   |  29 +----
 src/test/resources/repoinit-path-3.txt             |  20 +++
 src/test/resources/repoinit-path-4.txt             |  20 +++
 src/test/resources/repoinit-path-5.txt             |  20 +++
 src/test/resources/repoinit-path-6.txt             |  20 +++
 9 files changed, 304 insertions(+), 47 deletions(-)

diff --git a/pom.xml b/pom.xml
index ad8c69b..cf873b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,8 @@
   <properties>
     <jackrabbit.version>2.18.2</jackrabbit.version>
     <oak.version>1.16.0</oak.version>
+    <!-- To debug the pax process, override this with -D -->
+    <pax.vm.options>-Ddefault.pom.options=unused</pax.vm.options>
   </properties>
 
   <scm>
@@ -92,6 +94,10 @@
                         <name>repoinit.test.files.path</name>
                         <value>${basedir}/src/test/resources</value>
                         </property>
+                        <property>
+                        <name>pax.vm.options</name>
+                        <value>${pax.vm.options}</value>
+                        </property>
                     </systemProperties>
                 </configuration>
             </plugin>
@@ -132,7 +138,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.paxexam</artifactId>
-            <version>3.0.0</version>
+            <version>3.1.0</version>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
index e467d08..5322b90 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
@@ -17,24 +17,46 @@
 package org.apache.sling.jcr.repoinit.it;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.testing.paxexam.SlingOptions;
 import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.After;
+import org.junit.Before;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.options.CompositeOption;
 
 import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
 import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
 
 public abstract class RepoInitTestSupport extends TestSupport {
 
+    protected Session session;
+
+    @Inject
+    private SlingRepository repository;
+
     @Configuration
     public Option[] configuration() {
         SlingOptions.versionResolver.setVersionFromProject("org.apache.jackrabbit", "jackrabbit-api");
-        final Option[] options = {
+        final Option[] options = 
+        remove(new Option[] {
+            vmOption(System.getProperty("pax.vm.options")),
             baseConfiguration(),
             slingQuickstart(),
             testBundle("bundle.filename"),
@@ -43,8 +65,12 @@ public abstract class RepoInitTestSupport extends TestSupport {
             newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
                 .put("whitelist.bundles.regexp", "^PAXEXAM.*$")
                 .asOption()
-        };
-        return ArrayUtils.addAll(options, additionalOptions());
+            },
+        // remove our bundle under test to avoid duplication
+        mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.jcr.repoinit").version(versionResolver)
+        );
+        final Option[] allOptions = ArrayUtils.addAll(options, additionalOptions());
+        return allOptions;
     }
 
     protected Option[] additionalOptions() {
@@ -58,4 +84,53 @@ public abstract class RepoInitTestSupport extends TestSupport {
             slingQuickstartOakTar(workingDirectory, httpPort)
         );
     }
+
+    static String getRepoinitFilesPath() {
+        return System.getProperty("repoinit.test.files.path");
+    }
+
+    @Before
+    public void setupSession() throws Exception {
+        if(session == null) {
+            session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        }
+    }
+
+    @After
+    public void cleanupSession() {
+        if(session != null) {
+            session.logout();
+        }
+    }
+
+    // TODO should come from org.apache.sling.testing.paxexam
+    private static List<Option> expand(final Option[] options) {
+        final List<Option> expanded = new ArrayList<>();
+        if (options != null) {
+            for (final Option option : options) {
+                if (option != null) {
+                    if (option instanceof CompositeOption) {
+                        expanded.addAll(Arrays.asList(((CompositeOption) option).getOptions()));
+                    } else {
+                        expanded.add(option);
+                    }
+                }
+            }
+        }
+        return expanded;
+    }
+
+    // TODO should come from org.apache.sling.testing.paxexam
+    private static Option[] remove(final Option[] options, final Option... removables) {
+        final List<Option> expanded = expand(options);
+        for (final Option removable : removables) {
+            if (removable instanceof CompositeOption) {
+                expanded.removeAll(Arrays.asList(((CompositeOption) removable).getOptions()));
+            } else {
+                expanded.removeAll(Collections.singleton(removable));
+            }
+        }
+        return expanded.toArray(new Option[0]);
+    }
+
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
index 395b342..b9a7d3a 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
@@ -26,12 +26,9 @@ import java.util.UUID;
 
 import javax.inject.Inject;
 import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
 
-import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
 import org.apache.sling.repoinit.parser.RepoInitParser;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,16 +43,12 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 @ExamReactorStrategy(PerClass.class)
 public class RepoInitTextIT extends RepoInitTestSupport {
 
-    private Session session;
     private static final String FRED_WILMA = "fredWilmaService";
     private static final String ANOTHER = "anotherService";
 
     public static final String REPO_INIT_FILE = "/repoinit.txt";
 
     @Inject
-    private SlingRepository repository;
-
-    @Inject
     private RepoInitParser parser;
 
     @Inject
@@ -63,7 +56,7 @@ public class RepoInitTextIT extends RepoInitTestSupport {
 
     @Before
     public void setup() throws Exception {
-        session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        setupSession();
 
         // Execute some repoinit statements
         final InputStream is = getClass().getResourceAsStream(REPO_INIT_FILE);
@@ -79,13 +72,6 @@ public class RepoInitTextIT extends RepoInitTestSupport {
         assertTrue("Expecting test nodes to be created", session.itemExists("/acltest/A/B"));
     }
 
-    @After
-    public void cleanup() {
-        if(session != null) {
-            session.logout();
-        }
-    }
-
     @Test
     public void serviceUserCreated() throws Exception {
         new Retry() {
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
new file mode 100644
index 0000000..05604bc
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
@@ -0,0 +1,137 @@
+/*
+ * 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.
+ */
+package org.apache.sling.jcr.repoinit.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** Verify the RepositoryInitializerFactory functionality, to execute
+ *  repoinit statements coming from OSGi configurations
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class RepositoryInitializerFactoryIT extends RepoInitTestSupport {
+
+    @Inject
+    private ConfigurationAdmin configAdmin;
+
+    private static final String TEST_MARKER = "TEST_MARKER";
+    private static final String TEST_MARKER_VALUE = "TEST_VALUE";
+
+    @Override
+    protected Option[] additionalOptions() {
+        return new Option[] {
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("scripts", "create path /repoinit-test/scripts/A")
+            .asOption(),
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("scripts", "create path /repoinit-test/scripts/B")
+            .put("references", "")
+            .asOption(),
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("scripts", "create path /repoinit-test/scripts/C")
+            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-3.txt")
+            .asOption(),
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-4.txt")
+            .asOption(),
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-5.txt")
+            .put("scripts", "")
+            .asOption(),
+            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+            .put(TEST_MARKER, TEST_MARKER_VALUE)
+            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-6.txt")
+            .put("scripts", "create path /repoinit-test/scripts/D")
+            .asOption(),
+        };
+    }
+
+    private List<String> getMissingPaths() throws Exception {
+        final String [] paths = {
+            "/repoinit-test/scripts/A",
+            // TODO fails due to SLING-9015  ?? "/repoinit-test/scripts/B", 
+            "/repoinit-test/scripts/C",
+            "/repoinit-test/scripts/D",
+            "/repoinit-test/path-3",
+            "/repoinit-test/path-4",
+            "/repoinit-test/path-5",
+            "/repoinit-test/path-6",
+        };
+        final List<String> missing = new ArrayList<>();
+        for(String path : paths) {
+            if(!session.itemExists(path)) {
+                missing.add(path);
+            }
+        }
+        return missing;
+    }
+
+    @Test
+    public void allConfigsRegistered() throws Exception {
+        int markerCount = 0;
+        for(Configuration cfg : configAdmin.listConfigurations(null)) {
+            if(cfg.getProperties().get(TEST_MARKER) != null) {
+                markerCount++;
+            }
+        }
+
+        // allPathsCreated fails semi-randomly, trying to find out what's happening
+        final int expectedMarkers = 6;
+        assertEquals("Expecting the correct amount of registered configs", expectedMarkers, markerCount);
+    }
+
+    @Test
+    public void allPathsCreated() throws Exception {
+        final long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(15);
+        List<String> missing = null;
+
+        // Configs are processed asynchronously, give them some time
+        while(System.currentTimeMillis() < endTime) {
+            missing = getMissingPaths();
+            if(missing.isEmpty()) {
+                break;
+            }
+            Thread.sleep(250);
+        }
+        assertTrue("Expecting all paths to be created, missing: " + missing, missing.isEmpty());
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
index 74e567d..3173009 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
@@ -19,13 +19,6 @@ package org.apache.sling.jcr.repoinit.it;
 import static org.junit.Assert.assertTrue;
 import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
 
-import javax.inject.Inject;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
-import org.apache.sling.jcr.api.SlingRepository;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -45,11 +38,7 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
         "raw:file://" + getRepoinitFilesPath() + "/repoinit-path-2.txt",
     };
 
-    private Session session;
-
-    @Inject
-    private SlingRepository repository;
-
+    @Override
     protected Option[] additionalOptions() {
         return new Option[] {
             newConfiguration("org.apache.sling.jcr.repoinit.impl.RepositoryInitializer")
@@ -58,18 +47,6 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
         };
     }
 
-    @Before
-    public void setup() throws Exception {
-        session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
-    }
-
-    @After
-    public void cleanup() {
-        if(session != null) {
-            session.logout();
-        }
-    }
-
     @Test
     public void path1Created() throws Exception {
         assertTrue(session.itemExists("/repoinit-test/path-1"));
@@ -79,8 +56,4 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
     public void path2Created() throws Exception {
         assertTrue(session.itemExists("/repoinit-test/path-2"));
     }
-
-    static String getRepoinitFilesPath() {
-        return System.getProperty("repoinit.test.files.path");
-    }
 }
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-3.txt b/src/test/resources/repoinit-path-3.txt
new file mode 100644
index 0000000..126c6f6
--- /dev/null
+++ b/src/test/resources/repoinit-path-3.txt
@@ -0,0 +1,20 @@
+#
+#  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.
+#
+
+create path /repoinit-test/path-3
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-4.txt b/src/test/resources/repoinit-path-4.txt
new file mode 100644
index 0000000..bb2c975
--- /dev/null
+++ b/src/test/resources/repoinit-path-4.txt
@@ -0,0 +1,20 @@
+#
+#  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.
+#
+
+create path /repoinit-test/path-4
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-5.txt b/src/test/resources/repoinit-path-5.txt
new file mode 100644
index 0000000..9e28f7d
--- /dev/null
+++ b/src/test/resources/repoinit-path-5.txt
@@ -0,0 +1,20 @@
+#
+#  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.
+#
+
+create path /repoinit-test/path-5
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-6.txt b/src/test/resources/repoinit-path-6.txt
new file mode 100644
index 0000000..5fd1ba9
--- /dev/null
+++ b/src/test/resources/repoinit-path-6.txt
@@ -0,0 +1,20 @@
+#
+#  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.
+#
+
+create path /repoinit-test/path-6
\ No newline at end of file


[sling-org-apache-sling-jcr-repoinit] 04/04: SLING-9015 - fix null/empty checks and activate corresponding test

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d07f175296127c8448aaf930385baf9cdbeada4c
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jan 21 13:10:50 2020 +0100

    SLING-9015 - fix null/empty checks and activate corresponding test
---
 .../sling/jcr/repoinit/impl/RepositoryInitializerFactory.java       | 6 ++++++
 .../sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java       | 2 --
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
index b82f00c..3eae372 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializerFactory.java
@@ -106,6 +106,9 @@ public class RepositoryInitializerFactory implements SlingRepositoryInitializer
                 if ( config.references() != null ) {
                     final RepoinitTextProvider p = new RepoinitTextProvider();
                     for(final String reference : config.references()) {
+                        if(reference == null || reference.trim().length() == 0) {
+                            continue;
+                        }
                         final String repoinitText = p.getRepoinitText("raw:" + reference);
                         final List<Operation> ops = parser.parse(new StringReader(repoinitText));
                         log.info("Executing {} repoinit operations", ops.size());
@@ -115,6 +118,9 @@ public class RepositoryInitializerFactory implements SlingRepositoryInitializer
                 }
                 if ( config.scripts() != null ) {
                     for(final String script : config.scripts()) {
+                        if(script == null || script.trim().length() == 0) {
+                            continue;
+                        }
                         final List<Operation> ops = parser.parse(new StringReader(script));
                         log.info("Executing {} repoinit operations", ops.size());
                         processor.apply(s, ops);
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
index e3e5c86..36c00b5 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
@@ -87,12 +87,10 @@ public class RepositoryInitializerFactoryIT extends RepoInitTestSupport {
             "create path /repoinit-test/scripts/A", 
             "/repoinit-test/scripts/A");
 
-        /* Fails due to SLING-9015 
         assertConfigAndPaths(
             "", 
             "create path /repoinit-test/scripts/B", 
             "/repoinit-test/scripts/B");
-        */
 
         assertConfigAndPaths(
             getTestFileUrl("/repoinit-path-3.txt"), 


[sling-org-apache-sling-jcr-repoinit] 01/04: SLING-9015 - refactor tests

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 421f8b22ad17e41e39135e1fb95074ea6e93cb5a
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jan 20 15:08:49 2020 +0100

    SLING-9015 - refactor tests
---
 .../apache/sling/jcr/repoinit/it/RepoInitTestSupport.java   | 13 ++++++++-----
 .../sling/jcr/repoinit/it/RepositoryInitializerIT.java      | 10 ++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
index a22ea4f..e467d08 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.jcr.repoinit.it;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.sling.testing.paxexam.SlingOptions;
 import org.apache.sling.testing.paxexam.TestSupport;
 import org.ops4j.pax.exam.Configuration;
@@ -33,7 +34,7 @@ public abstract class RepoInitTestSupport extends TestSupport {
     @Configuration
     public Option[] configuration() {
         SlingOptions.versionResolver.setVersionFromProject("org.apache.jackrabbit", "jackrabbit-api");
-        return new Option[]{
+        final Option[] options = {
             baseConfiguration(),
             slingQuickstart(),
             testBundle("bundle.filename"),
@@ -41,11 +42,13 @@ public abstract class RepoInitTestSupport extends TestSupport {
             junitBundles(),
             newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
                 .put("whitelist.bundles.regexp", "^PAXEXAM.*$")
-                .asOption(),        
-            newConfiguration("org.apache.sling.jcr.repoinit.impl.RepositoryInitializer")
-                .put("references", RepositoryInitializerIT.REPOINIT_SRC_URLS)
-                .asOption(),
+                .asOption()
         };
+        return ArrayUtils.addAll(options, additionalOptions());
+    }
+
+    protected Option[] additionalOptions() {
+        return new Option[] {};
     }
 
     protected Option slingQuickstart() {
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
index 292ddb2..74e567d 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
@@ -17,6 +17,7 @@
 package org.apache.sling.jcr.repoinit.it;
 
 import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
 
 import javax.inject.Inject;
 import javax.jcr.Session;
@@ -27,6 +28,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
@@ -48,6 +50,14 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
     @Inject
     private SlingRepository repository;
 
+    protected Option[] additionalOptions() {
+        return new Option[] {
+            newConfiguration("org.apache.sling.jcr.repoinit.impl.RepositoryInitializer")
+            .put("references", RepositoryInitializerIT.REPOINIT_SRC_URLS)
+            .asOption()
+        };
+    }
+
     @Before
     public void setup() throws Exception {
         session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));


[sling-org-apache-sling-jcr-repoinit] 03/04: SLING-9015 - RepositoryInitializerFactoryIT works, with one test commented out

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5e1cfd4cff6a82ff335bfcd5fcd9f032c0e092cd
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jan 21 13:04:47 2020 +0100

    SLING-9015 - RepositoryInitializerFactoryIT works, with one test commented out
---
 pom.xml                                            |   6 +-
 .../sling/jcr/repoinit/it/RepoInitTestSupport.java |   8 +-
 .../it/RepositoryInitializerFactoryIT.java         | 134 +++++++++------------
 .../jcr/repoinit/it/RepositoryInitializerIT.java   |  12 +-
 src/test/resources/repoinit-path-6.txt             |  20 ---
 5 files changed, 69 insertions(+), 111 deletions(-)

diff --git a/pom.xml b/pom.xml
index cf873b7..00c768d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,16 +85,14 @@
                 </executions>
                 <configuration>
                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                    <!-- pax exam bug, often times out at exit -->
+                    <forkedProcessExitTimeoutInSeconds>1</forkedProcessExitTimeoutInSeconds>
                     <systemProperties>
                         <property>
                         <name>bundle.filename</name>
                         <value>${basedir}/target/${project.build.finalName}.jar</value>
                         </property>
                         <property>
-                        <name>repoinit.test.files.path</name>
-                        <value>${basedir}/src/test/resources</value>
-                        </property>
-                        <property>
                         <name>pax.vm.options</name>
                         <value>${pax.vm.options}</value>
                         </property>
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
index 5322b90..cd0eb65 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
@@ -25,6 +25,8 @@ import org.junit.Before;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.options.CompositeOption;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
 import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
@@ -48,6 +50,8 @@ public abstract class RepoInitTestSupport extends TestSupport {
 
     protected Session session;
 
+    protected static final Logger log = LoggerFactory.getLogger(RepoInitTestSupport.class.getName());
+
     @Inject
     private SlingRepository repository;
 
@@ -85,8 +89,8 @@ public abstract class RepoInitTestSupport extends TestSupport {
         );
     }
 
-    static String getRepoinitFilesPath() {
-        return System.getProperty("repoinit.test.files.path");
+    public String getTestFileUrl(String path) {
+        return getClass().getResource(path).toExternalForm();
     }
 
     @Before
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
index 05604bc..e3e5c86 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
@@ -16,21 +16,19 @@
  */
 package org.apache.sling.jcr.repoinit.it;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
 
-import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
@@ -47,91 +45,69 @@ public class RepositoryInitializerFactoryIT extends RepoInitTestSupport {
     @Inject
     private ConfigurationAdmin configAdmin;
 
-    private static final String TEST_MARKER = "TEST_MARKER";
-    private static final String TEST_MARKER_VALUE = "TEST_VALUE";
-
-    @Override
-    protected Option[] additionalOptions() {
-        return new Option[] {
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("scripts", "create path /repoinit-test/scripts/A")
-            .asOption(),
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("scripts", "create path /repoinit-test/scripts/B")
-            .put("references", "")
-            .asOption(),
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("scripts", "create path /repoinit-test/scripts/C")
-            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-3.txt")
-            .asOption(),
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-4.txt")
-            .asOption(),
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-5.txt")
-            .put("scripts", "")
-            .asOption(),
-            factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
-            .put(TEST_MARKER, TEST_MARKER_VALUE)
-            .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-6.txt")
-            .put("scripts", "create path /repoinit-test/scripts/D")
-            .asOption(),
-        };
-    }
-
-    private List<String> getMissingPaths() throws Exception {
-        final String [] paths = {
-            "/repoinit-test/scripts/A",
-            // TODO fails due to SLING-9015  ?? "/repoinit-test/scripts/B", 
-            "/repoinit-test/scripts/C",
-            "/repoinit-test/scripts/D",
-            "/repoinit-test/path-3",
-            "/repoinit-test/path-4",
-            "/repoinit-test/path-5",
-            "/repoinit-test/path-6",
-        };
-        final List<String> missing = new ArrayList<>();
-        for(String path : paths) {
-            if(!session.itemExists(path)) {
-                missing.add(path);
-            }
+    private void assertConfigAndPaths(String references, String scripts, String ... expectedPaths) throws Exception {
+        for(String path : expectedPaths) {
+            assertFalse("Expecting path to be absent before test:" + path, session.itemExists(path));
         }
-        return missing;
-    }
 
-    @Test
-    public void allConfigsRegistered() throws Exception {
-        int markerCount = 0;
-        for(Configuration cfg : configAdmin.listConfigurations(null)) {
-            if(cfg.getProperties().get(TEST_MARKER) != null) {
-                markerCount++;
-            }
+        final Dictionary<String, Object> props = new Hashtable<>();
+        if(references != null) {
+            props.put("references", references);
         }
-
-        // allPathsCreated fails semi-randomly, trying to find out what's happening
-        final int expectedMarkers = 6;
-        assertEquals("Expecting the correct amount of registered configs", expectedMarkers, markerCount);
-    }
-
-    @Test
-    public void allPathsCreated() throws Exception {
-        final long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(15);
-        List<String> missing = null;
+        if(scripts != null) {
+            props.put("scripts", scripts);
+        }
+        final Configuration cfg = configAdmin.createFactoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer");
+        cfg.setBundleLocation(null);
+        cfg.update(props);
 
         // Configs are processed asynchronously, give them some time
+        final long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(5);
+        List<String> missing = null;
         while(System.currentTimeMillis() < endTime) {
-            missing = getMissingPaths();
+            session.refresh(false);
+            missing = new ArrayList<>();
+            for(String path : expectedPaths) {
+                if(!session.itemExists(path)) {
+                    missing.add(path);
+                }
+            }
             if(missing.isEmpty()) {
                 break;
             }
             Thread.sleep(250);
         }
-        assertTrue("Expecting all paths to be created, missing: " + missing, missing.isEmpty());
+        assertTrue("Expected all paths to be created, missing: " + missing, missing.isEmpty());
     }
 
+    @Test
+    public void testReferencesAndScripts() throws Exception {
+        assertConfigAndPaths(
+            null, 
+            "create path /repoinit-test/scripts/A", 
+            "/repoinit-test/scripts/A");
+
+        /* Fails due to SLING-9015 
+        assertConfigAndPaths(
+            "", 
+            "create path /repoinit-test/scripts/B", 
+            "/repoinit-test/scripts/B");
+        */
+
+        assertConfigAndPaths(
+            getTestFileUrl("/repoinit-path-3.txt"), 
+            "create path /repoinit-test/scripts/C", 
+            "/repoinit-test/path-3",
+            "/repoinit-test/scripts/C");
+
+        assertConfigAndPaths(
+            getTestFileUrl("/repoinit-path-4.txt"), 
+                null,
+                "/repoinit-test/path-4");
+
+        assertConfigAndPaths(
+            getTestFileUrl("/repoinit-path-5.txt"), 
+                "", 
+                "/repoinit-test/path-5");
+    }
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
index 3173009..beac5e7 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
@@ -33,16 +33,16 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 @ExamReactorStrategy(PerClass.class)
 public class RepositoryInitializerIT extends RepoInitTestSupport {
 
-    static final String [] REPOINIT_SRC_URLS = {
-        "raw:file://" + getRepoinitFilesPath() + "/repoinit-path-1.txt",
-        "raw:file://" + getRepoinitFilesPath() + "/repoinit-path-2.txt",
-    };
-
     @Override
     protected Option[] additionalOptions() {
+        final String [] srcUrls = {
+            "raw:" + getTestFileUrl("/repoinit-path-1.txt"),
+            "raw:" + getTestFileUrl("/repoinit-path-2.txt")
+        };
+
         return new Option[] {
             newConfiguration("org.apache.sling.jcr.repoinit.impl.RepositoryInitializer")
-            .put("references", RepositoryInitializerIT.REPOINIT_SRC_URLS)
+            .put("references", srcUrls)
             .asOption()
         };
     }
diff --git a/src/test/resources/repoinit-path-6.txt b/src/test/resources/repoinit-path-6.txt
deleted file mode 100644
index 5fd1ba9..0000000
--- a/src/test/resources/repoinit-path-6.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-#  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.
-#
-
-create path /repoinit-test/path-6
\ No newline at end of file