You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2009/05/07 15:53:26 UTC
svn commit: r772650 - in /jackrabbit/trunk: jackrabbit-core/pom.xml
jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
Author: reschke
Date: Thu May 7 13:53:26 2009
New Revision: 772650
URL: http://svn.apache.org/viewvc?rev=772650&view=rev
Log:
JCR-2090: add test cases for new NodeType methods (note: not tested yet, jackrabbit-code hasn't implemented these methods yet)
Modified:
jackrabbit/trunk/jackrabbit-core/pom.xml
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
Modified: jackrabbit/trunk/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?rev=772650&r1=772649&r2=772650&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/pom.xml Thu May 7 13:53:26 2009
@@ -91,6 +91,7 @@
org.apache.jackrabbit.test.api.ShareableNodeTest#testSharedNodePath
org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitialNumberOfLinearVersions
org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion
+ org.apache.jackrabbit.test.api.nodetype.NodeTypeTest#testGetDeclaredSubtypes
</value>
</property>
</systemProperties>
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java?rev=772650&r1=772649&r2=772650&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/nodetype/NodeTypeTest.java Thu May 7 13:53:26 2009
@@ -16,6 +16,10 @@
*/
package org.apache.jackrabbit.test.api.nodetype;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
import org.apache.jackrabbit.test.AbstractJCRTest;
import org.apache.jackrabbit.test.NotExecutableException;
@@ -194,37 +198,61 @@
}
/**
- * Test if all node types returned by getDeclatedSupertypes() are also
+ * Test if all node types returned by getDeclaredSupertypes() are also
* returned by getSupertypes(). All existing node types are tested.
*/
public void testGetDeclaredSupertypes()
throws RepositoryException {
- NodeTypeIterator types = manager.getAllNodeTypes();
- while (types.hasNext()) {
+ for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
NodeType type = types.nextNodeType();
- NodeType declaredSupertypes[] = type.getDeclaredSupertypes();
- NodeType supertypes[] = type.getSupertypes();
+ Set declaredSupertypeNames = asSetOfNames(type.getDeclaredSupertypes());
+ Set supertypeNames = asSetOfNames(type.getSupertypes());
+
+ assertTrue("all declared supertypes must be supertypes: "
+ + (new HashSet(declaredSupertypeNames).removeAll(supertypeNames)),
+ supertypeNames.containsAll(declaredSupertypeNames));
+ }
+ }
- try {
- for (int i = 0; i < declaredSupertypes.length; i++) {
- boolean exists = false;
- for (int j = 0; j < supertypes.length; j++) {
- if (supertypes[j].getName().equals(declaredSupertypes[i].getName())) {
- exists = true;
- break;
- }
- }
- assertTrue("All node types returned by " +
- "getDeclaredSupertypes() must also be " +
- "returned by getSupertypes()",
- exists);
+ /**
+ * Test if all node types returned by getDeclaredSubtypes() are also
+ * returned by getSubtypes(), and that the information is consistent
+ * with getSuperTypes/getDeclaredSuperTypes. All existing node types are tested.
+ *
+ * @since JCR 2.0
+ */
+ public void testGetDeclaredSubtypes()
+ throws RepositoryException {
+
+ for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
+ NodeType type = types.nextNodeType();
+ String name = type.getName();
+
+ Set declaredSubtypeNames = asSetOfNames(type.getDeclaredSubtypes());
+ Set subtypeNames = asSetOfNames(type.getSubtypes());
+
+ assertTrue("all declared subtypes must be subtypes: "
+ + (new HashSet(declaredSubtypeNames).removeAll(subtypeNames)),
+ subtypeNames.containsAll(declaredSubtypeNames));
+
+ // check the reverse relation
+ for (Iterator it = subtypeNames.iterator(); it.hasNext(); ) {
+ String subtypename = (String) it.next();
+ boolean isDeclared = declaredSubtypeNames.contains(subtypename);
+
+ NodeType subtype = manager.getNodeType(subtypename);
+ Set supertypeNames = asSetOfNames(subtype.getSupertypes());
+
+ assertTrue(name + " should occur in set of super types: " + supertypeNames,
+ supertypeNames.contains(name));
+
+ if (isDeclared) {
+ Set declaredSupertypeNames = asSetOfNames(subtype.getDeclaredSupertypes());
+ assertTrue(name + " should occur in set of declared super types: " + declaredSupertypeNames,
+ declaredSupertypeNames.contains(name));
}
- } catch (ArrayIndexOutOfBoundsException e) {
- fail("The array returned by " +
- "getDeclaredSupertypes() must not exceed " +
- "the one returned by getSupertypes()");
}
}
}
@@ -408,5 +436,26 @@
}
return null;
}
+
+ /**
+ * Return the set of node type names for the specified node types.
+ */
+ private Set asSetOfNames(NodeType[] types) {
+ Set result = new HashSet();
+ for (int i = 0; i < types.length; i++) {
+ result.add(types[i].getName());
+ }
+ return result;
+ }
+ /**
+ * Return the set of node type names for the specified node types.
+ */
+ private Set asSetOfNames(NodeTypeIterator it) {
+ Set result = new HashSet();
+ while (it.hasNext()) {
+ result.add(it.nextNodeType().getName());
+ }
+ return result;
+ }
}
\ No newline at end of file