jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r718249 - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/ jackrabbit-spi2jcr/src/test/resources/
Date Mon, 17 Nov 2008 14:48:11 GMT
Author: angela
Date: Mon Nov 17 06:48:11 2008
New Revision: 718249

URL: http://svn.apache.org/viewvc?rev=718249&view=rev
Log:
JCR-1862: Transient removal of mandatory item throws ConstraintViolationException

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/custom_nodetypes.xml
    jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repositoryStubImpl.properties

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=718249&r1=718248&r2=718249&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
Mon Nov 17 06:48:11 2008
@@ -520,7 +520,7 @@
     }
 
     /**
-     * An item state cannot be removed if it is either protected or mandatory.
+     * An item state cannot be removed if it is protected.
      *
      * @param itemState
      * @throws ConstraintViolationException
@@ -535,9 +535,6 @@
             definition = ((PropertyState)itemState).getDefinition();
         }
         checkProtection(definition);
-        if (definition.isMandatory()) {
-            throw new ConstraintViolationException("Cannot remove mandatory item");
-        }
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java?rev=718249&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
Mon Nov 17 06:48:11 2008
@@ -0,0 +1,133 @@
+/*
+ * 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.jcr2spi.nodetype;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Property;
+
+/** <code>MandatoryItemTest</code>... */
+public class MandatoryItemTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(MandatoryItemTest.class);
+
+    private NodeDefinition childNodeDef;
+    private PropertyDefinition childPropDef;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType);
+        NodeDefinition[] ndefs = nt.getChildNodeDefinitions();
+        for (int i = 0; i < ndefs.length; i++) {
+            if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated())
{
+                childNodeDef = ndefs[i];
+                break;
+            }
+        }
+        PropertyDefinition[] pdefs = nt.getPropertyDefinitions();
+        for (int i = 0; i < pdefs.length; i++) {
+            if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated())
{
+                childPropDef = pdefs[i];
+                break;
+            }
+        }
+        if (childPropDef == null && childNodeDef == null) {
+            throw new NotExecutableException();
+        }
+    }
+
+    public void testCreation() throws NotExecutableException, RepositoryException {
+        Node n;
+        try {
+            n = testRootNode.addNode(nodeName1, testNodeType);
+        } catch (RepositoryException e) {
+            throw new NotExecutableException();
+        }
+
+        try {
+            testRootNode.save();
+            fail("Saving without having added the mandatory child items must fail.");
+        } catch (ConstraintViolationException e) {
+            // success
+        }
+
+        if (childNodeDef != null) {
+            n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
+        }
+        if (childPropDef != null) {
+            // TODO: check if definition defines default values
+            n.setProperty(childPropDef.getName(), "any value");
+        }
+        // now save must succeed.
+        testRootNode.save();
+    }
+
+    public void testRemoval() throws NotExecutableException, RepositoryException {
+        Node n;
+        Node childN = null;
+        Property childP = null;
+        try {
+            n = testRootNode.addNode(nodeName1, testNodeType);
+            if (childNodeDef != null) {
+                childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
+            }
+            if (childPropDef != null) {
+                // TODO: check if definition defines default values
+                childP = n.setProperty(childPropDef.getName(), "any value");
+            }
+            testRootNode.save();
+        } catch (RepositoryException e) {
+            throw new NotExecutableException();
+        }
+
+        // remove the mandatory items ((must succeed))
+        if (childN != null) {
+            childN.remove();
+        }
+        if (childP != null) {
+            childP.remove();
+        }
+        // ... however, saving must not be allowed.
+        try {
+            testRootNode.save();
+            fail("removing mandatory child items without re-adding them must fail.");
+        } catch (ConstraintViolationException e) {
+            // success.
+        }
+
+        // re-add the mandatory items
+        if (childNodeDef != null) {
+            childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
+        }
+        if (childPropDef != null) {
+            // TODO: check if definition defines default values
+            childP = n.setProperty(childPropDef.getName(), "any value");
+        }
+        // save must succeed now.
+        testRootNode.save();
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/MandatoryItemTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java?rev=718249&r1=718248&r2=718249&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/nodetype/TestAll.java
Mon Nov 17 06:48:11 2008
@@ -30,6 +30,7 @@
 
         suite.addTestSuite(AddMixinTest.class);
         suite.addTestSuite(RemoveMixinTest.class);
+        suite.addTestSuite(MandatoryItemTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/custom_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/custom_nodetypes.xml?rev=718249&r1=718248&r2=718249&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/custom_nodetypes.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/custom_nodetypes.xml Mon Nov 17
06:48:11 2008
@@ -242,6 +242,19 @@
     </childNodeDefinition>
   </nodeType>
 
+  <!-- Defines a test nodetype with mandatory non-protected child definitions -->
+  <nodeType name="test:mandatoryChildDefs" isMixin="false" hasOrderableChildNodes="false"
primaryItemName="">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDefinition name="mandatoryProp" requiredType="undefined" autoCreated="false"
mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
+    <childNodeDefinition name="mandatoryNode" defaultPrimaryType="nt:unstructured" autoCreated="false"
mandatory="true" onParentVersion="COMPUTE" protected="false" sameNameSiblings="false">
+      <requiredPrimaryTypes>
+        <requiredPrimaryType>nt:base</requiredPrimaryType>
+      </requiredPrimaryTypes>
+    </childNodeDefinition>
+  </nodeType>
+
 
   <!-- ======================================================== -->
   <!-- Node type definitions only required for jackrabbit core  -->

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repositoryStubImpl.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repositoryStubImpl.properties?rev=718249&r1=718248&r2=718249&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repositoryStubImpl.properties (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/test/resources/repositoryStubImpl.properties Mon
Nov 17 06:48:11 2008
@@ -485,3 +485,6 @@
 javax.jcr.tck.OnParentVersionAbortTest.nodetype=nt:unstructured
 javax.jcr.tck.OnParentVersionIgnoreTest.nodename4=test:ignoreOnParentVersion
 javax.jcr.tck.OnParentVersionIgnoreTest.nodetype=nt:unstructured
+
+# jcr2spi: special nodetype with mandatory non-protected child items
+javax.jcr.tck.MandatoryItemTest.nodetype=test:mandatoryChildDefs



Mime
View raw message