jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1452698 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype: CanAddChildNodeCallWithNodeTypeTest.java NodeTypeUtil.java
Date Tue, 05 Mar 2013 08:49:49 GMT
Author: alexparvulescu
Date: Tue Mar  5 08:49:49 2013
New Revision: 1452698

URL: http://svn.apache.org/r1452698
Log:
JCR-3528 Node type selection for CanAddChildNodeCallWithNodeTypeTest#testResidualAndLegalType
is not optimal

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java?rev=1452698&r1=1452697&r2=1452698&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/CanAddChildNodeCallWithNodeTypeTest.java
Tue Mar  5 08:49:49 2013
@@ -218,18 +218,23 @@ public class CanAddChildNodeCallWithNode
     public void testResidualAndLegalType()
             throws NotExecutableException, RepositoryException {
 
-        NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, true);
+        String type = null;
+        NodeType nodeType = null;
 
-        if (nodeDef == null) {
-            throw new NotExecutableException("No testable residual child node def.");
+        for (NodeDefinition nodeDef : NodeTypeUtil.locateAllChildNodeDef(
+                session, false, false, true)) {
+            for (NodeType nt : nodeDef.getRequiredPrimaryTypes()) {
+                if (!nt.isAbstract()) {
+                    nodeType = nodeDef.getDeclaringNodeType();
+                    type = nt.getName();
+                }
+            }
         }
-
-        String type = nodeDef.getRequiredPrimaryTypes()[0].getName();
-        if (type.equals(ntBase)) {
-            // nt:base is abstract and can never be added, upgrade for check below
-            type = ntUnstructured;
+        if (nodeType == null || type == null) {
+            throw new NotExecutableException(
+                    "No testable residual child node def.");
         }
-        NodeType nodeType = nodeDef.getDeclaringNodeType();
+
         String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
 
         assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) "
+

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?rev=1452698&r1=1452697&r2=1452698&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
Tue Mar  5 08:49:49 2013
@@ -28,7 +28,10 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
+
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -147,6 +150,114 @@ public class NodeTypeUtil {
     }
 
     /**
+     * Locate all non-protected child node def declared by a non-abstract node type
+     * 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 List<NodeDefinition> locateAllChildNodeDef(Session session,
+                                                    boolean regardDefaultPrimaryType,
+                                                    boolean defaultPrimaryType,
+                                                    boolean residual)
+            throws RepositoryException {
+        List<NodeDefinition> nodeTypes = new ArrayList<NodeDefinition>();
+
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator types = manager.getAllNodeTypes();
+
+        boolean skip = false;
+
+        while (types.hasNext()) {
+            NodeType type = types.nextNodeType();
+
+            // node types with more than one residual child node definition
+            // will cause trouble in test cases. the implementation
+            // might pick another definition than the definition returned by
+            // this method, when a child node is set.
+            NodeDefinition[] childDefs = type.getChildNodeDefinitions();
+            int residuals = 0;
+            for (int i = 0; i < childDefs.length; i++) {
+                if (childDefs[i].getName().equals("*")) {
+                    residuals++;
+                }
+            }
+            if (residuals > 1) {
+                // more than one residual, not suitable for tests
+                continue;
+            }
+
+            NodeDefinition nodeDefs[] = type.getDeclaredChildNodeDefinitions();
+
+            for (int i = 0; i < nodeDefs.length; i++) {
+                NodeDefinition nodeDef = nodeDefs[i];
+
+                if (nodeDef.getDeclaringNodeType().isAbstract()) {
+                    continue;
+                }
+
+                if (nodeDef.isProtected()) {
+                    continue;
+                }
+
+                if (nodeDef.getRequiredPrimaryTypes().length > 1) {
+                    // behaviour of implementations that support multiple multiple inheritance
+                    // of primary node types is not specified
+                    continue;
+                }
+
+                if (regardDefaultPrimaryType) {
+
+                    if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() ==
null) {
+                        continue;
+                    }
+
+                    if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() !=
null) {
+                        continue;
+                    }
+                }
+
+                if (residual && !nodeDef.getName().equals("*")) {
+                    continue;
+                }
+
+                if (!residual) {
+                    // if another child node def is a residual definition
+                    // skip the current node type
+                    NodeDefinition nodeDefsAll[] = type.getChildNodeDefinitions();
+                    for (int j = 0; j < nodeDefsAll.length; j++) {
+                        if (nodeDefsAll[j].getName().equals("*")) {
+                            skip = true;
+                            break;
+                        }
+                    }
+                    if (skip) {
+                        // break the loop of the current child not defs
+                        skip = false;
+                        break;
+                    }
+                }
+
+                nodeTypes.add(nodeDef);
+            }
+        }
+        return nodeTypes;
+    }
+
+    /**
      * Locate a child node def parsing all node types
      *
      * @param session     the session to access the node types



Mime
View raw message