Search in sources :

Example 56 with NodeTypeIterator

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("*"));
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 57 with NodeTypeIterator

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));
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 58 with NodeTypeIterator

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);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 59 with NodeTypeIterator

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));
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) HashSet(java.util.HashSet)

Example 60 with NodeTypeIterator

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())));
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) HashSet(java.util.HashSet)

Aggregations

NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)65 NodeType (javax.jcr.nodetype.NodeType)53 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)28 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Node (javax.jcr.Node)9 RepositoryException (javax.jcr.RepositoryException)9 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)8 ArrayList (java.util.ArrayList)6 Session (javax.jcr.Session)6 HashSet (java.util.HashSet)4 Value (javax.jcr.Value)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Property (javax.jcr.Property)2