incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r586541 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/api/ main/java/org/apache/sling/microsling/request/ main/java/org/apache/sling/microsling/request/helpers/ main/java/org/apache/sling/microsling/...
Date Fri, 19 Oct 2007 17:11:28 GMT
Author: bdelacretaz
Date: Fri Oct 19 10:11:25 2007
New Revision: 586541

URL: http://svn.apache.org/viewvc?rev=586541&view=rev
Log:
SLING-60 : SlingRequestPathInfoParser takes ResourceResolver info into account

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
  (with props)
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
Fri Oct 19 10:11:25 2007
@@ -116,9 +116,12 @@
      */
     String getSuffix();
     
+    /** The path that was used to resolve (=load) the Resource that we are processing */
+    String getResourcePath();
+    
     /** 
-     * Return the "content path" part of the URL, what comes before selectors, extension

-     * and suffix
+     * Return the unused "content path" part of the URL, what comes after the path of the

+     * resolved Resource, but before selectors, extension and suffix
      */
-    String getContentPath();
+    String getUnusedContentPath();
 }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/MicroslingRequestContext.java
Fri Oct 19 10:11:25 2007
@@ -44,7 +44,7 @@
     private final ServletContext servletContext;
     private final Repository repository;
     private Resource resource;
-    private final SlingRequestPathInfoParser requestPathInfo;
+    private SlingRequestPathInfoParser requestPathInfo;
     private final HttpServletRequest request;
     private final ServiceLocator serviceLocator;
     private RequestParameterMap parameterMap;
@@ -70,9 +70,6 @@
             throw new SlingException("Repository not available in ServletContext attribute
" + repoAttr);
         }
 
-        // Parse request URI
-        requestPathInfo = new SlingRequestPathInfoParser(request.getPathInfo());
-
         // load the request parameter map
         // this can be done lazily when we keep the request here
         parameterMap = new SlingRequestParameterMap(request);
@@ -90,7 +87,6 @@
         if(resource==null) {
             final ResourceResolver rr = (ResourceResolver)serviceLocator.getRequiredService(ResourceResolver.class.getName());
             resource = rr.getResource(request);
-            // TODO initialize SlingRequestPathInfo from resource here
         }
         return resource;
     }
@@ -109,6 +105,16 @@
     }
 
     public SlingRequestPathInfo getRequestPathInfo() {
+        if(requestPathInfo == null) {
+            // make sure Resource is resolved, as we need it to compute the path info
+            try {
+                getResource();
+            } catch(Exception e) {
+                // TODO bitten by my own "throws Exception" stuff here ;-)
+                // To fix this, using more specific Exceptions should help
+            }
+            requestPathInfo = new SlingRequestPathInfoParser(resource,request.getPathInfo());
+        }
         return requestPathInfo;
     }
 

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
Fri Oct 19 10:11:25 2007
@@ -20,18 +20,30 @@
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
+import org.apache.sling.microsling.api.Resource;
 import org.apache.sling.microsling.api.SlingRequestPathInfo;
 
 /** microsling request URI parser that provides SlingRequestPathInfo 
- *  for the current request.
+ *  for the current request, based on the path of the Resource.
+ *  
+ *  The values provided by this depend on the Resource.getURI() value,
+ *  as the ResourceResolver might use all or only part of the request 
+ *  URI path to locate the resource (see also SLING-60 ).
+ *  
+ *  What we're after is the remainder of the path, the part that was
+ *  not used to locate the Resource, and we split that part in different
+ *  subparts: selectors, extension and suffix.
+ *  
+ *  @see SlingRequestPathInfoParserTest for a number of examples.
  */
 public class SlingRequestPathInfoParser implements SlingRequestPathInfo {
     
-    private final String contentPath;
+    private final String unusedContentPath;
     private final String selectorString;
     private final String [] selectors;
     private final String extension;
     private final String suffix;
+    private final String resourcePath;
     
     private final static String EMPTY = "";
     
@@ -55,17 +67,22 @@
     }
     
     /** break requestPath as required by SlingRequestPathInfo */
-    public SlingRequestPathInfoParser(String requestPath) throws PatternSyntaxException {
+    public SlingRequestPathInfoParser(Resource r,String requestPath) throws PatternSyntaxException
{
         if(parsingPatternException != null) {
             throw parsingPatternException;
         }
         
-        if(requestPath == null) {
-            requestPath = "";
+        String pathToParse = requestPath;
+        if(pathToParse == null) {
+            pathToParse = "";
+        }
+        resourcePath = r.getURI();
+        if(pathToParse.length() >= resourcePath.length()) {
+            pathToParse = pathToParse.substring(resourcePath.length());
         }
         
-        Matcher m = splitInThreePattern.matcher(requestPath);
-        contentPath = groupOrEmpty(m,1);
+        Matcher m = splitInThreePattern.matcher(pathToParse);
+        unusedContentPath = groupOrEmpty(m,1);
         suffix = groupOrEmpty(m,4);
         
         final String selAndExt = groupOrEmpty(m,3);
@@ -88,7 +105,7 @@
     public String toString() {
         return 
           "SlingRequestPathInfoParser:"
-          + ", path='" + contentPath + "'"
+          + ", path='" + unusedContentPath + "'"
           + ", selectorString='" + selectorString + "'"
           + ", extension='" + extension + "'"
           + ", suffix='" + suffix + "'"
@@ -118,7 +135,11 @@
         return suffix;
     }
     
-    public String getContentPath() {
-        return contentPath;
+    public String getUnusedContentPath() {
+        return unusedContentPath;
+    }
+
+    public String getResourcePath() {
+        return resourcePath;
     }
 }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
Fri Oct 19 10:11:25 2007
@@ -21,18 +21,33 @@
 import org.apache.sling.microsling.api.Resource;
 import org.apache.sling.microsling.api.ResourceResolver;
 import org.apache.sling.microsling.api.SlingRequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-/** A RequestFilter that selects the Resource to process */
+/** The microsling ResourceResolver locates a Resource using a ResourcePathIterator:
+ *  it first tries to find an exact match for the Request URI, and if not goes up
+ *  the path, breaking it a "." and "/", stopping if it finds a Resource. 
+ */
 public class MicroslingResourceResolver implements ResourceResolver {
 
+    private static final Logger log = LoggerFactory.getLogger(MicroslingResourceResolver.class);
   
+            
     public Resource getResource(HttpServletRequest request) throws Exception {
         final SlingRequestContext ctx = SlingRequestContext.Accessor.getSlingRequestContext(request);
         Resource result = null;
         
-        // TODO support OCM-mapped objects as well
-        final String contentPath = ctx.getRequestPathInfo().getContentPath();
-        if (ctx.getSession().itemExists(contentPath)) {
-            result = new JcrNodeResource(ctx.getSession(),contentPath);
+        final ResourcePathIterator it = new ResourcePathIterator(request.getPathInfo());
+        while(it.hasNext() && result == null) {
+            final String path = it.next();
+            if(log.isDebugEnabled()) {
+                log.debug("Trying to locate Resource at path '" + path + "'");
+            }
+            if (ctx.getSession().itemExists(path)) {
+                result = new JcrNodeResource(ctx.getSession(),path);
+                if(log.isInfoEnabled()) {
+                    log.info("Found Resource at path '" + path + "'");
+                }
+            }
         }
         
         return result;

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java?rev=586541&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
Fri Oct 19 10:11:25 2007
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.resource;
+
+import java.util.Iterator;
+
+/** Iterate over the the HTTP request path by creating shorter segments
+ *  of that path using "." and "/" as separators.
+ *  
+ *  For example, if path = /some/stuff.a4.html/xyz the sequence is:
+ *  <ol>
+ *    <li>
+ *      /some/stuff.a4.html/xyz
+ *    </li>
+ *    <li>
+ *      /some/stuff.a4.html
+ *    </li>
+ *    <li>
+ *      /some/stuff.a4
+ *    </li>
+ *    <li>
+ *      /some/stuff
+ *    </li>
+ *    <li>
+ *      /some
+ *    </li>
+ *  </ol>
+ */
+class ResourcePathIterator implements Iterator<String> {
+
+    private String nextPath;
+    
+    ResourcePathIterator(String path) {
+        nextPath = path;
+    }
+    
+    public boolean hasNext() {
+        return nextPath != null && nextPath.length() > 0;
+    }
+
+    public String next() {
+        final String result = nextPath;
+        final int pos = Math.max(result.lastIndexOf('.'),result.lastIndexOf('/'));
+        if(pos < 0) {
+            nextPath = null;
+        } else {
+            nextPath = result.substring(0,pos);
+        }
+        return result;
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException("Cannot remove() on ResourcePathIterator");
+    }
+
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Fri Oct 19 10:11:25 2007
@@ -87,7 +87,7 @@
         final SlingRequestContext ctx = SlingRequestContext.Accessor.getSlingRequestContext(req);
 
         // Create or update node under current path
-        final String nodePath = ctx.getRequestPathInfo().getContentPath();
+        final String nodePath = ctx.getRequestPathInfo().getResourcePath();
 
         Session s = null;
         try {

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java?rev=586541&r1=586540&r2=586541&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
Fri Oct 19 10:11:25 2007
@@ -16,83 +16,156 @@
  */
 package org.apache.sling.microsling.request.helpers;
 
+import javax.jcr.Item;
+
 import junit.framework.TestCase;
 
+import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.SlingRequestPathInfo;
+
 /** Test the SlingRequestPathInfoParser */
 public class SlingRequestPathInfoParserTest extends TestCase {
 
+    static class MockResource implements Resource {
+        
+        private final String uri;
+        
+        MockResource(String uri) {
+            this.uri = uri;
+        }
+
+        public Object getData() {
+            throw new Error("MockResource does not implement this method");
+        }
+
+        public Item getItem() {
+            throw new Error("MockResource does not implement this method");
+        }
+
+        public String getResourceType() {
+            throw new Error("MockResource does not implement this method");
+        }
+
+        public String getURI() {
+            return uri;
+        }
+        
+    }
+    
     public void testSimplePath() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
-        assertEquals("/some/path",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/path",p.getUnusedContentPath());
+        assertEquals("",p.getResourcePath());
     }
     
     public void testSimpleSuffix() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
         assertEquals("/some/suffix",p.getSuffix());
     }
     
     public void testSimpleSelectorString() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
         assertEquals("print.a4",p.getSelectorString());
     }
     
     public void testSimpleExtension() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
         assertEquals("html",p.getExtension());
     }
     
     public void testAllOptions() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
-        assertEquals("/some/path",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/path",p.getUnusedContentPath());
         assertEquals("print.a4",p.getSelectorString());
         assertEquals("html",p.getExtension());
         assertEquals("/some/suffix",p.getSuffix());
     }
     
     public void testAllEmpty() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser(null);
-        assertEquals("",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),null);
+        assertEquals("",p.getUnusedContentPath());
         assertEquals("",p.getSelectorString());
         assertEquals("",p.getExtension());
         assertEquals("",p.getSuffix());
     }
     
     public void testPathOnly() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here");
-        assertEquals("/some/path/here",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path/here");
+        assertEquals("/some/path/here",p.getUnusedContentPath());
         assertEquals("",p.getSelectorString());
         assertEquals("",p.getExtension());
         assertEquals("",p.getSuffix());
     }
     
     public void testPathAndExtensionOnly() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.html");
-        assertEquals("/some/path/here",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path/here.html");
+        assertEquals("/some/path/here",p.getUnusedContentPath());
         assertEquals("",p.getSelectorString());
         assertEquals("html",p.getExtension());
         assertEquals("",p.getSuffix());
     }
     
     public void testPathAndOneSelectorOnly() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.print.html");
-        assertEquals("/some/path/here",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path/here.print.html");
+        assertEquals("/some/path/here",p.getUnusedContentPath());
         assertEquals("print",p.getSelectorString());
         assertEquals("html",p.getExtension());
         assertEquals("",p.getSuffix());
     }
     
     public void testPathExtAndSuffix() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.html/something");
-        assertEquals("/some/path/here",p.getContentPath());
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path/here.html/something");
+        assertEquals("/some/path/here",p.getUnusedContentPath());
         assertEquals("",p.getSelectorString());
         assertEquals("html",p.getExtension());
         assertEquals("/something",p.getSuffix());
     }
     
     public void testSelectorsSplit() {
-        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource(""),"/some/path.print.a4.html/some/suffix");
         assertEquals(2,p.getSelectors().length);
         assertEquals("print",p.getSelector(0));
         assertEquals("a4",p.getSelector(1));
+    }
+    
+    public void testPartialResolutionA() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource("/some"),"/some/path.print.a4.html/some/suffix");
+        assertEquals("/some",p.getResourcePath());
+        assertEquals("print.a4",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/some/suffix",p.getSuffix());
+        assertEquals("/path",p.getUnusedContentPath());
+    }
+    
+    public void testPartialResolutionB() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource("/some/path"),"/some/path.print.a4.html/some/suffix");
+        assertEquals("print.a4",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/some/suffix",p.getSuffix());
+        assertEquals("",p.getUnusedContentPath());
+    }
+    
+    public void testPartialResolutionC() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource("/some/path.print"),"/some/path.print.a4.html/some/suffix");
+        assertEquals("a4",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/some/suffix",p.getSuffix());
+        assertEquals("",p.getUnusedContentPath());
+    }
+    
+    public void testPartialResolutionD() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource("/some/path.print.a"),"/some/path.print.a4.html/some/suffix");
+        assertEquals("",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/some/suffix",p.getSuffix());
+        assertEquals("4",p.getUnusedContentPath());
+    }
+    
+    public void testPartialResolutionE() {
+        SlingRequestPathInfo p = new SlingRequestPathInfoParser(new MockResource("/some/path.print.a4.html"),"/some/path.print.a4.html/some/suffix");
+        assertEquals("",p.getSelectorString());
+        assertEquals("",p.getExtension());
+        assertEquals("",p.getSuffix());
+        assertEquals("/some/suffix",p.getUnusedContentPath());
     }
 }

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java?rev=586541&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
Fri Oct 19 10:11:25 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.resource;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+/** Test the ResourcePathIterator class */
+
+public class ResourcePathIteratorTest extends TestCase {
+    
+    public void testNullInput() {
+        final Iterator<String> it = new ResourcePathIterator(null);
+        assertFalse(it.hasNext());
+    }
+    
+    public void testEmptyInput() {
+        final Iterator<String> it = new ResourcePathIterator("");
+        assertFalse(it.hasNext());
+    }
+    
+    public void testNoSeparators() {
+        final Iterator<String> it = new ResourcePathIterator("MickeyMouseWasHere");
+        assertTrue(it.hasNext());
+        assertEquals("MickeyMouseWasHere",it.next());
+        assertFalse(it.hasNext());
+    }
+    
+    public void testSlashOnly() {
+        final Iterator<String> it = new ResourcePathIterator("/MickeyMouseWasHere/ok");
+        assertTrue(it.hasNext());
+        assertEquals("/MickeyMouseWasHere/ok",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/MickeyMouseWasHere",it.next());
+        assertFalse(it.hasNext());
+    }
+    
+    public void testDotOnly() {
+        final Iterator<String> it = new ResourcePathIterator("MickeyMouseWasHere.ok");
+        assertTrue(it.hasNext());
+        assertEquals("MickeyMouseWasHere.ok",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("MickeyMouseWasHere",it.next());
+        assertFalse(it.hasNext());
+    }
+    
+    public void testRealisticPath() {
+        final Iterator<String> it = new ResourcePathIterator("/some/stuff.print.a4/more");
+        assertTrue(it.hasNext());
+        assertEquals("/some/stuff.print.a4/more",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/some/stuff.print.a4",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/some/stuff.print",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/some/stuff",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("/some",it.next());
+        assertFalse(it.hasNext());
+    }
+    
+    public void testRelativePath() {
+        final Iterator<String> it = new ResourcePathIterator("some/stuff.print");
+        assertTrue(it.hasNext());
+        assertEquals("some/stuff.print",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("some/stuff",it.next());
+        assertTrue(it.hasNext());
+        assertEquals("some",it.next());
+        assertFalse(it.hasNext());
+    }
+}

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message