jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebast...@apache.org
Subject svn commit: r812102 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/nodetype/ test/java/org/apache/jackrabbit/core/nodetype/xml/ test/resources/org/apache/jackrabbit/core/nodetype/xml/
Date Mon, 07 Sep 2009 12:09:52 GMT
Author: sebastien
Date: Mon Sep  7 12:09:51 2009
New Revision: 812102

URL: http://svn.apache.org/viewvc?rev=812102&view=rev
Log:
JCR-2297 Registering multiple node types with the same name in a single file must fail

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_cnd_nodetypes.cnd
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_xml_nodetypes.xml
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=812102&r1=812101&r2=812102&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Mon Sep  7 12:09:51 2009
@@ -1275,8 +1275,11 @@
         // and do some preliminary checks
         for (NodeTypeDef ntd : ntDefs) {
             Name name = ntd.getName();
-            if (name != null && registeredNTDefs.containsKey(name)) {
+            if (name != null && tmpNTDefCache.containsKey(name)) {
                 String msg = name + " already exists";
+                if (tmpNTDefCache.containsKey(name)) {
+                    msg += " locally";
+                }
                 log.debug(msg);
                 throw new InvalidNodeTypeDefException(msg);
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=812102&r1=812101&r2=812102&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
Mon Sep  7 12:09:51 2009
@@ -65,6 +65,14 @@
     private static final String TEST_NS_CND_NODETYPES =
         "test_ns_cnd_nodetypes.cnd";
 
+    /** Name of the xml nodetype file with same node type name definitions. */
+    private static final String TEST_SAME_NT_NAME_XML_NODETYPES =
+        "test_same_nt_name_xml_nodetypes.xml";
+
+    /** Name of the cnd nodetype file with same node type name definitions. */
+    private static final String TEST_SAME_NT_NAME_CND_NODETYPES =
+        "test_same_nt_name_cnd_nodetypes.cnd";
+
     private static final NameFactory FACTORY = NameFactoryImpl.getInstance();
 
     /** Test node types definitions. */
@@ -252,6 +260,24 @@
         }
     }
 
+    /** Test for same node type name on node type import. */
+    public void testInvalidXMLNodeTypes() throws Exception {
+        JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)
+            superuser.getWorkspace().getNodeTypeManager();
+        try {
+            ntm.registerNodeTypes(
+                TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_XML_NODETYPES),
+                JackrabbitNodeTypeManager.TEXT_XML);
+            fail("Importing multiple node types with the same name must fail");
+        } catch (RepositoryException e) {
+            if (e.getCause() instanceof InvalidNodeTypeDefException) {
+               // Expected
+            } else {
+               throw e;
+            }
+        }
+    }
+
     /** Test for namespace registration on node type import. */
     public void testImportCNDNodeTypes() throws Exception {
         try {
@@ -271,6 +297,24 @@
         }
     }
 
+    /** Test for same node type name on node type import. */
+    public void testInvalidCNDNodeTypes() throws Exception {
+        JackrabbitNodeTypeManager ntm = (JackrabbitNodeTypeManager)
+            superuser.getWorkspace().getNodeTypeManager();
+        try {
+            ntm.registerNodeTypes(
+                TestAll.class.getResourceAsStream(TEST_SAME_NT_NAME_CND_NODETYPES),
+                JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+            fail("Importing multiple node types with the same name must fail");
+        } catch (RepositoryException e) {
+            if (e.getCause() instanceof InvalidNodeTypeDefException) {
+               // Expected
+            } else {
+               throw e;
+            }
+        }
+    }
+
     /** Test for the empty item definition. */
     public void testEmptyItem() {
         PropDef def = getPropDef("itemNodeType", "emptyItem");

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_cnd_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_cnd_nodetypes.cnd?rev=812102&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_cnd_nodetypes.cnd
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_cnd_nodetypes.cnd
Mon Sep  7 12:09:51 2009
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+<testns6 = "test-namespace6">
+
+[testns6:sameNodeType] > nt:base
+
+[testns6:sameNodeType] > nt:unstructured

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_xml_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_xml_nodetypes.xml?rev=812102&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_xml_nodetypes.xml
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_same_nt_name_xml_nodetypes.xml
Mon Sep  7 12:09:51 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!--
+/*
+ * 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.
+ */
+ -->
+<nodeTypes xmlns:testns5="test-namespace5"
+           xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+
+  <nodeType name="testns5:sameNodeType"
+            isMixin="false" hasOrderableChildNodes="false" primaryItemName=""
+            isAbstract="false" isQueryable="false">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+  </nodeType>
+
+  <nodeType name="testns5:sameNodeType"
+            isMixin="false" hasOrderableChildNodes="false" primaryItemName=""
+            isAbstract="false" isQueryable="false">
+    <supertypes>
+      <supertype>nt:unstructured</supertype>
+    </supertypes>
+  </nodeType>
+
+</nodeTypes>



Mime
View raw message