Search in sources :

Example 6 with NodeDefinition

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

the class CanAddChildNodeCallWithNodeTypeTest method testResidualAndLegalType.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName, String nodeTypeName)</code>
     * returns true if <code>childNodeName</code> does not match the <code>NodeDef</code>
     * but <code>nodeTypeName</code> matches the node type of a residual <code>NodeDef</code>.
     */
public void testResidualAndLegalType() throws NotExecutableException, RepositoryException {
    String type = null;
    NodeType nodeType = null;
    for (NodeDefinition nodeDef : NodeTypeUtil.locateAllChildNodeDef(session, false, false, true)) {
        for (NodeType nt : nodeDef.getRequiredPrimaryTypes()) {
            if (!nt.isAbstract()) {
                nodeType = nodeDef.getDeclaringNodeType();
                type = nt.getName();
            }
        }
    }
    if (nodeType == null || type == null) {
        throw new NotExecutableException("No testable residual child node def.");
    }
    String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
    assertTrue("NodeType.canAddChildNode(String childNodeName, String nodeTypeName) " + "must return true for a not defined childNodeName if nodeTypeName " + "matches the type of a residual child node def", nodeType.canAddChildNode(undefinedName, type));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 7 with NodeDefinition

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

the class CanAddChildNodeCallWithoutNodeTypeTest method testResidualWithDefault.

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

Example 8 with NodeDefinition

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

the class CanAddChildNodeCallWithoutNodeTypeTest method testResidualWithoutDefault.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
     * true if <code>NodeType</code> contains a residual <code>NodeDef</code>
     * without a default primary type.
     */
public void testResidualWithoutDefault() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, true);
    if (nodeDef == null) {
        throw new NotExecutableException("No residual child node def " + "with a defaultPrimaryType found.");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
    assertFalse("NodeType.canAddChildNode(String childNodeName) must return " + "false for a not defiend childNodeName if NodeType has a " + "residual child node definition without a defaultPrimaryType", nodeType.canAddChildNode(undefinedName));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 9 with NodeDefinition

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

the class CanAddChildNodeCallWithoutNodeTypeTest method testDefinedWithoutDefault.

/**
     * Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
     * true if <code>NodeType</code> contains a <code>NodeDef</code>  named
     * <code>childNodeName</code> without a default primary type.
     */
public void testDefinedWithoutDefault() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No child node def without " + "defaultPrimaryType found");
    }
    NodeType nodeType = nodeDef.getDeclaringNodeType();
    assertFalse("NodeType.canAddChildNode(String childNodeName) must return false " + "if child node def 'childNodeName' does not define 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 10 with NodeDefinition

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

the class CanRemoveItemTest method testRemovableChildNode.

/**
     * Tests if {@link NodeType#canRemoveItem(String)} and
     * {@link NodeType#canRemoveNode(String)} return true
     * if the specified node is not a protected nor a mandatory
     * child node.
     */
public void testRemovableChildNode() throws NotExecutableException, RepositoryException {
    NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, false, false);
    if (nodeDef == null) {
        throw new NotExecutableException("No mandatory property def found.");
    }
    NodeType type = nodeDef.getDeclaringNodeType();
    assertTrue("NodeType.canRemoveItem(String itemName) must return true " + "if itemName is not a protected nor a mandatory child node def.", type.canRemoveItem(nodeDef.getName()));
    assertTrue("NodeType.canRemoveNode(String nodeName) must return true " + "if nodeName is not a protected nor a mandatory 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)

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