Search in sources :

Example 96 with NodeType

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

the class NodeTypeTest method testGetPrimaryItemName.

/**
 * Test if node.getPrimaryItemName() returns the same name as
 * node.getPrimaryItem().getName()
 */
public void testGetPrimaryItemName() throws NotExecutableException, RepositoryException {
    Node node = locateNodeWithPrimaryItem(rootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node with primary item defined");
    }
    String name = node.getPrimaryItem().getName();
    NodeType type = node.getPrimaryNodeType();
    assertEquals("node.getPrimaryNodeType().getPrimaryItemName() " + "must return the same name as " + "node.getPrimaryItem().getName()", name, type.getPrimaryItemName());
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType)

Example 97 with NodeType

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

the class NodeTypeTest method testGetDeclaredChildNodeDefs.

/**
 * Test if all node defs returned by getDeclaredChildNodeDefs() are also
 * returned by getChildNodeDefs(). All existing node types are tested.
 */
public void testGetDeclaredChildNodeDefs() throws RepositoryException {
    NodeTypeIterator types = manager.getAllNodeTypes();
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        NodeDefinition[] declaredDefs = type.getDeclaredChildNodeDefinitions();
        NodeDefinition[] defs = type.getChildNodeDefinitions();
        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 node defs returned by " + "getDeclaredChildNodeDefs() must also be " + "returned by getChildNodeDefs().", exists);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            fail("The array returned by " + "getDeclaredChildNodeDefs() must not exceed " + "the one returned by getChildNodeDefs()");
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 98 with NodeType

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

the class CanRemoveItemTest method testRemovableProperty.

/**
 * Tests that {@link NodeType#canRemoveItem(String)} and
 * {@link NodeType#canRemoveProperty(String)} return true
 * if the specified property is not a protected nor a mandatory
 * property.
 */
public void testRemovableProperty() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No mandatory property def found.");
    }
    NodeType type = propDef.getDeclaringNodeType();
    assertTrue("NodeType.canRemoveItem(String itemName) must return true " + "if itemName is not a protected nor a mandatory property def.", type.canRemoveItem(propDef.getName()));
    assertTrue("NodeType.canRemoveProperty(String propertyName) must return true " + "if propertyName is not a protected nor a mandatory property def.", type.canRemoveProperty(propDef.getName()));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 99 with NodeType

use of javax.jcr.nodetype.NodeType 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)

Example 100 with NodeType

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

the class CanRemoveItemTest method testMandatoryChildNode.

/**
 * Tests if {@link NodeType#canRemoveItem(String)} and
 * {@link NodeType#canRemoveNode(String)} return
 * false if the specified node is a mandatory child node.
 */
public void testMandatoryChildNode() 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 mandatory child node def.", type.canRemoveItem(nodeDef.getName()));
    assertFalse("NodeType.canRemoveNode(String nodeName) must return false " + "if nodeName is 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

NodeType (javax.jcr.nodetype.NodeType)272 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)81 Node (javax.jcr.Node)63 Value (javax.jcr.Value)60 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)55 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)46 NodeDefinition (javax.jcr.nodetype.NodeDefinition)45 RepositoryException (javax.jcr.RepositoryException)41 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 Session (javax.jcr.Session)29 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)15 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)12 NodeIterator (javax.jcr.NodeIterator)7 Property (javax.jcr.Property)7 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)7