You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by tr...@apache.org on 2014/08/14 14:32:34 UTC

svn commit: r1617920 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/

Author: tripod
Date: Thu Aug 14 12:32:34 2014
New Revision: 1617920

URL: http://svn.apache.org/r1617920
Log:
OAK-2033 Setting a path property with a value that contains a unregistered namespace does not fail

- moving tests
- adding check for path values

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NameAndPathPropertyTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/MiscTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java?rev=1617920&r1=1617919&r2=1617920&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java Thu Aug 14 12:32:34 2014
@@ -20,13 +20,12 @@ import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.commit.DefaultValidator;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.api.Type.NAMES;
-
 /**
  * TODO document
  */
@@ -72,10 +71,16 @@ class NameValidator extends DefaultValid
 
     protected void checkValidValue(PropertyState property)
             throws CommitFailedException {
-        if (NAME.equals(property.getType()) || NAMES.equals(property.getType())) {
-            for (String value : property.getValue(NAMES)) {
+        if (Type.NAME.equals(property.getType()) || Type.NAMES.equals(property.getType())) {
+            for (String value : property.getValue(Type.NAMES)) {
                 checkValidValue(value);
             }
+        } else if (Type.PATH.equals(property.getType()) || Type.PATHS.equals(property.getType())) {
+            for (String value : property.getValue(Type.PATHS)) {
+                for (String name: PathUtils.elements(value)) {
+                    checkValidValue(name);
+                };
+            }
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/MiscTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/MiscTest.java?rev=1617920&r1=1617919&r2=1617920&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/MiscTest.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/MiscTest.java Thu Aug 14 12:32:34 2014
@@ -20,7 +20,6 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
@@ -28,8 +27,6 @@ import org.apache.jackrabbit.commons.jac
 import org.junit.Ignore;
 import org.junit.Test;
 
-import static org.junit.Assert.fail;
-
 public class MiscTest extends AbstractRepositoryTest {
 
     public MiscTest(NodeStoreFixture fixture) {
@@ -46,20 +43,6 @@ public class MiscTest extends AbstractRe
         traverse(index);
     }
 
-    @Test
-    public void testMVNameProperty() throws Exception {
-        Session session = getAdminSession();
-        Node testRootNode = session.getRootNode().addNode("testRoot");
-        try {
-            testRootNode.setProperty("testNameProperty", new String[]{"foobar:test"}, PropertyType.NAME);
-            session.save();
-            fail("adding a MV name property without registered namespace must fail.");
-        } catch (RepositoryException e) {
-            // ok.
-        }
-    }
-
-
     private void traverse(Node node) throws RepositoryException {
         System.out.println(node.getPath());
         PropertyIterator iter = node.getProperties();

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NameAndPathPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NameAndPathPropertyTest.java?rev=1617920&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NameAndPathPropertyTest.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NameAndPathPropertyTest.java Thu Aug 14 12:32:34 2014
@@ -0,0 +1,122 @@
+/*
+ * 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 javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class NameAndPathPropertyTest extends AbstractRepositoryTest {
+
+    public NameAndPathPropertyTest(NodeStoreFixture fixture) {
+        super(fixture);
+    }
+
+    @Test
+    public void testMVNameProperty() throws Exception {
+        Session session = getAdminSession();
+        Node testRootNode = session.getRootNode().addNode("testRoot");
+        try {
+            testRootNode.setProperty("testNameProperty", new String[]{"foobar:test"}, PropertyType.NAME);
+            session.save();
+            fail("adding a MV name property without registered namespace must fail.");
+        } catch (RepositoryException e) {
+            // ok.
+        }
+    }
+
+    @Test
+    public void testMVPathProperty() throws Exception {
+        Session session = getAdminSession();
+        Node testRootNode = session.getRootNode().addNode("testRoot");
+        try {
+            testRootNode.setProperty("testPathProperty", new String[]{
+                    "/foobar:test",
+                    "/foobar:test/a",
+                    "/a/foobar:test",
+            }, PropertyType.PATH);
+            session.save();
+            fail("adding a MV path property without registered namespace must fail.");
+        } catch (RepositoryException e) {
+            // ok.
+        }
+    }
+
+
+    @Test
+    public void testPathProperty() throws Exception {
+        Session session = getAdminSession();
+        Node testRootNode = session.getRootNode().addNode("testRoot");
+        try {
+            testRootNode.setProperty("testPathProperty", "/foobar:test", PropertyType.PATH);
+            session.save();
+            fail("adding a  path property without registered namespace must fail.");
+        } catch (RepositoryException e) {
+            // ok.
+        }
+    }
+
+    @Test
+    public void testInvalidPathProperty() throws Exception {
+        Session session = getAdminSession();
+        Node testRootNode = session.getRootNode().addNode("testRoot");
+        try {
+            testRootNode.setProperty("testPathProperty", "/*/dfsdf", PropertyType.PATH);
+            session.save();
+            fail("adding a  path property without registered namespace must fail.");
+        } catch (RepositoryException e) {
+            // ok.
+        }
+    }
+
+
+    @Test
+    public void testInvalidMVPathProperty() throws Exception {
+        Session session = getAdminSession();
+        Node testRootNode = session.getRootNode().addNode("testRoot");
+        try {
+            testRootNode.setProperty("testPathProperty", new String[]{"/*/dfsdf"}, PropertyType.PATH);
+            session.save();
+            fail("adding a  path property without registered namespace must fail.");
+        } catch (RepositoryException e) {
+            // ok.
+        }
+    }
+
+
+    private void traverse(Node node) throws RepositoryException {
+        System.out.println(node.getPath());
+        PropertyIterator iter = node.getProperties();
+        while (iter.hasNext()) {
+            Property p = iter.nextProperty();
+            System.out.println(p.getPath());
+            p.getDefinition();
+        }
+        NodeIterator niter = node.getNodes();
+        while (niter.hasNext()) {
+            traverse(niter.nextNode());
+        }
+    }
+}
\ No newline at end of file