jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1126998 - in /jackrabbit/branches/2.2: ./ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/ jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/ jackrabbit-spi-commons/src/test...
Date Tue, 24 May 2011 12:18:16 GMT
Author: jukka
Date: Tue May 24 12:18:16 2011
New Revision: 1126998

URL: http://svn.apache.org/viewvc?rev=1126998&view=rev
Log:
2.2: Merged revision 1104027 (JCR-2953)

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java
    jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
    jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java
    jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 12:18:16 2011
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064670,1065599,1065622,1066059,1066071,1069831,1071562,1071573,1071680,1074140,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097513-1097514,1098963-1098964,1099033
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064670,1065599,1065622,1066059,1066071,1069831,1071562,1071573,1071680,1074140,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097513-1097514,1098963-1098964,1099033,1104027

Modified: jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java?rev=1126998&r1=1126997&r2=1126998&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/conversion/PathParser.java Tue May 24 12:18:16 2011
@@ -174,7 +174,7 @@ public class PathParser {
     /**
      * Parses the given <code>jcrPath</code> and returns a <code>Path</code>. If
      * <code>parent</code> is not <code>null</code>, it is prepended to the
-     * built path before it is returned. If the specifed <code>jcrPath</code>
+     * built path before it is returned. If the specified <code>jcrPath</code>
      * is an identifier based absolute path beginning with an identifier segment
      * the given <code>identifierResolver</code> will be used to resolve it to an
      * absolute path.<p/>
@@ -406,8 +406,14 @@ public class PathParser {
                         throw new MalformedPathException("'" + jcrPath + "' is not a valid path. '" + c + "' not a valid name character.");
                     }
                 case '{':
-                    if (state == STATE_PREFIX_START) {
+                    if (state == STATE_PREFIX_START && lastPos == pos-1) {
+                        // '{' marks the start of a uri enclosed in an expanded name
+                        // instead of the usual namespace prefix, if it is
+                        // located at the beginning of a new segment.
                         state = STATE_URI;
+                    } else if (state == STATE_NAME_START || state == STATE_DOT || state == STATE_DOTDOT) {
+                        // otherwise it's part of the local name
+                        state = STATE_NAME;
                     }
                     break;
 

Modified: jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java?rev=1126998&r1=1126997&r2=1126998&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/NameParserTest.java Tue May 24 12:18:16 2011
@@ -42,10 +42,9 @@ public class NameParserTest extends Test
 
 
     public void testParse() throws Exception {
-        for (int i=0; i<tests.length; i++) {
-            JcrName t = tests[i];
+        for (JcrName t : tests) {
             long t1 = System.currentTimeMillis();
-            for (int j=0; j<NUM_TESTS; j++) {
+            for (int j = 0; j < NUM_TESTS; j++) {
                 try {
                     Name n = NameParser.parse(t.jcrName, resolver, factory);
                     if (!t.isValid()) {
@@ -64,17 +63,16 @@ public class NameParserTest extends Test
                 }
             }
             long t2 = System.currentTimeMillis();
-            if (NUM_TESTS>1) {
-                System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms");
+            if (NUM_TESTS > 1) {
+                System.out.println("testCreate():\t" + t + "\t" + (t2 - t1) + "\tms");
             }
         }
     }
 
     public void testCheckFormat() throws Exception {
-        for (int i=0; i<tests.length; i++) {
-            JcrName t = tests[i];
+        for (JcrName t : tests) {
             long t1 = System.currentTimeMillis();
-            for (int j=0; j<NUM_TESTS; j++) {
+            for (int j = 0; j < NUM_TESTS; j++) {
                 // check just creation
                 boolean isValid = true;
                 try {
@@ -82,11 +80,11 @@ public class NameParserTest extends Test
                 } catch (IllegalNameException e) {
                     isValid = false;
                 }
-                assertEquals("\"" + t.jcrName + "\".checkFormat()", t.isValid(),  isValid);
+                assertEquals("\"" + t.jcrName + "\".checkFormat()", t.isValid(), isValid);
             }
             long t2 = System.currentTimeMillis();
-            if (NUM_TESTS>1) {
-                System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms");
+            if (NUM_TESTS > 1) {
+                System.out.println("testCheckFormat():\t" + t + "\t" + (t2 - t1) + "\tms");
             }
         }
     }
@@ -94,7 +92,7 @@ public class NameParserTest extends Test
     public void testExpandedJcrNames() throws NamespaceException, IllegalNameException {
         NamespaceResolver resolver = new TestNamespaceResolver();
 
-        List valid = new ArrayList();
+        List<String[]> valid = new ArrayList<String[]>();
         // valid qualified jcr-names:
         // String-array consisting of { jcrName , uri , localName }
         valid.add(new String[] {"abc:{c}", "abc", "{c}"});
@@ -116,6 +114,7 @@ public class NameParserTest extends Test
         // unknown uri -> but valid non-prefixed jcr-name
         valid.add(new String[] {"{test}abc", "", "{test}abc"});
         valid.add(new String[] {"{ab}", "", "{ab}"});
+        valid.add(new String[] {".{.}", "", ".{.}"});
 
         // valid expanded jcr-names:
         // String-array consisting of { jcrName , uri , localName }
@@ -126,8 +125,8 @@ public class NameParserTest extends Test
         valid.add(new String[] {"{abc:}def", "abc:", "def"});
         valid.add(new String[] {"{}abc", "", "abc"});
 
-        for (Iterator it = valid.iterator(); it.hasNext();) {
-            String[] strs = (String[]) it.next();
+        for (Object aValid : valid) {
+            String[] strs = (String[]) aValid;
             try {
                 Name n = NameParser.parse(strs[0], resolver, factory);
                 assertEquals("URI mismatch", strs[1], n.getNamespaceURI());
@@ -138,7 +137,7 @@ public class NameParserTest extends Test
         }
 
         // invalid jcr-names (neither expanded nor qualified form)
-        List invalid = new ArrayList();
+        List<String> invalid = new ArrayList<String>();
         // invalid prefix
         invalid.add("{a:b");
         invalid.add("}a:b");
@@ -159,8 +158,8 @@ public class NameParserTest extends Test
         invalid.add("{http://jackrabbit.apache.org}");
         invalid.add("{}");
 
-        for (Iterator it = invalid.iterator(); it.hasNext();) {
-            String jcrName = (String) it.next();
+        for (Object anInvalid : invalid) {
+            String jcrName = (String) anInvalid;
             try {
                 NameParser.parse(jcrName, resolver, factory);
                 fail("Parsing '" + jcrName + "' should fail. Not a valid jcr name.");
@@ -171,9 +170,7 @@ public class NameParserTest extends Test
     }
 
     public void testCheckFormatOfExpandedNames() throws NamespaceException, IllegalNameException {
-        NamespaceResolver resolver = new TestNamespaceResolver();
-
-        List valid = new ArrayList();
+        List<String[]> valid = new ArrayList<String[]>();
         // valid qualified jcr-names:
         // String-array consisting of { jcrName , uri , localName }
         valid.add(new String[] {"abc:{c}", "abc", "{c}"});
@@ -203,8 +200,8 @@ public class NameParserTest extends Test
         valid.add(new String[] {"{abc}def", "abc", "def"});
         valid.add(new String[] {"{}abc", "", "abc"});
 
-        for (Iterator it = valid.iterator(); it.hasNext();) {
-            String[] strs = (String[]) it.next();
+        for (Object aValid : valid) {
+            String[] strs = (String[]) aValid;
             try {
                 NameParser.checkFormat(strs[0]);
             } catch (Exception e) {
@@ -213,7 +210,7 @@ public class NameParserTest extends Test
         }
 
         // invalid jcr-names (neither expanded nor qualified form)
-        List invalid = new ArrayList();
+        List<String> invalid = new ArrayList<String>();
         // invalid prefix
         invalid.add("{a:b");
         invalid.add("}a:b");
@@ -234,8 +231,8 @@ public class NameParserTest extends Test
         invalid.add("{/jackrabbit/a/b/c}abc");
 
 
-        for (Iterator it = invalid.iterator(); it.hasNext();) {
-            String jcrName = (String) it.next();
+        for (Object anInvalid : invalid) {
+            String jcrName = (String) anInvalid;
             try {
                 NameParser.checkFormat(jcrName);
                 fail("Checking format of '" + jcrName + "' should fail. Not a valid jcr name.");
@@ -273,4 +270,4 @@ public class NameParserTest extends Test
             }
         }
     }
-}
\ No newline at end of file
+}

Modified: jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java?rev=1126998&r1=1126997&r2=1126998&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/conversion/PathParserTest.java Tue May 24 12:18:16 2011
@@ -19,15 +19,19 @@ package org.apache.jackrabbit.spi.common
 import junit.framework.TestCase;
 
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.JcrPath;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 
+import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 
 /**
@@ -49,17 +53,16 @@ public class PathParserTest extends Test
     }
 
     public void testParse() throws Exception {
-        for (int i=0; i<tests.length; i++) {
-            JcrPath t = tests[i];
+        for (JcrPath t : tests) {
             long t1 = System.currentTimeMillis();
-            for (int j=0; j<NUM_TESTS; j++) {
+            for (int j = 0; j < NUM_TESTS; j++) {
                 try {
                     Path p = PathParser.parse(t.path, resolver, factory);
-                    if (t.normalizedPath==null) {
+                    if (t.normalizedPath == null) {
                         if (!t.isValid()) {
                             fail("Should throw IllegalArgumentException: " + t.path);
                         }
-                        assertEquals("\"" + t.path + "\".create(false)", t.path,  pathResolver.getJCRPath(p));
+                        assertEquals("\"" + t.path + "\".create(false)", t.path, pathResolver.getJCRPath(p));
                         assertEquals("\"" + t.path + "\".isNormalized()", t.isNormalized(), p.isNormalized());
                         assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
                     } else {
@@ -79,18 +82,17 @@ public class PathParserTest extends Test
                 }
             }
             long t2 = System.currentTimeMillis();
-            if (NUM_TESTS>1) {
-                System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms");
+            if (NUM_TESTS > 1) {
+                System.out.println("testCreate():\t" + t + "\t" + (t2 - t1) + "\tms");
             }
         }
     }
 
     public void testCheckFormat() throws Exception {
-        for (int i=0; i<tests.length; i++) {
-            JcrPath t = tests[i];
+        for (JcrPath t : tests) {
             long t1 = System.currentTimeMillis();
-            for (int j=0; j<NUM_TESTS; j++) {
-                if (t.normalizedPath==null) {
+            for (int j = 0; j < NUM_TESTS; j++) {
+                if (t.normalizedPath == null) {
                     // check just creation
                     boolean isValid = true;
                     try {
@@ -98,18 +100,18 @@ public class PathParserTest extends Test
                     } catch (MalformedPathException e) {
                         isValid = false;
                     }
-                    assertEquals("\"" + t.path + "\".checkFormat()", t.isValid(),  isValid);
+                    assertEquals("\"" + t.path + "\".checkFormat()", t.isValid(), isValid);
                 }
             }
             long t2 = System.currentTimeMillis();
-            if (NUM_TESTS>1) {
-                System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms");
+            if (NUM_TESTS > 1) {
+                System.out.println("testCheckFormat():\t" + t + "\t" + (t2 - t1) + "\tms");
             }
         }
     }
 
     public void testNormalizedPaths() throws Exception {
-        List paths = new ArrayList();
+        List<Path> paths = new ArrayList<Path>();
         // normalized paths
         paths.add(PathParser.parse("/", resolver, factory));
         paths.add(PathParser.parse("/foo", resolver, factory));
@@ -120,8 +122,7 @@ public class PathParserTest extends Test
         paths.add(PathParser.parse("..", resolver, factory));
         paths.add(PathParser.parse(".", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertTrue("path is not normalized: " + path, path.isNormalized());
         }
 
@@ -137,14 +138,13 @@ public class PathParserTest extends Test
         paths.add(PathParser.parse("../foo/..", resolver, factory));
         paths.add(PathParser.parse("../foo/.", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertFalse("path is normalized: " + path, path.isNormalized());
         }
     }
 
     public void testAbsolutePaths() throws Exception {
-        List paths = new ArrayList();
+        List<Path> paths = new ArrayList<Path>();
 
         // absolute paths
         paths.add(PathParser.parse("/", resolver, factory));
@@ -155,8 +155,7 @@ public class PathParserTest extends Test
         paths.add(PathParser.parse("/foo/./bar", resolver, factory));
         paths.add(PathParser.parse("/foo/.././bar/./foo", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertTrue("path is not absolute: " + path, path.isAbsolute());
         }
 
@@ -173,22 +172,113 @@ public class PathParserTest extends Test
         paths.add(PathParser.parse("../foo/..", resolver, factory));
         paths.add(PathParser.parse("../foo/.", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertFalse("path is absolute: " + path, path.isAbsolute());
         }
     }
 
+    public void testExpandedPaths() throws Exception {
+        Map<String,Path> paths = new HashMap<String,Path>();
+
+        NameResolver ns = new ParsingNameResolver(NameFactoryImpl.getInstance(), new TestNamespaceResolver());
+        PathResolver ps = new ParsingPathResolver(factory, ns);
+
+        // expanded paths
+        paths.put("/",PathParser.parse("/", ns, factory));
+        paths.put("/foo",PathParser.parse("/{}foo", ns, factory));
+        paths.put("/a:foo/a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/{http://jackrabbit.apache.org}bar", ns, factory));
+        paths.put("/a:foo/../a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/../{http://jackrabbit.apache.org}bar", ns, factory));
+        paths.put("/foo/..",PathParser.parse("/{}foo/..", ns, factory));
+        paths.put("/a:foo/./a:bar",PathParser.parse("/{http://jackrabbit.apache.org}foo/./{http://jackrabbit.apache.org}bar", ns, factory));
+        paths.put("/a:foo/.././a:bar/./a:foo",PathParser.parse("/{http://jackrabbit.apache.org}foo/.././{http://jackrabbit.apache.org}bar/./{http://jackrabbit.apache.org}foo", resolver, factory));
+        paths.put("/foo/.{a}/a:b",PathParser.parse("/{}foo/{}.{a}/{http://jackrabbit.apache.org}b", ns, factory));
+        paths.put("/foo/.{.}/a:c",PathParser.parse("/{}foo/{}.{.}/{http://jackrabbit.apache.org}c", ns, factory));
+        paths.put("foo/.{.}/a:c",PathParser.parse("{}foo/{}.{.}/{http://jackrabbit.apache.org}c", ns, factory));
+
+        for (String key : paths.keySet()) {
+            Path path = paths.get(key);
+            assertEquals(key, ps.getJCRPath(path));
+        }
+    }
+
+    public void testJCRPaths() throws Exception {
+        Map<String,Path> paths = new HashMap<String,Path>();
+        paths.put("/",PathParser.parse("/", resolver, factory));
+        paths.put("/foo",PathParser.parse("/foo", resolver, factory));
+        paths.put("/a:foo/a:bar",PathParser.parse("/a:foo/a:bar", resolver, factory));
+        paths.put("/a:foo/../a:bar",PathParser.parse("/a:foo/../a:bar", resolver, factory));
+        paths.put("/a:foo/..",PathParser.parse("/a:foo/..", resolver, factory));
+        paths.put("/a:foo/./a:bar",PathParser.parse("/a:foo/./a:bar", resolver, factory));
+        paths.put("/a:foo/.././a:bar/./a:foo",PathParser.parse("/a:foo/.././a:bar/./a:foo", resolver, factory));
+        paths.put("foo/..",PathParser.parse("foo/..", resolver, factory));
+        paths.put("foo/.",PathParser.parse("foo/.", resolver, factory));
+        paths.put("foo/../bar",PathParser.parse("foo/../bar", resolver, factory));
+        paths.put("foo/./bar",PathParser.parse("foo/./bar", resolver, factory));
+        paths.put("./foo",PathParser.parse("./foo", resolver, factory));
+        paths.put(".",PathParser.parse(".", resolver, factory));
+        paths.put("foo/..",PathParser.parse("foo/..", resolver, factory));
+        paths.put("../foo/..",PathParser.parse("../foo/..", resolver, factory));
+        paths.put("../foo/.",PathParser.parse("../foo/.", resolver, factory));
+        paths.put("/foo/.{a}/a:b",PathParser.parse("/foo/.{a}/a:b", resolver, factory));
+        paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory));
+        paths.put("/a:foo/{.}/a:c",PathParser.parse("/a:foo/{.}/a:c", resolver, factory));
+        paths.put("/a:foo/{..}/a:c",PathParser.parse("/a:foo/{..}/a:c", resolver, factory));
+        paths.put("/a:foo/{...}/a:c",PathParser.parse("/a:foo/{...}/a:c", resolver, factory));
+        paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory));
+        paths.put("/a:foo/.{.}/a:c",PathParser.parse("/a:foo/.{.}/a:c", resolver, factory));
+        paths.put(".{a}",PathParser.parse(".{a}", resolver, factory));
+        paths.put(".{.}",PathParser.parse(".{.}", resolver, factory));
+        paths.put("..{.}",PathParser.parse("..{.}", resolver, factory));
+        paths.put("..{..}",PathParser.parse("..{..}", resolver, factory));
+        paths.put(".{...}",PathParser.parse(".{...}", resolver, factory));
+        paths.put("{...}",PathParser.parse("{...}", resolver, factory));
+        paths.put("...",PathParser.parse("...", resolver, factory));
+        paths.put("a:.{.}",PathParser.parse("a:.{.}", resolver, factory));
+        paths.put("..{a}",PathParser.parse("..{a}", resolver, factory));
+        paths.put(".{..}",PathParser.parse(".{..}", resolver, factory));
+        paths.put("a:..{.}",PathParser.parse("a:..{.}", resolver, factory));
+        paths.put("a:.{..}",PathParser.parse("a:.{..}", resolver, factory));
+        paths.put("a:..{..}",PathParser.parse("a:..{..}", resolver, factory));
+        paths.put(".a",PathParser.parse(".a", resolver, factory));
+        paths.put("..a",PathParser.parse("..a", resolver, factory));
+
+        for (String key : paths.keySet()) {
+            Path path = paths.get(key);
+            assertEquals(key, pathResolver.getJCRPath(path));
+        }
+    }
+
+    public void testInvalidJCRPaths() throws Exception {
+        List<String> paths = new ArrayList<String>();
+        paths.add("/a:..");
+        paths.add("/a:.");
+        paths.add("/a::");
+        paths.add("/a:{:a}");
+        paths.add("/.{:a}");
+        paths.add("/.{a:a}");
+        paths.add("/:");
+        paths.add("/*");
+        paths.add("//");
+
+        for (String jcrPath : paths) {
+            try {
+                PathParser.parse(jcrPath, resolver, factory);
+                fail(jcrPath + " isn't a valid jcr path");
+            } catch (MalformedPathException e) {
+                // ok.
+            }
+        }
+    }
+
     public void testCanonicalPaths() throws Exception {
-        List paths = new ArrayList();
+        List<Path> paths = new ArrayList<Path>();
 
         // canonical paths
         paths.add(PathParser.parse("/", resolver, factory));
         paths.add(PathParser.parse("/foo", resolver, factory));
         paths.add(PathParser.parse("/foo/bar", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertTrue("path is not canonical: " + path, path.isCanonical());
         }
 
@@ -203,18 +293,17 @@ public class PathParserTest extends Test
         paths.add(PathParser.parse(".", resolver, factory));
         paths.add(PathParser.parse("/foo/..", resolver, factory));
 
-        for (Iterator it = paths.iterator(); it.hasNext(); ) {
-            Path path = (Path) it.next();
+        for (Path path : paths) {
             assertFalse("path is canonical: " + path, path.isCanonical());
         }
     }
 
     public void testIdentifierParse() throws RepositoryException {
         DummyIdentifierResolver idResolver = new DummyIdentifierResolver();
-        List valid = idResolver.getValidIdentifiers();
-        for (Iterator it = valid.iterator(); it.hasNext();) {
-            String jcrPath = "[" + it.next() + "]";
-            try {                
+        List<String> valid = idResolver.getValidIdentifiers();
+        for (String id : valid) {
+            String jcrPath = "[" + id + "]";
+            try {
                 PathParser.parse(jcrPath, resolver, factory);
                 fail("Parsing an identifier-based jcr path needs a IdentifierResolver");
             } catch (MalformedPathException e) {
@@ -249,20 +338,46 @@ public class PathParserTest extends Test
         }
     }
 
+    public void testIdentifierParseWithTrailingString() throws RepositoryException {
+        List<String> suffix = new ArrayList<String>();
+        suffix.add("/");          // additional path delimiter
+        suffix.add("/property");  // additional path segment
+        suffix.add("suffix");     // trailing string
+        suffix.add("[1]");        // an index
+
+        DummyIdentifierResolver idResolver = new DummyIdentifierResolver();
+        List<String> valid = idResolver.getValidIdentifiers();
+        for (String id : valid) {
+            for (String s : suffix) {
+                String jcrPath = "[" + id + "]" + s;
+                try {
+                    PathParser.parse(jcrPath, resolver, idResolver, factory, true);
+                } catch (MalformedPathException e) {
+                    // success
+                }
+
+                try {
+                    PathParser.parse(jcrPath, resolver, idResolver, factory, false);
+                } catch (MalformedPathException e) {
+                    // success
+                }
+            }
+        }
+    }
+
     public void testInvalidIdentifierParse() throws RepositoryException {
         DummyIdentifierResolver idResolver = new DummyIdentifierResolver();
 
-        List invalid = idResolver.getInvalidIdentifierPaths();
-        for (Iterator it = invalid.iterator(); it.hasNext();) {
-            String jcrPath = it.next().toString();
+        List<String> invalid = idResolver.getInvalidIdentifierPaths();
+        for (String jcrPath : invalid) {
             try {
-                Path p = PathParser.parse(jcrPath, resolver, idResolver, factory, true);
+                PathParser.parse(jcrPath, resolver, idResolver, factory, true);
                 fail("Invalid identifier based path");
             } catch (MalformedPathException e) {
                 // ok
             }
             try {
-                Path p = PathParser.parse(jcrPath, resolver, idResolver, factory, false);
+                PathParser.parse(jcrPath, resolver, idResolver, factory, false);
                 fail("Invalid identifier based path");
             } catch (MalformedPathException e) {
                 // ok
@@ -272,15 +387,14 @@ public class PathParserTest extends Test
     
     public void testIdentifierCheckFormat() throws RepositoryException {
         DummyIdentifierResolver idResolver = new DummyIdentifierResolver();
-        List valid = idResolver.getValidIdentifiers();
-        for (Iterator it = valid.iterator(); it.hasNext();) {
-            String jcrPath = "[" + it.next() + "]";
+        List<String> valid = idResolver.getValidIdentifiers();
+        for (String id : valid) {
+            String jcrPath = "[" + id + "]";
             PathParser.checkFormat(jcrPath);
         }
 
-        List invalid = idResolver.getInvalidIdentifierFormats();
-        for (Iterator it = invalid.iterator(); it.hasNext();) {
-            String jcrPath = it.next().toString();
+        List<String> invalid = idResolver.getInvalidIdentifierFormats();
+        for (String jcrPath : invalid) {
             try {
                 // passing null-nameResolver -> executes check-format only
                 PathParser.checkFormat(jcrPath);
@@ -290,4 +404,34 @@ public class PathParserTest extends Test
             }
         }
     }
+
+
+    /**
+     * Dummy NamespaceResolver that only knows the empty namespace and
+     * namespaces containing either 'jackrabbit' or 'abc'. Used to test
+     * the parsing of the expanded jcr names, which should treat a jcr name with
+     * unknown namespace uri qualified jcr names.
+     */
+    private class TestNamespaceResolver implements NamespaceResolver {
+
+        public String getURI(String prefix) throws NamespaceException {
+            if (Name.NS_EMPTY_PREFIX.equals(prefix)) {
+                return Name.NS_DEFAULT_URI;
+            } else if ("a".equals(prefix)) {
+                return "http://jackrabbit.apache.org";
+            } else {
+                throw new NamespaceException("Unknown namespace prefix " + prefix);
+            }
+        }
+
+        public String getPrefix(String uri) throws NamespaceException {
+            if (Name.NS_DEFAULT_URI.equals(uri)) {
+                return Name.NS_EMPTY_PREFIX;
+            } else if ("http://jackrabbit.apache.org".equals(uri)) {
+                return "a";
+            } else {
+                throw new NamespaceException("Unknown namespace prefix " + uri);
+            }
+        }
+    }
 }

Modified: jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java?rev=1126998&r1=1126997&r2=1126998&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/PathTest.java Tue May 24 12:18:16 2011
@@ -61,11 +61,10 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestor() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
                 if (p.getNormalizedPath().denotesRoot()) {
                     continue;
                 }
@@ -78,11 +77,8 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestorOfRelativePath() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        int degree = 5;
-        for (int i = 0; i < tests.length; i++) {
-            JcrPath test = tests[i];
+        for (JcrPath test : tests) {
             if (test.isValid() && !test.isAbsolute()) {
                 Path p = resolver.getQPath(test.path);
 
@@ -97,10 +93,8 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestorAtDegreeDepth() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            JcrPath test = tests[i];
+        for (JcrPath test : tests) {
             if (test.isValid() && test.isAbsolute()) {
                 Path p = resolver.getQPath(test.path);
 
@@ -113,11 +107,10 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestorIsAncestor() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
                 while (!p.getNormalizedPath().denotesRoot()) {
                     Path ancestor = p.getAncestor(1);
                     assertTrue(ancestor.isAncestorOf(p));
@@ -128,8 +121,8 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestorOfRelativePath2() throws RepositoryException {
-        for (Iterator it = JcrPathAndAncestor.list.iterator(); it.hasNext();) {
-            JcrPathAndAncestor tp = (JcrPathAndAncestor) it.next();
+        for (Object aList : JcrPathAndAncestor.list) {
+            JcrPathAndAncestor tp = (JcrPathAndAncestor) aList;
 
             Path ancestor = resolver.getQPath(tp.ancestor).getNormalizedPath();
             Path p = resolver.getQPath(tp.path);
@@ -139,19 +132,15 @@ public class PathTest extends TestCase {
     }
 
     public void testGetAncestorReturnsNormalized() throws RepositoryException {
-        List tests = JcrPathAndAncestor.list;
-        for (Iterator it = tests.iterator(); it.hasNext();) {
-            JcrPathAndAncestor test = (JcrPathAndAncestor) it.next();
-
+        List<JcrPathAndAncestor> tests = JcrPathAndAncestor.list;
+        for (JcrPathAndAncestor test : tests) {
             Path p = resolver.getQPath(test.path);
             assertTrue(p.getAncestor(test.degree).isNormalized());
         }
     }
 
     public void testIsAncestorOfRelativePath() throws RepositoryException {
-        for (Iterator it = JcrPathAndAncestor.list.iterator(); it.hasNext();) {
-            JcrPathAndAncestor tp = (JcrPathAndAncestor) it.next();
-
+        for (JcrPathAndAncestor tp : JcrPathAndAncestor.list) {
             Path ancestor = resolver.getQPath(tp.ancestor);
             Path p = resolver.getQPath(tp.path);
 
@@ -168,11 +157,11 @@ public class PathTest extends TestCase {
     public void testAbsolutePathIsDescendantOfRoot() throws RepositoryException {
         Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path).getNormalizedPath();
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path).getNormalizedPath();
                 if (!p.equals(root)) {
-                    assertTrue(tests[i].path + " must be decendant of the root path.",p.isDescendantOf(root));
+                    assertTrue(test.path + " must be decendant of the root path.", p.isDescendantOf(root));
                 }
             }
         }
@@ -181,9 +170,9 @@ public class PathTest extends TestCase {
     public void testRootIsAncestorOfAbsolutePath() throws RepositoryException {
         Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path).getNormalizedPath();
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path).getNormalizedPath();
                 if (!p.equals(root)) {
                     assertFalse(p.isAncestorOf(root));
                 }
@@ -193,17 +182,16 @@ public class PathTest extends TestCase {
 
     public void testIsEquivalentToSelf() throws RepositoryException {
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid()) {
+                Path p = resolver.getQPath(test.path);
                 assertTrue(p.isEquivalentTo(p));
             }
         }
     }
 
     public void testIsEquivalentTo() throws IllegalArgumentException, RepositoryException {
-        for (Iterator it = Equivalent.list.iterator(); it.hasNext();) {
-            Equivalent tp = (Equivalent) it.next();
+        for (Equivalent tp : Equivalent.list) {
 
             Path path = resolver.getQPath(tp.path);
             Path other = resolver.getQPath(tp.other);
@@ -222,10 +210,10 @@ public class PathTest extends TestCase {
         Path absPath = factory.getRootPath();
         Path relPath = factory.create(NameConstants.JCR_DATA);
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid()) {
-                Path p = resolver.getQPath(tests[i].path).getNormalizedPath();
-                if (tests[i].isAbsolute()) {
+        for (JcrPath test : tests) {
+            if (test.isValid()) {
+                Path p = resolver.getQPath(test.path).getNormalizedPath();
+                if (test.isAbsolute()) {
                     if (absPath.isAncestorOf(p)) {
                         assertTrue(p.isDescendantOf(absPath));
                     } else {
@@ -265,9 +253,9 @@ public class PathTest extends TestCase {
         Path rel = factory.create(NameConstants.JCR_DATA);
 
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path).getNormalizedPath();
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path).getNormalizedPath();
                 try {
                     if (p.isAbsolute()) {
                         p.isDescendantOf(rel);
@@ -303,9 +291,9 @@ public class PathTest extends TestCase {
         Path rel = factory.create(NameConstants.JCR_DATA);
 
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path).getNormalizedPath();
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path).getNormalizedPath();
                 try {
                     if (p.isAbsolute()) {
                         p.isAncestorOf(rel);
@@ -321,55 +309,50 @@ public class PathTest extends TestCase {
     }
 
     public void testAbsolutePaths() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
-                assertTrue("Path must be absolute " + tests[i].path, p.isAbsolute());
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
+                assertTrue("Path must be absolute " + test.path, p.isAbsolute());
             }
         }
     }
 
     public void testNotAbsolutePaths() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && !tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
-                assertFalse("Path must not be absolute " + tests[i].path, p.isAbsolute());
+        for (JcrPath test : tests) {
+            if (test.isValid() && !test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
+                assertFalse("Path must not be absolute " + test.path, p.isAbsolute());
             }
         }
     }
 
     public void testCanonicalPaths() throws Exception {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);;
-                if (!tests[i].isNormalized()) {
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
+                if (!test.isNormalized()) {
                     p = p.getNormalizedPath();
                 }
-                assertTrue("Path must be canonical " + tests[i].path, p.isCanonical());
+                assertTrue("Path must be canonical " + test.path, p.isCanonical());
             }
         }
     }
 
     public void testNotCanonicalPaths() throws Exception {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && (!tests[i].isNormalized() || !tests[i].isAbsolute())) {
-                Path p = resolver.getQPath(tests[i].path);
-                assertFalse("Path must not be canonical " + tests[i].path, p.isCanonical());
+        for (JcrPath test : tests) {
+            if (test.isValid() && (!test.isNormalized() || !test.isAbsolute())) {
+                Path p = resolver.getQPath(test.path);
+                assertFalse("Path must not be canonical " + test.path, p.isCanonical());
             }
         }
     }
 
     public void testIsNotAncestor() throws RepositoryException {
-        for (Iterator it = NotAncestor.list.iterator(); it.hasNext();) {
-            NotAncestor test = (NotAncestor) it.next();
+        for (NotAncestor test : NotAncestor.list) {
             Path p = resolver.getQPath(test.path);
             Path ancestor = resolver.getQPath(test.notAncestor);
             assertFalse(test.notAncestor + " isn't an ancestor of " + test.path,
@@ -378,35 +361,33 @@ public class PathTest extends TestCase {
     }
 
     public void testDepth() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
-                String normJcrPath = (tests[i].normalizedPath == null) ? tests[i].path : tests[i].normalizedPath;
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
+                String normJcrPath = (test.normalizedPath == null) ? test.path : test.normalizedPath;
                 int depth = Text.explode(normJcrPath, '/').length;
-                assertTrue("Depth of " + tests[i].path + " must be " + depth, depth == p.getDepth());
+                assertTrue("Depth of " + test.path + " must be " + depth, depth == p.getDepth());
             }
         }
     }
 
     public void testDepthOfRelativePath() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && !tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && !test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
                 int depth = Path.ROOT_DEPTH;
                 Path.Element[] elements = p.getNormalizedPath().getElements();
-                for (int j = 0; j < elements.length; j++) {
-                    if (elements[j].denotesParent()) {
+                for (Path.Element element : elements) {
+                    if (element.denotesParent()) {
                         depth--;
-                    } else if (elements[j].denotesName()) {
+                    } else if (element.denotesName()) {
                         depth++;
                     }
                 }
                 //System.out.println("Depth of " + tests[i].path + " = " + depth);
-                assertTrue("Depth of " + tests[i].path + " must be " + depth, depth == p.getDepth());
+                assertTrue("Depth of " + test.path + " must be " + depth, depth == p.getDepth());
             }
         }
     }
@@ -430,22 +411,20 @@ public class PathTest extends TestCase {
     }
 
     public void testAncestorCount() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
                 assertTrue("Ancestor count must be same a depth", p.getDepth() == p.getAncestorCount());
             }
         }
     }
 
     public void testAncestorCountOfRelativePath() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && !tests[i].isAbsolute()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && !test.isAbsolute()) {
+                Path p = resolver.getQPath(test.path);
                 assertTrue("Ancestor count or a relative path must be -1", -1 == p.getAncestorCount());
             }
         }
@@ -469,69 +448,65 @@ public class PathTest extends TestCase {
     }
 
     public void testLength() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid()) {
-                int length = Text.explode(tests[i].path, '/').length;
-                if (tests[i].isAbsolute()) {
+        for (JcrPath test : tests) {
+            if (test.isValid()) {
+                int length = Text.explode(test.path, '/').length;
+                if (test.isAbsolute()) {
                     length++;
                 }
-                Path p = resolver.getQPath(tests[i].path);
+                Path p = resolver.getQPath(test.path);
                 //System.out.println("Length of " + tests[i].path + " = " + length);
-                assertEquals("Length of " + tests[i].path + " must reflect " +
+                assertEquals("Length of " + test.path + " must reflect " +
                         "number of elements.", new Integer(length), new Integer(p.getLength()));
             }
         }
     }
 
     public void testIsNormalized() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid()) {
-                Path p = resolver.getQPath(tests[i].path);
-                if (tests[i].isNormalized()) {
-                    assertTrue("Path " + tests[i].path + " must be normalized.", p.isNormalized());
+        for (JcrPath test : tests) {
+            if (test.isValid()) {
+                Path p = resolver.getQPath(test.path);
+                if (test.isNormalized()) {
+                    assertTrue("Path " + test.path + " must be normalized.", p.isNormalized());
                 } else {
-                    assertFalse("Path " + tests[i].path + " must not be normalized.", p.isNormalized());
+                    assertFalse("Path " + test.path + " must not be normalized.", p.isNormalized());
                 }
             }
         }
     }
 
     public void testGetNameElement() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid()) {
+                Path p = resolver.getQPath(test.path);
                 Path.Element nameEl = p.getNameElement();
                 Path.Element[] all = p.getElements();
-                assertEquals(all[all.length-1], nameEl);
+                assertEquals(all[all.length - 1], nameEl);
             }
         }
     }
 
     public void testSubPath() throws RepositoryException {
-        Path root = factory.getRootPath();
         JcrPath[] tests = JcrPath.getTests();
-        for (int i = 0; i < tests.length; i++) {
-            if (tests[i].isValid() && tests[i].isNormalized()) {
-                Path p = resolver.getQPath(tests[i].path);
+        for (JcrPath test : tests) {
+            if (test.isValid() && test.isNormalized()) {
+                Path p = resolver.getQPath(test.path);
 
                 // subpath between 0 and length -> equal path
                 assertEquals(p, p.subPath(0, p.getLength()));
 
                 // subpath a single element
                 if (p.getLength() > 2) {
-                    Path expected = factory.create(new Path.Element[] {p.getElements()[1]});
-                    assertEquals(expected, p.subPath(1,2));
+                    Path expected = factory.create(new Path.Element[]{p.getElements()[1]});
+                    assertEquals(expected, p.subPath(1, 2));
                 }
                 // subpath name element
                 if (p.getLength() > 2) {
                     Path expected = p.getLastElement();
-                    assertEquals(expected, p.subPath(p.getLength()-1, p.getLength()));
+                    assertEquals(expected, p.subPath(p.getLength() - 1, p.getLength()));
                 }
             }
         }
@@ -579,7 +554,7 @@ public class PathTest extends TestCase {
             this.degree = degree;
         }
 
-        private static List list = new ArrayList();
+        private static List<JcrPathAndAncestor> list = new ArrayList<JcrPathAndAncestor>();
         static {
             // normalized
             list.add(new JcrPathAndAncestor("abc/def", "abc", 1));
@@ -632,7 +607,7 @@ public class PathTest extends TestCase {
             this.notAncestor = notAncestor;
         }
 
-        private static List list = new ArrayList();
+        private static List<NotAncestor> list = new ArrayList<NotAncestor>();
         static {
             // false if same path
             list.add(new NotAncestor("/", "/"));
@@ -704,7 +679,7 @@ public class PathTest extends TestCase {
             this.isEquivalent = isEquivalent;
         }
 
-        private static List list = new ArrayList();
+        private static List<Equivalent> list = new ArrayList<Equivalent>();
         static {
             list.add(new Equivalent(".", "a/b", false));
             list.add(new Equivalent(".", "a/..", true));



Mime
View raw message