sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1607679 - in /sling/trunk/tooling/ide: api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java api/src/org/apache/sling/ide/transport/ResourceProxy.java
Date Thu, 03 Jul 2014 15:37:57 GMT
Author: rombert
Date: Thu Jul  3 15:37:57 2014
New Revision: 1607679

URL: http://svn.apache.org/r1607679
Log:
SLING-3710 - Incorrect handling of nt:hierarchyNode instances nested
within jcr:content nodes of other nt:hieararchyNode node

Added ResourceProxy.getChild

Modified:
    sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java

Modified: sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java?rev=1607679&r1=1607678&r2=1607679&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
(original)
+++ sling/trunk/tooling/ide/api-test/src/test/java/org/apache/sling/ide/transport/ResourceProxyTest.java
Thu Jul  3 15:37:57 2014
@@ -17,6 +17,7 @@
 package org.apache.sling.ide.transport;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 import org.junit.Test;
@@ -27,9 +28,7 @@ public class ResourceProxyTest {
     public void coveredChildren_firstLevel() {
 
         ResourceProxy r = new ResourceProxy("/content");
-        ResourceProxy child = new ResourceProxy("/content/test");
-        child.addProperty("jcr:primaryType", "nt:unstructured");
-        r.addChild(child);
+        r.addChild(newResource("/content/test", "nt:unstructured"));
 
         assertThat(r.covers("/content/test"), is(true));
     }
@@ -38,13 +37,10 @@ public class ResourceProxyTest {
     public void coveredChildren_secondLevel() {
 
         ResourceProxy r = new ResourceProxy("/content");
-        ResourceProxy child = new ResourceProxy("/content/test");
-        child.addProperty("jcr:primaryType", "nt:unstructured");
+        ResourceProxy child = newResource("/content/test", "nt:unstructured");
         r.addChild(child);
 
-        ResourceProxy grandChild = new ResourceProxy("/content/test/en");
-        grandChild.addProperty("jcr:primaryType", "nt:unstructured");
-        child.addChild(grandChild);
+        child.addChild(newResource("/content/test/en", "nt:unstructured"));
 
         assertThat(r.covers("/content/test/en"), is(true));
     }
@@ -62,13 +58,34 @@ public class ResourceProxyTest {
     public void coveredChildren_notCoveredSecondLevel() {
 
         ResourceProxy r = new ResourceProxy("/content");
-        ResourceProxy child = new ResourceProxy("/content/test");
-        child.addProperty("jcr:primaryType", "nt:unstructured");
+        ResourceProxy child = newResource("/content/test", "nt:unstructured");
+        r.addChild(child);
+
+        child.addChild(new ResourceProxy("/content/test/en"));
+
+        assertThat(r.covers("/content/test/en"), is(false));
+    }
+
+    @Test
+    public void getChild() {
+
+        ResourceProxy r = new ResourceProxy("/content");
+        ResourceProxy child = newResource("/content/test", "nt:unstructured");
         r.addChild(child);
 
         ResourceProxy grandChild = new ResourceProxy("/content/test/en");
+        grandChild.addProperty("jcr:primaryType", "nt:unstructured");
         child.addChild(grandChild);
 
-        assertThat(r.covers("/content/test/en"), is(false));
+        assertThat(r.getChild("/content/test"), is(child));
+        assertThat(r.getChild("/content/test/en"), is(grandChild));
+        assertThat(r.getChild("/content/test/en2"), is(nullValue()));
+    }
+
+    private ResourceProxy newResource(String path, String primaryType) {
+
+        ResourceProxy child = new ResourceProxy(path);
+        child.addProperty("jcr:primaryType", primaryType);
+        return child;
     }
 }

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java?rev=1607679&r1=1607678&r2=1607679&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/ResourceProxy.java Thu
Jul  3 15:37:57 2014
@@ -117,6 +117,20 @@ public class ResourceProxy {
         return false;
     }
 
+    // TODO - unit test
+    public ResourceProxy getChild(String path) {
+        for (ResourceProxy child : getChildren()) {
+            if (child.getPath().equals(path)) {
+                return child;
+            } else if (path.startsWith(child.getPath())) {
+                return child.getChild(path);
+            }
+        }
+
+        return null;
+    }
+
+
     @Override
     public String toString() {
         StringBuilder out = new StringBuilder();
@@ -129,4 +143,5 @@ public class ResourceProxy {
 
         return out.toString();
     }
+
 }



Mime
View raw message