You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/11/26 09:13:27 UTC

svn commit: r720764 - /incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java

Author: fmeschbe
Date: Wed Nov 26 00:13:27 2008
New Revision: 720764

URL: http://svn.apache.org/viewvc?rev=720764&view=rev
Log:
SLING-249 test sling:alias property on jcr:content child node
and use defined node types instead of nt:unstructured

Modified:
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java?rev=720764&r1=720763&r2=720764&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2Test.java Wed Nov 26 00:13:27 2008
@@ -66,6 +66,9 @@
                 "/SLING-INF/nodetypes/folder.cnd")));
         assertTrue(RepositoryUtil.registerNodeType(getSession(),
             this.getClass().getResourceAsStream(
+                "/SLING-INF/nodetypes/mapping.cnd")));
+        assertTrue(RepositoryUtil.registerNodeType(getSession(),
+            this.getClass().getResourceAsStream(
                 "/SLING-INF/nodetypes/resource.cnd")));
         assertTrue(RepositoryUtil.registerNodeType(getSession(),
             this.getClass().getResourceAsStream(
@@ -77,15 +80,6 @@
         repoField.setAccessible(true);
         repoField.set(resFac, getRepository());
 
-        Field mappingsField = resFac.getClass().getDeclaredField("mappings");
-        mappingsField.setAccessible(true);
-        mappingsField.set(resFac, new Mapping[] { Mapping.DIRECT });
-
-        Field patternsField = resFac.getClass().getDeclaredField("patterns");
-        patternsField.setAccessible(true);
-        patternsField.set(resFac,
-            new JcrResourceResolverFactoryImpl.ResourcePattern[0]);
-
         // ensure using JcrResourceResolver2
         Field unrrField = resFac.getClass().getDeclaredField("useNewResourceResolver");
         unrrField.setAccessible(true);
@@ -105,12 +99,12 @@
             "nt:unstructured");
 
         // test mappings
-        mapRoot = getSession().getRootNode().addNode("etc", "nt:unstructured");
-        Node map = mapRoot.addNode("map", "nt:unstructured");
-        Node https = map.addNode("https", "nt:unstructured");
-        https.addNode("localhost.443", "nt:unstructured");
-        Node http = map.addNode("http", "nt:unstructured");
-        http.addNode("localhost.80", "nt:unstructured");
+        mapRoot = getSession().getRootNode().addNode("etc", "nt:folder");
+        Node map = mapRoot.addNode("map", "sling:Mapping");
+        Node https = map.addNode("https", "sling:Mapping");
+        https.addNode("localhost.443", "sling:Mapping");
+        Node http = map.addNode("http", "sling:Mapping");
+        http.addNode("localhost.80", "sling:Mapping");
 
         session.save();
 
@@ -275,7 +269,7 @@
 
         Node localhost443 = mapRoot.getNode("map/https/localhost.443");
         Node toContent = localhost443.addNode("_playground_designground_",
-            "nt:unstructured");
+            "sling:Mapping");
         toContent.setProperty(JcrResourceResolver2.PROP_REG_EXP,
             "(playground|designground)");
         toContent.setProperty(JcrResourceResolver2.PROP_REDIRECT_INTERNAL,
@@ -301,6 +295,46 @@
         String alias = "testAlias";
         rootNode.setProperty(JcrResourceResolver2.PROP_ALIAS, alias);
         session.save();
+        
+        String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
+            + "/" + alias + ".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)
+            + "/" + alias + ".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 testResolveResourceAliasJcrContent() throws Exception {
+        // define an alias for the rootPath in the jcr:content child node
+        String alias = "testAlias";
+        Node content = rootNode.addNode("jcr:content", "nt:unstructured");
+        content.setProperty(JcrResourceResolver2.PROP_ALIAS, alias);
+        session.save();
 
         String path = ResourceUtil.normalize(ResourceUtil.getParent(rootPath)
             + "/" + alias + ".print.html");