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

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

commit 256c502ef04f3af04e7e4cc1be8d902c63dfebe4
Author: Stefan Seifert <[email protected]>
AuthorDate: Wed Sep 16 19:25:11 2015 +0000

    SLING-4381/SLING-5024 fix root node child listing
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1703453 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../nosql/generic/resource/impl/PathUtil.java      |  4 ++-
 .../AbstractNoSqlResourceProviderRootTest.java     | 34 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/sling/nosql/generic/resource/impl/PathUtil.java 
b/src/main/java/org/apache/sling/nosql/generic/resource/impl/PathUtil.java
index a4a59b0..8af73e6 100644
--- a/src/main/java/org/apache/sling/nosql/generic/resource/impl/PathUtil.java
+++ b/src/main/java/org/apache/sling/nosql/generic/resource/impl/PathUtil.java
@@ -20,6 +20,8 @@ package org.apache.sling.nosql.generic.resource.impl;
 
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang3.StringUtils;
+
 /**
  * Helper functions for handling paths.
  */
@@ -35,7 +37,7 @@ public final class PathUtil {
      * @return Regex pattern
      */
     public static Pattern getChildPathPattern(String parentPath) {
-        return Pattern.compile("^" + Pattern.quote(parentPath) + "/[^/]+$");
+        return Pattern.compile("^" + 
Pattern.quote(StringUtils.removeEnd(parentPath,  "/")) + "/[^/]+$");
     }
     
     /**
diff --git 
a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
 
b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
index 3b4966f..82d88f0 100644
--- 
a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
+++ 
b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
@@ -18,9 +18,14 @@
  */
 package org.apache.sling.nosql.generic.resource.impl;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.sling.api.resource.ModifiableValueMap;
 import org.apache.sling.api.resource.PersistenceException;
@@ -34,6 +39,7 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 
 /**
  * Test monting NoSqlResourceProvider as root resource provider.
@@ -77,6 +83,34 @@ public abstract class AbstractNoSqlResourceProviderRootTest {
         context.resourceResolver().delete(test);
     }
     
+    @Test
+    public void testListChildren_RootNode() throws IOException {
+        Resource testResource = 
ResourceUtil.getOrCreateResource(context.resourceResolver(), "/test",
+                ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE, 
JcrConstants.NT_UNSTRUCTURED),
+                JcrConstants.NT_UNSTRUCTURED, true);
+
+        Resource root = context.resourceResolver().getResource("/");
+
+        List<Resource> children = Lists.newArrayList(root.listChildren());
+        assertFalse(children.isEmpty());
+        assertTrue(containsResource(children, testResource));
+
+        children = Lists.newArrayList(root.getChildren());
+        assertFalse(children.isEmpty());
+        assertTrue(containsResource(children, testResource));
+
+        context.resourceResolver().delete(testResource);
+    }
+
+    private boolean containsResource(List<Resource> children, Resource 
resource) {
+        for (Resource child : children) {
+            if (StringUtils.equals(child.getPath(), resource.getPath())) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     @Test(expected = PersistenceException.class)
     public void testDeleteRootPath() throws PersistenceException {
         Resource root = context.resourceResolver().getResource("/");

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to