use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeDefTest method testIsAutoCreate.
/**
* Tests if auto create nodes are not a residual set definition (getName()
* does not return "*")
*/
public void testIsAutoCreate() throws RepositoryException {
NodeTypeIterator types = manager.getAllNodeTypes();
// loop all node types
while (types.hasNext()) {
NodeType type = types.nextNodeType();
NodeDefinition[] defs = type.getChildNodeDefinitions();
for (int i = 0; i < defs.length; i++) {
if (defs[i].isAutoCreated()) {
assertFalse("An auto create node must not be a " + "residual set definition.", defs[i].getName().equals("*"));
}
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testIsNodeType.
/**
* Test if isNodeType(String nodeTypeName) returns true if nodeTypeName is
* the name of the node itself. Also, primary node types must return true if
* nodeTypeName is "nt:base", and mixin node types must return false in that
* case.
*/
public void testIsNodeType() throws RepositoryException {
// find a primary node type but not "nt:base"
NodeTypeIterator types = manager.getPrimaryNodeTypes();
while (types.hasNext()) {
NodeType type = types.nextNodeType();
assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is nodeTypeName", type.isNodeType(type.getName()));
if (type.isMixin()) {
assertFalse("isNodeType(String nodeTypeName) must return " + "false if NodeType is not a subtype of " + "nodeTypeName", type.isNodeType(ntBase));
} else {
assertTrue("isNodeType(String nodeTypeName) must return true if " + "NodeType is a subtype of nodeTypeName", type.isNodeType(ntBase));
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testGetSupertypes.
/**
* Test if getSupertypes() of a primary node that is not "nt:base" returns at
* least "nt:base". NotExecutableException is thrown if no primary node type
* apart from "nt:base".
*/
public void testGetSupertypes() throws NotExecutableException, RepositoryException {
// find a primary node type but not "nt:base"
NodeTypeIterator types = manager.getPrimaryNodeTypes();
NodeType type = null;
while (types.hasNext()) {
type = types.nextNodeType();
if (!type.getName().equals(ntBase)) {
break;
}
}
// note: type is never null, since at least "nt:base" must exist
if (type.getName().equals("nt:base")) {
throw new NotExecutableException("Workspace does not have sufficient primary node types to run " + "this test. At least nt:base plus anther type are required.");
}
NodeType[] supertypes = type.getSupertypes();
boolean hasNTBase = false;
for (int i = 0; i < supertypes.length; i++) {
if (supertypes[i].getName().equals(ntBase)) {
hasNTBase = true;
break;
}
}
assertTrue("getSupertypes() of a primary node type that is not " + "\"nt:base\" must at least return \"nt:base\"", hasNTBase);
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testGetDeclaredSubtypes.
/**
* 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<String> declaredSubtypeNames = asSetOfNames(type.getDeclaredSubtypes());
Set<String> subtypeNames = asSetOfNames(type.getSubtypes());
assertTrue("all declared subtypes must be subtypes: " + (new HashSet<String>(declaredSubtypeNames).removeAll(subtypeNames)), subtypeNames.containsAll(declaredSubtypeNames));
// check the reverse relation
for (Iterator<String> it = subtypeNames.iterator(); it.hasNext(); ) {
String subtypename = it.next();
boolean isDeclared = declaredSubtypeNames.contains(subtypename);
NodeType subtype = manager.getNodeType(subtypename);
Set<String> supertypeNames = asSetOfNames(subtype.getSupertypes());
assertTrue(name + " should occur in set of super types: " + supertypeNames, supertypeNames.contains(name));
if (isDeclared) {
Set<String> declaredSupertypeNames = asSetOfNames(subtype.getDeclaredSupertypes());
assertTrue(name + " should occur in set of declared super types: " + declaredSupertypeNames, declaredSupertypeNames.contains(name));
}
}
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeTypeTest method testGetDeclaredSupertypes.
/**
* Test if all node types returned by getDeclaredSupertypes() are also
* returned by getSupertypes(). All existing node types are tested.
*/
public void testGetDeclaredSupertypes() throws RepositoryException {
for (NodeTypeIterator types = manager.getAllNodeTypes(); types.hasNext(); ) {
NodeType type = types.nextNodeType();
Set<String> declaredSupertypeNames = asSetOfNames(type.getDeclaredSupertypes());
Set<String> supertypeNames = asSetOfNames(type.getSupertypes());
assertTrue("all declared supertypes must be supertypes: " + (new HashSet<String>(declaredSupertypeNames).removeAll(supertypeNames)), supertypeNames.containsAll(declaredSupertypeNames));
assertEquals("getDeclaredSuperTypes and getDeclaredSuperTypeNames must be consistent", declaredSupertypeNames, new HashSet<String>(Arrays.asList(type.getDeclaredSupertypeNames())));
}
}
Aggregations