jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157417 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype: CanRemoveItemTest.java NodeTypeUtil.java TestAll.java
Date Mon, 14 Mar 2005 10:11:21 GMT
Author: mreutegg
Date: Mon Mar 14 02:11:19 2005
New Revision: 157417

URL: http://svn.apache.org/viewcvs?view=rev&rev=157417
Log:
Test cases for NodeType.canRemoveItem().

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java?view=auto&rev=157417
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java
Mon Mar 14 02:11:19 2005
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.test.api.nodetype;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.PropertyDef;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeDef;
+
+/**
+ * Tests <code>NodeType.canRemoveItem(String itemName)</code> returns true if
a
+ * node or property is removable
+ *
+ * @test
+ * @sources CanRemoveItemTest.java
+ * @executeClass org.apache.jackrabbit.test.api.nodetype.CanRemoveItemTest
+ * @keywords level1
+ */
+public class CanRemoveItemTest extends AbstractJCRTest {
+
+    /**
+     * The session we use for the tests
+     */
+    private Session session;
+
+    /**
+     * Sets up the fixture for the test cases.
+     */
+    protected void setUp() throws Exception {
+        isReadOnly = true;
+        super.setUp();
+
+        session = helper.getReadOnlySession();
+    }
+
+    /**
+     * Releases the session aquired in {@link #setUp()}.
+     */
+    protected void tearDown() throws Exception {
+        if (session != null) {
+            session.logout();
+        }
+        super.tearDown();
+    }
+
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * true if <code>itemName</code> is nor a protected nor a mandatory
+     * property.
+     */
+    public void testRemovableProperty()
+            throws NotExecutableException, RepositoryException {
+
+        PropertyDef propDef =
+            NodeTypeUtil.locatePropertyDef(session, false, false);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No mandatory property def found.");
+        }
+
+        NodeType type = propDef.getDeclaringNodeType();
+
+        assertTrue("NodeType.canRemoveIten(String itemName) must return true " +
+                    "if itemName is nor a protected nor a mandatory property def.",
+                    type.canRemoveItem(propDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * false if <code>itemName</code> is a protected property.
+     */
+    public void testProtectedProperty()
+            throws NotExecutableException, RepositoryException {
+
+        PropertyDef propDef =
+            NodeTypeUtil.locatePropertyDef(session, true, false);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No protected property def found.");
+        }
+
+        NodeType type = propDef.getDeclaringNodeType();
+
+        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
+                    "if itemName is a protected property def.",
+                    type.canRemoveItem(propDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * false if <code>itemName</code> is a mandatory property.
+     */
+    public void testMandatoryProperty()
+            throws NotExecutableException, RepositoryException {
+
+        PropertyDef propDef =
+            NodeTypeUtil.locatePropertyDef(session, false, true);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No mandatory property def found.");
+        }
+
+        NodeType type = propDef.getDeclaringNodeType();
+
+        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
+                    "if itemName is a mandatory property def.",
+                    type.canRemoveItem(propDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * true if <code>itemName</code> is nor a protected nor a mandatory
+     * child node.
+     */
+    public void testRemovableChildNode()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef =
+            NodeTypeUtil.locateChildNodeDef(session, false, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No mandatory property def found.");
+        }
+
+        NodeType type = nodeDef.getDeclaringNodeType();
+
+        assertTrue("NodeType.canRemoveIten(String itemName) must return true " +
+                   "if itemName is nor a protected nor a mandatory child node def.",
+                   type.canRemoveItem(nodeDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * false if <code>itemName</code> is a protected child node.
+     */
+    public void testProtectedChildNode()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef =
+            NodeTypeUtil.locateChildNodeDef(session, true, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No mandatory property def found.");
+        }
+
+        NodeType type = nodeDef.getDeclaringNodeType();
+
+        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
+                    "if itemName is a protected child node def.",
+                    type.canRemoveItem(nodeDef.getName()));
+    }
+
+    /**
+     * Tests if <code>NodeType.canRemoveItem(String itemName)</code> removes
+     * false if <code>itemName</code> is a mandatory child node.
+     */
+    public void testMandatoryChildNode()
+            throws NotExecutableException, RepositoryException {
+
+        NodeDef nodeDef =
+            NodeTypeUtil.locateChildNodeDef(session, true, false);
+
+        if (nodeDef == null) {
+            throw new NotExecutableException("No mandatory property def found.");
+        }
+
+        NodeType type = nodeDef.getDeclaringNodeType();
+
+        assertFalse("NodeType.canRemoveIten(String itemName) must return false " +
+                    "if itemName is a mandatory child node def.",
+                    type.canRemoveItem(nodeDef.getName()));
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanRemoveItemTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?view=diff&r1=157416&r2=157417
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
Mon Mar 14 02:11:19 2005
@@ -45,6 +45,25 @@
  */
 class NodeTypeUtil {
 
+    /**
+     * Locate a child node def parsing all node types
+     *
+     * @param session:      the session to access the node types
+     * @param regardDefaultPrimaryType:
+     *                      if true, the default primary type of the returned
+     *                      <code>NodeDef</code> is according to param
+     *                      <code>defaultPrimaryType</code>. If false, the returned
+     *                      <code>NodeDef</code> might have a default primary
type
+     *                      or not.
+     * @param defaultPrimaryType:
+     *                      if <code>regardDefaultPrimaryType</code> is true:
+     *                      if true, the returned <code>NodeDef</code> has a
+     *                      default primary type, else not
+     * @param residual:     if true, the returned <code>NodeDef</code> is of
+     *                      the residual name "*", else not
+     * @return
+     * @throws RepositoryException
+     */
     public static NodeDef locateChildNodeDef(Session session,
                                              boolean regardDefaultPrimaryType,
                                              boolean defaultPrimaryType,
@@ -108,6 +127,56 @@
     }
 
     /**
+     * Locate a child node def parsing all node types
+     *
+     * @param session:      the session to access the node types
+     * @param isProtected:  if true, the returned <code>NodeDef</code> is
+     *                      protected, else not
+     * @param mandatory:    if true, the returned <code>NodeDef</code> is
+     *                      mandatory, else not
+     * @return the first <code>NodeDef</code> found fitting the
+     *         requirements
+     */
+    public static NodeDef locateChildNodeDef(Session session,
+                                             boolean isProtected,
+                                             boolean mandatory)
+        throws RepositoryException {
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator types = manager.getAllNodeTypes();
+
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            NodeDef nodeDefs[] = type.getDeclaredChildNodeDefs();
+
+            for (int i = 0; i < nodeDefs.length; i++) {
+                NodeDef nodeDef = nodeDefs[i];
+
+                if (nodeDef.getName().equals("*")) {
+                    continue;
+                }
+
+                if (isProtected && !nodeDef.isProtected()) {
+                    continue;
+                }
+                if (!isProtected && nodeDef.isProtected()) {
+                    continue;
+                }
+
+                if (mandatory && !nodeDef.isMandatory()) {
+                    continue;
+                }
+                if (!mandatory && nodeDef.isMandatory()) {
+                    continue;
+                }
+
+                return nodeDef;
+            }
+        }
+        return null;
+    }
+
+    /**
      * Locate a property def parsing all node types
      *
      * @param session:      the session to access the node types
@@ -183,6 +252,59 @@
                 }
 
                 if (!residual && propDef.getName().equals("*")) {
+                    continue;
+                }
+
+                if (residual && !propDef.getName().equals("*")) {
+                    continue;
+                }
+
+                return propDef;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Locate a property def parsing all node types
+     *
+     * @param session:      the session to access the node types
+     * @param isProtected:  if true, the returned <code>PropertyDef</code> is
+     *                      protected, else not
+     * @param mandatory:    if true, the returned <code>PropertyDef</code> is
+     *                      mandatory, else not
+     * @return the first <code>PropertyDef</code> found fitting the
+     *         requirements
+     */
+    public static PropertyDef locatePropertyDef(Session session,
+                                                boolean isProtected,
+                                                boolean mandatory)
+            throws RepositoryException {
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator types = manager.getAllNodeTypes();
+
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+            PropertyDef propDefs[] = type.getDeclaredPropertyDefs();
+            for (int i = 0; i < propDefs.length; i++) {
+                PropertyDef propDef = propDefs[i];
+
+                if (propDef.getName().equals("*")) {
+                    continue;
+                }
+
+                if (isProtected && !propDef.isProtected()) {
+                    continue;
+                }
+                if (!isProtected && propDef.isProtected()) {
+                    continue;
+                }
+
+                if (mandatory && !propDef.isMandatory()) {
+                    continue;
+                }
+                if (!mandatory && propDef.isMandatory()) {
                     continue;
                 }
 

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java?view=diff&r1=157416&r2=157417
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/TestAll.java
Mon Mar 14 02:11:19 2005
@@ -58,6 +58,8 @@
         suite.addTestSuite(CanAddChildNodeCallWithNodeTypeTest.class);
         suite.addTestSuite(CanAddChildNodeCallWithoutNodeTypeTest.class);
 
+        suite.addTestSuite(CanRemoveItemTest.class);
+
         return suite;
     }
 }



Mime
View raw message