You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2011/10/14 17:48:48 UTC

svn commit: r1183393 - /sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java

Author: justin
Date: Fri Oct 14 15:48:47 2011
New Revision: 1183393

URL: http://svn.apache.org/viewvc?rev=1183393&view=rev
Log:
SLING-2244 - adding unit test for sling:vanityPath. Thanks to Antonio Sanso for the patch!

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=1183393&r1=1183392&r2=1183393&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 Fri Oct 14 15:48:47 2011
@@ -87,6 +87,8 @@ public class JcrResourceResolverTest ext
     private Node rootWs2Node;
 
     private JcrResourceListener listener;
+    
+    String vanity;
 
     protected void setUp() throws Exception {
         super.setUp();
@@ -116,6 +118,11 @@ public class JcrResourceResolverTest ext
         Node https = map.addNode("https", "sling:Mapping");
         https.addNode("localhost.443", "sling:Mapping");
 
+        // define a vanity path for the rootPath
+        vanity = "testVanity";
+        rootNode.setProperty("sling:vanityPath", vanity);
+        rootNode.addMixin("sling:VanityPath");
+        
         session.save();
 
         resFac = new JcrResourceResolverFactoryImpl();
@@ -1285,6 +1292,40 @@ public class JcrResourceResolverTest ext
         assertNotNull(res.adaptTo(Node.class));
         assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
     }
+    
+    public void testResolveVanityPath() throws Exception {
+        String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+                + "/" + vanity + ".print.html");
+
+        HttpServletRequest request = new ResourceResolverTestRequest(path);
+        Resource res = resResolver.resolve(request, path);
+        assertNotNull(res);
+        assertEquals(rootPath, res.getPath());
+        assertEquals(rootNode.getPrimaryNodeType().getName(),
+                res.getResourceType());
+
+        assertEquals(".print.html",
+                res.getResourceMetadata().getResolutionPathInfo());
+
+        assertNotNull(res.adaptTo(Node.class));
+        assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
+
+        path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath) + "/"
+                + vanity + ".print.html/suffix.pdf");
+
+        request = new ResourceResolverTestRequest(path);
+        res = resResolver.resolve(request, path);
+        assertNotNull(res);
+        assertEquals(rootPath, res.getPath());
+        assertEquals(rootNode.getPrimaryNodeType().getName(),
+                res.getResourceType());
+
+        assertEquals(".print.html/suffix.pdf",
+                res.getResourceMetadata().getResolutionPathInfo());
+
+        assertNotNull(res.adaptTo(Node.class));
+        assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
+    }
 
     public void testGetDoesNotGoUp() throws Exception {