You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/04/05 11:03:44 UTC
svn commit: r1309704 -
/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Author: cziegeler
Date: Thu Apr 5 09:03:44 2012
New Revision: 1309704
URL: http://svn.apache.org/viewvc?rev=1309704&view=rev
Log:
Add a test case for vanity path ordering
Modified:
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=1309704&r1=1309703&r2=1309704&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java Thu Apr 5 09:03:44 2012
@@ -1304,18 +1304,18 @@ public class JcrResourceResolverTest ext
assertNotNull(res.adaptTo(Node.class));
assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
-
+
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+ "/" + alias + "/" + alias + ".print.html");
res = resResolver.resolve(request, path);
assertEquals("GET request resolution does not go up the path",
Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
-
+
Node child = rootNode.addNode("child", "nt:unstructured");
child.setProperty(JcrResourceResolver.PROP_ALIAS, alias);
session.save();
-
- res = resResolver.resolve(request, path);
+
+ res = resResolver.resolve(request, path);
assertEquals(child.getPath(), res.getPath());
}
@@ -1739,20 +1739,20 @@ public class JcrResourceResolverTest ext
mapped = resResolver.map(child.getPath() + selExt);
assertEquals(path, mapped);
}
-
+
public void testMapResourceAlias() throws Exception {
// define an alias for the rootPath
String alias = "testAlias";
rootNode.setProperty(JcrResourceResolver.PROP_ALIAS, alias);
session.save();
-
+
String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
- + "/" + alias);
+ + "/" + alias);
String mapped = resResolver.map(rootNode.getPath());
assertEquals(path, mapped);
Node child = rootNode.addNode("child");
session.save();
-
+
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+ "/" + alias+"/child");
mapped = resResolver.map(child.getPath());
@@ -1765,26 +1765,26 @@ public class JcrResourceResolverTest ext
Node content = rootNode.addNode("jcr:content", "nt:unstructured");
content.setProperty(JcrResourceResolver.PROP_ALIAS, alias);
session.save();
-
+
String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
- + "/" + alias);
+ + "/" + alias);
String mapped = resResolver.map(rootNode.getPath());
assertEquals(path, mapped);
-
+
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
- + "/" + alias+"/_jcr_content");
+ + "/" + alias+"/_jcr_content");
mapped = resResolver.map(content.getPath());
assertEquals(path, mapped);
-
+
Node child = content.addNode("child");
session.save();
-
+
path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+ "/" + alias+"/_jcr_content/child");
mapped = resResolver.map(child.getPath());
assertEquals(path, mapped);
}
-
+
public void test_resolve() throws Exception {
Node child = rootNode.addNode("child");
@@ -1938,6 +1938,88 @@ public class JcrResourceResolverTest ext
assertEquals(child.getPath(), resNode.getPath());
}
+ /**
+ * Test the order property of the vanity paths
+ */
+ public void test_resolve_with_sling_vanity_path_order() throws Exception {
+ final String vanityPath = "/ordering";
+
+ // create two nodes - child2 with a higher order
+ Node child1 = rootNode.addNode("child1");
+ child1.addMixin("sling:VanityPath");
+ child1.setProperty("sling:vanityPath", vanityPath);
+ child1.setProperty("sling:vanityOrder", 100);
+ Node child2 = rootNode.addNode("child2");
+ child2.addMixin("sling:VanityPath");
+ child2.setProperty("sling:vanityPath", vanityPath);
+ child2.setProperty("sling:vanityOrder", 200);
+ session.save();
+
+ // we should wait a little bit for the observation to be processed
+ try { Thread.sleep(2000); } catch (final InterruptedException ignore) {}
+
+ // we should get child2 now
+ Resource rsrc = resResolver.resolve(vanityPath);
+ assertNotNull(rsrc);
+ assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
+ assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
+
+ // remove 2
+ child2.remove();
+ session.save();
+
+ // we should wait a little bit for the observation to be processed
+ try { Thread.sleep(2000); } catch (final InterruptedException ignore) {}
+
+ // we should get child 1 now
+ rsrc = resResolver.resolve(vanityPath);
+ assertNotNull(rsrc);
+ assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
+ assertEquals("Path does not match", child1.getPath(), rsrc.getPath());
+
+ // readding child2
+ child2 = rootNode.addNode("child2");
+ child2.addMixin("sling:VanityPath");
+ child2.setProperty("sling:vanityPath", vanityPath);
+ child2.setProperty("sling:vanityOrder", 200);
+ session.save();
+
+ // we should wait a little bit for the observation to be processed
+ try { Thread.sleep(2000); } catch (final InterruptedException ignore) {}
+
+ // we should get child2 now
+ rsrc = resResolver.resolve(vanityPath);
+ assertNotNull(rsrc);
+ assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
+ assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
+
+ // change order of child 1 to make it higher than child 2
+ child1.setProperty("sling:vanityOrder", 300);
+ session.save();
+
+ // we should wait a little bit for the observation to be processed
+ try { Thread.sleep(2000); } catch (final InterruptedException ignore) {}
+
+ // we should get child 1 now
+ rsrc = resResolver.resolve(vanityPath);
+ assertNotNull(rsrc);
+ assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
+ assertEquals("Path does not match", child1.getPath(), rsrc.getPath());
+
+ // change order of child 1 to make it lower than child 2
+ child1.setProperty("sling:vanityOrder", 50);
+ session.save();
+
+ // we should wait a little bit for the observation to be processed
+ try { Thread.sleep(2000); } catch (final InterruptedException ignore) {}
+
+ // we should get child 2 now
+ rsrc = resResolver.resolve(vanityPath);
+ assertNotNull(rsrc);
+ assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
+ assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
+ }
+
public void test_resolve_with_sling_alias() throws Exception {
Node child = rootNode.addNode("child");