jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1517773 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Tue, 27 Aug 2013 09:54:46 GMT
Author: mduerig
Date: Tue Aug 27 09:54:46 2013
New Revision: 1517773

URL: http://svn.apache.org/r1517773
Log:
OAK-978: Compatibility - AssertionError thrown for invalid paths
- Remove premature optimisation
- Add regression test
- Adapted test expectation

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1517773&r1=1517772&r2=1517773&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Tue Aug 27 09:54:46 2013
@@ -162,44 +162,7 @@ public class NamePathMapperImpl implemen
             return this.idManager.getPath(jcrPath.substring(1, length - 1));
         }
 
-        boolean hasClarkBrackets = false;
-        boolean hasIndexBrackets = false;
-        boolean hasColon = false;
-        boolean hasNameStartingWithDot = false;
-        boolean hasTrailingSlash = false;
-
-        char prev = 0;
-        for (int i = 0; i < length; i++) {
-            char c = jcrPath.charAt(i);
-
-            if (c == '{' || c == '}') {
-                hasClarkBrackets = true;
-            } else if (c == '[' || c == ']') {
-                hasIndexBrackets = true;
-            } else if (c == ':') {
-                hasColon = true;
-            } else if (c == '.' && (prev == 0 || prev == '/')) {
-                hasNameStartingWithDot = true;
-            } else if(c == '/' && i == (length - 1)){
-                hasTrailingSlash = true;
-            }
-
-            prev = c;
-        }
-
-        // try a shortcut
-        if (!hasNameStartingWithDot && !hasClarkBrackets && !hasIndexBrackets)
{
-            if (!hasColon || !hasSessionLocalMappings()) {
-                if (hasTrailingSlash){
-                    return jcrPath.substring(0, length - 1);
-                } else {
-                    return jcrPath;
-                }
-            }
-        }
-
         final StringBuilder parseErrors = new StringBuilder();
-
         PathListener listener = new PathListener() {
             @Override
             public void error(String message) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1517773&r1=1517772&r2=1517773&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Tue Aug 27 09:54:46 2013
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -27,10 +31,6 @@ import org.apache.jackrabbit.oak.core.Id
 import org.junit.Ignore;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
 public class NamePathMapperImplTest {
 
     private static final Map<String, String> GLOBAL = ImmutableMap.of(
@@ -148,10 +148,10 @@ public class NamePathMapperImplTest {
         };
         NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
-        checkIdentical(npMapper, "/");
-        checkIdentical(npMapper, "/foo:bar");
-        checkIdentical(npMapper, "/foo:bar/quu:qux");
-        checkIdentical(npMapper, "foo:bar");
+        assertEquals("/", npMapper.getOakPathKeepIndex("/"));
+        assertEquals("/foo:bar", npMapper.getOakPathKeepIndex("/foo:bar"));
+        assertEquals("/foo:bar/quu:qux", npMapper.getOakPathKeepIndex("/foo:bar/quu:qux"));
+        assertEquals("foo:bar", npMapper.getOakPathKeepIndex("foo:bar"));
     }
 
     @Test
@@ -214,16 +214,4 @@ public class NamePathMapperImplTest {
         assertFalse(JcrPathParser.validate("/foo/../.."));
     }
 
-    private void checkIdentical(NamePathMapper npMapper, String jcrPath) {
-        String oakPath = npMapper.getOakPathKeepIndex(jcrPath);
-        checkIdentical(jcrPath, oakPath);
-    }
-
-    private static void checkIdentical(String expected, String actual) {
-        assertEquals(expected, actual);
-        if (expected != actual) {
-            fail("Expected the strings to be the same");
-        }
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1517773&r1=1517772&r2=1517773&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Aug 27 09:54:46 2013
@@ -274,6 +274,12 @@ public class RepositoryTest extends Abst
         root.getNode("/foo");
     }
 
+    @Test(expected = RepositoryException.class)
+    public void testExceptionThrownForInvalidPath() throws RepositoryException {
+        Session session = getAdminSession();
+        session.itemExists("//jcr:content");
+    }
+
     @Test
     public void getNodeByIdentifier() throws RepositoryException {
         Node node = getNode("/foo");



Mime
View raw message