Search in sources :

Example 1 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class AddNodeTest method testMixinNodeType.

/**
     * Tests if addNode() throws a ConstraintViolationException in case
     * of an mixin node type.
     */
public void testMixinNodeType() throws RepositoryException, NotExecutableException {
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeIterator nts = ntMgr.getMixinNodeTypes();
    if (nts.hasNext()) {
        try {
            testRootNode.addNode(nodeName1, nts.nextNodeType().getName());
            superuser.save();
            fail("Expected ConstraintViolationException.");
        } catch (ConstraintViolationException e) {
        // correct.
        }
    } else {
        throw new NotExecutableException("no mixins.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 2 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeDefTest method testGetDefaultPrimaryTypes.

/**
     * 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. Also
     * tests the string based access ({@link NodeDefinition#getDefaultPrimaryTypeName()}.
     * 
     * @since JCR 2.0
     */
public void testGetDefaultPrimaryTypes() 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++) {
            NodeDefinition def = defs[i];
            NodeType defaultType = def.getDefaultPrimaryType();
            String defaultTypeName = def.getDefaultPrimaryTypeName();
            if (defaultType != null) {
                NodeType[] requiredTypes = def.getRequiredPrimaryTypes();
                for (int j = 0; j < requiredTypes.length; j++) {
                    NodeType requiredType = requiredTypes[j];
                    boolean isSubType = compareWithRequiredType(requiredType, defaultType);
                    assertTrue("The NodeType returned by " + "getDefaultPrimaryType or one of its " + "supertypes must match all NodeTypes " + "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);
            }
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 3 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeDefTest method testGetRequiredPrimaryTypeNames.

/**
     * 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<String> rptnames = new HashSet<String>();
            for (int j = 0; j < requiredPrimaryTypes.length; j++) {
                rptnames.add(requiredPrimaryTypes[j].getName());
            }
            Set<String> rptnames2 = new HashSet<String>(Arrays.asList(defs[i].getRequiredPrimaryTypeNames()));
            assertEquals("names returned from getRequiredPrimaryTypeNames should match types returned from getRequiredPrimaryTypes", rptnames, rptnames2);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) HashSet(java.util.HashSet)

Example 4 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeTypeManagerTest method testGetNodeType.

/**
     * Test if getNodeType(String nodeTypeName) returns the expected NodeType and
     * if a NoSuchTypeException is thrown if no according node type is existing
     */
public void testGetNodeType() throws RepositoryException {
    NodeType type = manager.getAllNodeTypes().nextNodeType();
    assertEquals("getNodeType(String nodeTypeName) does not return correct " + "NodeType", manager.getNodeType(type.getName()).getName(), type.getName());
    StringBuffer notExistingName = new StringBuffer("X");
    NodeTypeIterator types = manager.getAllNodeTypes();
    while (types.hasNext()) {
        // build a name which is for sure not existing
        // (":" of namespace prefix will be replaced later on)
        notExistingName.append(types.nextNodeType().getName());
    }
    try {
        manager.getNodeType(notExistingName.toString().replaceAll(":", ""));
        fail("getNodeType(String nodeTypeName) must throw a " + "NoSuchNodeTypeException if no according NodeType " + "does exist");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 5 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeTypeTest method testGetDeclaredPropertyDefs.

/**
     * Test if all property defs returned by getDeclatedPropertyDefs() are also
     * returned by getPropertyDefs(). All existing node types are tested.
     */
public void testGetDeclaredPropertyDefs() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] declaredDefs = type.getDeclaredPropertyDefinitions();
        PropertyDefinition[] defs = type.getPropertyDefinitions();
        try {
            for (int i = 0; i < declaredDefs.length; i++) {
                boolean exists = false;
                for (int j = 0; j < defs.length; j++) {
                    if (defs[j].getName().equals(declaredDefs[i].getName())) {
                        exists = true;
                        break;
                    }
                }
                assertTrue("All property defs returned by " + "getDeclaredPropertyDefs() must also be " + "returned by getPropertyDefs()", exists);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            fail("The array returned by " + "getDeclaredPropertyDefs() must not exceed " + "the one returned by getPropertyDefs()");
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

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