You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/07/04 11:32:11 UTC

svn commit: r209048 - /incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java

Author: mreutegg
Date: Mon Jul  4 02:32:09 2005
New Revision: 209048

URL: http://svn.apache.org/viewcvs?rev=209048&view=rev
Log:
JCR-156: Review test cases and cross check with 1.0 specification
- Some test cases might fail because the methods locateChildNodeDef() and locatePropertyDef() return child node definitions or property definitions of node types that contain additional residual definitions. This will cause a different exception to be thrown than expected.

Modified:
    incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java

Modified: incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?rev=209048&r1=209047&r2=209048&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java (original)
+++ incubator/jackrabbit/trunk/core/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java Mon Jul  4 02:32:09 2005
@@ -71,6 +71,23 @@
 
         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++) {
@@ -97,7 +114,7 @@
                     continue;
                 }
 
-                if (!residual && i == 0) {
+                if (!residual) {
                     // if another child node def is a residual definition
                     // overjump the current node type
                     NodeDefinition nodeDefsAll[] = type.getChildNodeDefinitions();
@@ -245,10 +262,46 @@
                     continue;
                 }
 
+                // also skip property residual property definition if there
+                // is another residual definition
+                if (residual) {
+                    // check if there is another residual property def
+                    if (getNumResidualPropDefs(type) > 1) {
+                        continue;
+                    }
+                }
+
+                if (!residual) {
+                    // if not looking for a residual property def then there
+                    // must not be any residual definition at all on the node
+                    // type
+                    if (getNumResidualPropDefs(type) > 0) {
+                        continue;
+                    }
+                }
+
                 return propDef;
             }
         }
         return null;
+    }
+
+    /**
+     * Returns the number of residual property definitions of <code>type</code>
+     * including its base types.
+     * @param type the node type
+     * @return the number of residual property definitions.
+     */
+    private static int getNumResidualPropDefs(NodeType type) {
+        PropertyDefinition[] pDefs = type.getPropertyDefinitions();
+        int residuals = 0;
+        for (int j = 0; j < pDefs.length; j++) {
+            PropertyDefinition pDef = pDefs[j];
+            if (pDef.getName().equals("*")) {
+                residuals++;
+            }
+        }
+        return residuals;
     }
 
     /**