jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r772634 - /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeDefTest.java
Date Thu, 07 May 2009 12:26:37 GMT
Author: reschke
Date: Thu May  7 12:26:36 2009
New Revision: 772634

URL: http://svn.apache.org/viewvc?rev=772634&view=rev
Log:
JCR-2085: add tests covering new methods of NodeDefinition (getRequiredPrimaryTypeNames and
getDefaultRequiredTypeName)

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

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeDefTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeDefTest.java?rev=772634&r1=772633&r2=772634&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeDefTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeDefTest.java
Thu May  7 12:26:36 2009
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.test.api.nodetype;
 
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
 
@@ -162,12 +166,11 @@
     public void testGetRequiredPrimaryTypes()
             throws RepositoryException {
 
-        NodeTypeIterator types = manager.getAllNodeTypes();
         // loop all node types
-        while (types.hasNext()) {
+        for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
             NodeType type = types.nextNodeType();
             NodeDefinition defs[] = type.getChildNodeDefinitions();
-
+            
             for (int i = 0; i < defs.length; i++) {
                 assertTrue("getRequiredPrimaryTypes() must never return an " +
                         "empty array.",
@@ -176,17 +179,45 @@
         }
     }
 
+    /**
+     * Tests that the information from getRequiredPrimaryTypeNames()
+     * matches getRequiredPrimaryTypes().
+     * 
+     * @since JCR 2.0
+     */
+    public void testGetRequiredPrimaryTypeNames()
+            throws RepositoryException {
+
+        // loop all node types
+        for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
+            NodeType type = types.nextNodeType();
+            NodeDefinition defs[] = type.getChildNodeDefinitions();
+            
+            for (int i = 0; i < defs.length; i++) {
+                NodeType requiredPrimaryTypes[] = defs[i].getRequiredPrimaryTypes();
+                Set rptnames = new HashSet();
+                for (int j = 0; j < requiredPrimaryTypes.length; j++) {
+                    rptnames.add(requiredPrimaryTypes[j].getName());
+                }
+                
+                Set rptnames2 = new HashSet(Arrays.asList(defs[i].getRequiredPrimaryTypeNames()));
+                assertEquals("names returned from getRequiredPrimaryTypeNames should match
types returned from getRequiredPrimaryTypes", rptnames, rptnames2);
+            }
+        }
+    }
 
     /**
      * Tests if the default primary type is of the same or a sub node type as the
-     * the required primary types. Test runs for all existing node types.
+     * the required primary types. Test runs for all existing node types. Also
+     * tests the string based access ({@link NodeDefinition#getDefaultPrimaryTypeName()}.
+     * 
+     * @since JCR 2.0
      */
     public void testGetDefaultPrimaryTypes()
             throws RepositoryException {
 
-        NodeTypeIterator types = manager.getAllNodeTypes();
         // loop all node types
-        while (types.hasNext()) {
+        for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
             NodeType type = types.nextNodeType();
             NodeDefinition defs[] = type.getChildNodeDefinitions();
 
@@ -194,6 +225,7 @@
 
                 NodeDefinition def = defs[i];
                 NodeType defaultType = def.getDefaultPrimaryType();
+                String defaultTypeName = def.getDefaultPrimaryTypeName();
                 if (defaultType != null) {
 
                     NodeType requiredTypes[] =
@@ -211,6 +243,13 @@
                                 "returned by getRequiredPrimaryTypes()",
                                 isSubType);
                     }
+
+                    assertEquals("type names obtained from getDefaultPrimaryType and getDefaultPrimaryTypeName
should match", defaultType.getName(), defaultTypeName);
+                    NodeType tmpType = manager.getNodeType(defaultTypeName);
+                    assertEquals(tmpType.getName(), defaultTypeName);
+                }
+                else {
+                    assertNull("getDefaultPrimaryTypeName should return null when getDefaultPrimaryType
does", defaultTypeName);
                 }
             }
         }



Mime
View raw message