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 2021/06/08 14:29:49 UTC

[sling-org-apache-sling-jcr-repoinit] branch SLING-10463 created (now 1a82606)

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

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


      at 1a82606  SLING-10463 - create path fail if a property exists at the same path

This branch includes the following new commits:

     new 42e86e4  SLING-10463 - demonstrate current behavior
     new 1a82606  SLING-10463 - create path fail if a property exists at the same path

The 2 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.


[sling-org-apache-sling-jcr-repoinit] 01/02: SLING-10463 - demonstrate current behavior

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

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

commit 42e86e433d3102c2d4b09a8af60f3837189b6da7
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jun 8 16:21:03 2021 +0200

    SLING-10463 - demonstrate current behavior
---
 .../java/org/apache/sling/jcr/repoinit/CreatePathsTest.java   | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
index cb356d9..edcc692 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
@@ -32,6 +32,7 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 /** Test the creation of paths with specific node types */
 public class CreatePathsTest {
@@ -139,4 +140,14 @@ public class CreatePathsTest {
         Node subFolder2 = subFolder.getNode("subfolder2");
         assertEquals("sling:Folder", subFolder2.getPrimaryNodeType().getName());
     }
+
+    @Test
+    public void createPathWherePropertyExists() throws Exception {
+        final Node folder = U.adminSession.getRootNode().addNode("cpwpe", "nt:unstructured");
+        folder.setProperty("nodeOrProperty", "someValue");
+        folder.getSession().save();
+        final String fullPath = "/cpwpe/nodeOrProperty";
+        U.parseAndExecute("create path " + fullPath);
+        assertTrue(U.adminSession.propertyExists(fullPath));
+    }
 }

[sling-org-apache-sling-jcr-repoinit] 02/02: SLING-10463 - create path fail if a property exists at the same path

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

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

commit 1a82606fb92fc86042b0dc073fa05b2f68b1922b
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jun 8 16:29:31 2021 +0200

    SLING-10463 - create path fail if a property exists at the same path
---
 .../org/apache/sling/jcr/repoinit/impl/AclVisitor.java |  4 +++-
 .../org/apache/sling/jcr/repoinit/CreatePathsTest.java | 18 ++++++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java b/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
index 9e363ef..d20bf61 100644
--- a/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
+++ b/src/main/java/org/apache/sling/jcr/repoinit/impl/AclVisitor.java
@@ -142,7 +142,9 @@ class AclVisitor extends DoNothingVisitor {
         for (PathSegmentDefinition psd : cp.getDefinitions()) {
             final String fullPath = parentPath + "/" + psd.getSegment();
             try {
-                if (session.itemExists(fullPath)) {
+                if (session.propertyExists(fullPath)) {
+                    throw new RuntimeException("Error creating Node at " + fullPath + ": a property exists with the same path");
+                } else if (session.itemExists(fullPath)) {
                     log.info("Path already exists, nothing to do (and not checking its primary type for now): {}", fullPath);
                 } else {
                     final Node parent = parentPath.equals("") ? session.getRootNode() : session.getNode(parentPath);
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
index edcc692..fe83738 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/CreatePathsTest.java
@@ -19,6 +19,7 @@ package org.apache.sling.jcr.repoinit;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.UUID;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -33,6 +34,7 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /** Test the creation of paths with specific node types */
 public class CreatePathsTest {
@@ -143,11 +145,19 @@ public class CreatePathsTest {
 
     @Test
     public void createPathWherePropertyExists() throws Exception {
-        final Node folder = U.adminSession.getRootNode().addNode("cpwpe", "nt:unstructured");
-        folder.setProperty("nodeOrProperty", "someValue");
+        final String testName = "cpwpe";
+        final String propName= "nodeOrProperty";
+        final Node folder = U.adminSession.getRootNode().addNode(testName, "nt:unstructured");
+        folder.setProperty(propName, "someValue");
         folder.getSession().save();
-        final String fullPath = "/cpwpe/nodeOrProperty";
-        U.parseAndExecute("create path " + fullPath);
+        final String fullPath = "/" + testName + "/" + propName;
         assertTrue(U.adminSession.propertyExists(fullPath));
+        try {
+            U.parseAndExecute("create path " + fullPath);
+            fail("Expecting a RuntimeException");
+        } catch(RuntimeException rex) {
+            final String expected = "a property exists";
+            assertTrue(rex.getMessage().contains(expected));
+        }
     }
 }