jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1582779 - in /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr: NamePathTest.java RepositoryTest.java
Date Fri, 28 Mar 2014 15:43:09 GMT
Author: angela
Date: Fri Mar 28 15:43:09 2014
New Revision: 1582779

URL: http://svn.apache.org/r1582779
Log:
OAK-1174 : Inconsistent handling of invalid names/paths

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java?rev=1582779&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java
Fri Mar 28 15:43:09 2014
@@ -0,0 +1,252 @@
+/*
+ * 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.jackrabbit.oak.jcr;
+
+import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class NamePathTest extends AbstractRepositoryTest {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(NamePathTest.class);
+
+    public NamePathTest(NodeStoreFixture fixture) {
+        super(fixture);
+    }
+
+    @Test
+    public void testSlashInPath() throws RepositoryException {
+        List<String> paths = ImmutableList.of(
+                "//jcr:content",
+                "//content"
+        );
+        testPaths(paths, getAdminSession());
+    }
+
+    @Test
+    public void testSlashInName() throws RepositoryException {
+        List<String> names = ImmutableList.of(
+                "/jcr:content",
+                "/content",
+                "jcr:con/ent",
+                "jc/r:content",
+                "con/ent"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Test
+    public void testColonInPath() throws RepositoryException {
+        List<String> paths = ImmutableList.of(
+                "/jcr:con:ent"
+        );
+        testPaths(paths, getAdminSession());
+    }
+
+    @Test
+    public void testColonInName() throws RepositoryException {
+        List<String> names = ImmutableList.of(
+                "jcr:con:ent"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Test
+    public void testSquareBracketsInPath() throws RepositoryException {
+        List<String> paths = ImmutableList.of(
+                "//jcr:content",
+                "/jcr:con]ent",
+                "/con]ent"
+        );
+        testPaths(paths, getAdminSession());
+    }
+
+    @Test
+    public void testSquareBracketsInName() throws RepositoryException {
+        List<String> names = ImmutableList.of(
+                "jcr:content[1]",
+                "content[1]",
+                "jcr:conten[t]",
+                "conten[t]",
+
+                "jcr:con[]ent",
+                "jcr[]:content",
+                "con[]ent",
+                "jcr:con[t]ent",
+                "jc[t]r:content",
+                "con[t]ent",
+
+                "jcr:con]ent",
+                "jc]r:content",
+                "con]ent",
+
+                "jcr:con[ent",
+                "jc[r:content",
+                "con[ent"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Test
+    public void testAsteriskInPath() throws RepositoryException {
+        List<String> paths = ImmutableList.of(
+                "/jcr:con*ent",
+                "/jcr:*ontent",
+                "/jcr:conten*",
+                "/con*ent",
+                "/*ontent",
+                "/conten*"
+        );
+        testPaths(paths, getAdminSession());
+    }
+
+    @Ignore("OAK-1174") // FIXME OAK-1174
+    @Test
+    public void testAskeriskInName() throws RepositoryException {
+        List<String> names = ImmutableList.of(
+                "jcr:con*ent",
+                "jcr:*ontent",
+                "jcr:conten*",
+                "con*ent",
+                "*ontent", // TODO fails
+                "conten*"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Test
+    public void testVerticalLineInPath() throws Exception {
+        List<String> paths = ImmutableList.of(
+                "/jcr:con|ent",
+                "/jcr:|ontent",
+                "/jcr:conten|",
+                "/|ontent",
+                "/conten|",
+                "/con|ent"
+                );
+        testPaths(paths, getAdminSession());
+    }
+
+    @Ignore("OAK-1174") // FIXME OAK-1174
+    @Test
+    public void testVerticalLineInName() throws Exception {
+        List<String> names = ImmutableList.of(
+                "jcr:con|ent",
+                "jcr:|ontent",
+                "jcr:conten|",
+                "con|ent",
+                "|ontent", //TODO fails
+                "conten|"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Ignore("OAK-1174") // FIXME OAK-1174
+    @Test
+    public void testWhitespaceInPath() throws Exception {
+        List<String> paths = ImmutableList.of(
+                "/content ",
+                "/ content",
+                "/content\t",
+                "/\tcontent",
+                "/jcr:con\tent",
+                "con\tent"
+        );
+
+        testPaths(paths, getAdminSession());
+    }
+
+    @Ignore("OAK-1174") // FIXME OAK-1174
+    @Test
+    public void testWhitespaceInName() throws Exception {
+        List<String> names = ImmutableList.of(
+                "jcr:content ",
+                "content ",
+                " content",
+                "jcr:content\t",
+                "content\t",
+                "\tcontent",
+                "con\tent"
+        );
+        testNames(names, getAdminSession());
+    }
+
+    @Test
+    public void testSpaceInNames() throws RepositoryException {
+        Session session = getAdminSession();
+        Node n = session.getRootNode().addNode("c o n t e n t");
+        Node n2 = session.getNode(n.getPath());
+    }
+
+
+    private static void testPaths(List<String> paths, Session session) throws RepositoryException
{
+        RepositoryException exception = null;
+        for (String path : paths) {
+            try {
+                session.itemExists(path);
+            } catch (RepositoryException e) {
+                exception = e;
+            }
+        }
+
+        session.setNamespacePrefix("foo", "http://foo.bar");
+        for (String path : paths) {
+            try {
+                session.itemExists(path);
+                assertNull("path = " + path, exception);
+            } catch (RepositoryException e) {
+                assertNotNull("path = " + path, exception);
+            }
+        }
+    }
+
+    private static void testNames(List<String> names, Session session) throws RepositoryException
{
+        RepositoryException exception = null;
+        for (String name : names) {
+            try {
+                session.getRootNode().addNode(name);
+            } catch (RepositoryException e) {
+                exception = e;
+            } finally {
+                session.refresh(false);
+            }
+        }
+
+        session.setNamespacePrefix("foo", "http://foo.bar");
+        for (String name : names) {
+            try {
+                session.getRootNode().addNode(name);
+                assertNull("name = " + name, exception);
+            } catch (RepositoryException e) {
+                assertNotNull("name = " + name, exception);
+            }
+        }
+    }
+}
\ No newline at end of file

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=1582779&r1=1582778&r2=1582779&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
Fri Mar 28 15:43:09 2014
@@ -28,7 +28,6 @@ import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 import javax.jcr.Binary;
 import javax.jcr.GuestCredentials;
@@ -56,7 +55,6 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeTemplate;
 
-import com.google.common.collect.ImmutableList;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.JackrabbitNode;
 import org.apache.jackrabbit.api.JackrabbitRepository;
@@ -350,100 +348,6 @@ public class RepositoryTest extends Abst
     }
 
     @Test
-    public void testInvalidPath() throws RepositoryException {
-        Session session = getAdminSession();
-
-        List<String> invalid = ImmutableList.of(
-                "//jcr:content",
-                "/jcr:con]ent",
-                "/con]ent",
-                "/jcr:con*ent",
-                "/con*ent",
-                "/jcr:con|ent",
-                "/con|ent");
-        for (String path : invalid) {
-            try {
-                session.itemExists(path);
-                fail("Invalid path " + path);
-            } catch (RepositoryException e) {
-                // success
-            }
-        }
-
-        session.setNamespacePrefix("foo", "http://foo.bar");
-        for (String path : invalid) {
-            try {
-                session.itemExists(path);
-                fail("Invalid path " + path);
-            } catch (RepositoryException e) {
-                // success
-            }
-        }
-    }
-
-    @Test
-    public void testInvalidName() throws RepositoryException {
-        List<String> invalid = ImmutableList.of(
-                "/jcr:content",
-                "/content",
-                "jcr:con/ent",
-                "jc/r:content",
-                "con/ent",
-
-                "jcr:con:ent",
-
-                "jcr:content[1]",
-                "content[1]",
-                "jcr:conten[t]",
-                "conten[t]",
-
-                "jcr:con[]ent",
-                "jcr[]:content",
-                "con[]ent",
-                "jcr:con[t]ent",
-                "jc[t]r:content",
-                "con[t]ent",
-
-                "jcr:con]ent",
-                "jc]r:content",
-                "con]ent",
-
-                "jcr:con[ent",
-                "jc[r:content",
-                "con[ent",
-
-                "jcr:con*ent",
-                "jc*r:content",
-                "con*ent",
-
-                "jcr:con|ent",
-                "jc|r:content",
-                "con|ent");
-
-        Session session = getAdminSession();
-        for (String name : invalid) {
-            try {
-                session.getRootNode().addNode(name);
-                fail("Invalid name " + name);
-            } catch (RepositoryException e) {
-                // success
-            } finally {
-                session.refresh(false);
-            }
-        }
-
-        session.setNamespacePrefix("foo", "http://foo.bar");
-        for (String name : invalid) {
-            try {
-                session.getRootNode().addNode(name);
-                fail("Invalid name " + name);
-            } catch (RepositoryException e) {
-                // success
-            }
-        }
-    }
-
-    @Test
     public void getNodeByIdentifier() throws RepositoryException {
         Node node = getNode("/foo");
         String id = node.getIdentifier();
@@ -2119,7 +2023,7 @@ public class RepositoryTest extends Abst
     @Test
     public void testReferenceBinary() throws RepositoryException {
         ValueFactory valueFactory = getAdminSession().getValueFactory();
-        Binary binary = valueFactory.createBinary(new RandomInputStream(1, 256*1024));
+        Binary binary = valueFactory.createBinary(new RandomInputStream(1, 256 * 1024));
 
         String reference = binary instanceof ReferenceBinary
             ? ((ReferenceBinary) binary).getReference()



Mime
View raw message