You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by as...@apache.org on 2014/04/29 09:44:48 UTC

svn commit: r1590898 - /sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java

Author: asanso
Date: Tue Apr 29 07:44:48 2014
New Revision: 1590898

URL: http://svn.apache.org/r1590898
Log:
SLING-3505 - Improve handling of updates to mapping (alias, vanity path)

* improve code coverage for vanity path and alias

Modified:
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java

Modified: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java?rev=1590898&r1=1590897&r2=1590898&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java (original)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/serversidetests/ResourceResolverTest.java Tue Apr 29 07:44:48 2014
@@ -35,6 +35,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
@@ -138,7 +139,7 @@ public class ResourceResolverTest {
         mapRoot = session.getNode("/etc");
         
         // define a vanity path for the rootPath
-        vanity = new String[] {"testVanity","testV"};
+        vanity = new String[] {"testVanity","testV", "testVanityToUpdate"};
         rootNode.setProperty("sling:vanityPath", vanity);
         rootNode.addMixin("sling:VanityPath");
         session.save();
@@ -520,8 +521,6 @@ public class ResourceResolverTest {
         }     
     }
 
-        
-
     @Test public void testResolveResourceInternalRedirectPathUpdate() throws Exception {
         HttpServletRequest request = new FakeSlingHttpServletRequest("https", null, -1, rootPath);
         Node localhost443 = mapRoot.getNode("map/https/localhost.443");
@@ -1245,6 +1244,97 @@ public class ResourceResolverTest {
         assertNotNull(res.adaptTo(Node.class));
         assertTrue(rootNode.isSame(res.adaptTo(Node.class)));
     }
+    
+    @Test public void testResolveVanityPathWithUpdate() throws Exception {
+        try {
+
+            String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+                    + "/" + vanity[2] + ".print.html");
+
+            HttpServletRequest request = new FakeSlingHttpServletRequest(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[2] + ".print.html/suffix.pdf");
+
+            request = new FakeSlingHttpServletRequest(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)));
+            
+            //update vanityPath
+            String [] vanityPathUpdated = new String[] {"testVanity","testV", "testVanityUpdated"};
+            rootNode.setProperty("sling:vanityPath", vanityPathUpdated);
+            saveMappings(session);
+            
+            path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+                    + "/" + vanityPathUpdated[2] + ".print.html");
+
+            request = new FakeSlingHttpServletRequest(path);
+            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) + "/"
+                    + vanityPathUpdated[2] + ".print.html/suffix.pdf");
+
+            request = new FakeSlingHttpServletRequest(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)));
+            
+            
+            path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+                    + "/" + vanity[2] + ".print.html");
+
+            request = new FakeSlingHttpServletRequest(path);
+            res = resResolver.resolve(request, path);
+            assertNotNull(res);
+            assertTrue(res instanceof NonExistingResource);
+            assertEquals("/"+vanity[2]+".print.html", res.getPath());
+            
+        } finally {
+            //restore vanityPath
+            vanity = new String[] {"testVanity","testV", "testVanityToUpdate"};
+            rootNode.setProperty("sling:vanityPath", vanity);
+            saveMappings(session);
+        }
+    }
+
 
     @Test public void testGetDoesNotGoUp() throws Exception {