Search in sources :

Example 41 with NodeDefinition

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

the class CanAddChildNodeCallWithoutNodeTypeTest method testDefinedWithDefault.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
     * true if <code>NodeType</code> contains a <code>NodeDef</code>  named
     * <code>childNodeName</code> with a default primary type.
     */
public void testDefinedWithDefault() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No child node def with " + "defaultPrimaryType found");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    assertTrue("NodeType.canAddChildNode(String childNodeName) must return " + "true if child node def 'childNodeName' defines a defaultPrimaryType.", nodeType.canAddChildNode(nodeDef.getName()));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 42 with NodeDefinition

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

the class CanRemoveItemTest method testProtectedChildNode.

/**
     * Tests if {@link NodeType#canRemoveItem(String)} and
     * {@link NodeType#canRemoveNode(String)} return 
     * false if the specified node is a protected child node.
     */
public void testProtectedChildNode() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No mandatory property def found.");
    }
    NodeType type = nodeDef.getDeclaringNodeType();
    assertFalse("NodeType.canRemoveItem(String itemName) must return false " + "if itemName is a protected child node def.", type.canRemoveItem(nodeDef.getName()));
    assertFalse("NodeType.canRemoveNode(String nodeName) must return false " + "if nodeName is a protected child node def.", type.canRemoveNode(nodeDef.getName()));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 43 with NodeDefinition

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

the class CanAddChildNodeCallWithNodeTypeTest method testUndefined.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns false if <code>childNodeName</code> does not match the <code>NodeDef</code>.
     */
public void testUndefined() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, true, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No testable node type found.");
    }
    String type = nodeDef.getRequiredPrimaryTypes()[0].getName();
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
    assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if childNodeName does not match the " + "child node def of NodeType.", nodeType.canAddChildNode(undefinedName, type));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 44 with NodeDefinition

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

the class CanAddChildNodeCallWithNodeTypeTest method testCanAddAbstractType.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns false if <code>nodeTypeName</code> represents an abstract node type.
     */
public void testCanAddAbstractType() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No testable node type found.");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String childNodeName = nodeDef.getName();
    String abstractName = null;
    NodeTypeIterator it = manager.getPrimaryNodeTypes();
    while (it.hasNext() && abstractName == null) {
        NodeType nt = it.nextNodeType();
        if (nt.isAbstract()) {
            abstractName = nt.getName();
        }
    }
    if (abstractName == null) {
        throw new NotExecutableException("No abstract type found.");
    }
    assertFalse("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return false if nodeTypeName represents an abstract node type.", nodeType.canAddChildNode(childNodeName, abstractName));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 45 with NodeDefinition

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

the class NodeTypeDefinitionImpl method getDeclaredChildNodeDefinitions.

/**
     * {@inheritDoc}
     */
public NodeDefinition[] getDeclaredChildNodeDefinitions() {
    QItemDefinition[] cnda = ntd.getChildNodeDefs();
    NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
    for (int i = 0; i < cnda.length; i++) {
        nodeDefs[i] = new NodeDefinitionImpl(cnda[i], null, resolver);
    }
    return nodeDefs;
}
Also used : NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) NodeDefinition(javax.jcr.nodetype.NodeDefinition) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3