Search in sources :

Example 11 with NodeType

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

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

Example 13 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 14 with NodeType

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

the class CanSetPropertyDateTest method testValueConstraintNotSatisfiedMultiple.

/**
     * Tests if canSetProperty(String propertyName, Value[] values) returns
     * false if values do not satisfy the value constraints of the property def
     */
public void testValueConstraintNotSatisfiedMultiple() throws NotExecutableException, ParseException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, true, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple date property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No multiple date property def with " + "testable value constraints has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value[] values = new Value[] { value };
    assertFalse("canSetProperty(String propertyName, Value[] values) must " + "return false if values do not match the value constraints.", nodeType.canSetProperty(propDef.getName(), values));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 15 with NodeType

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

the class CanSetPropertyDateTest method testValueConstraintNotSatisfied.

/**
     * Tests if canSetProperty(String propertyName, Value value) returns false
     * if value does not match the value constraints of the property def
     */
public void testValueConstraintNotSatisfied() throws NotExecutableException, ParseException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No date property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No date property def with " + "testable value constraints has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    assertFalse("canSetProperty(String propertyName, Value value) must " + "return false if value does not match the value constraints.", nodeType.canSetProperty(propDef.getName(), value));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)258 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)79 Value (javax.jcr.Value)57 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)53 Node (javax.jcr.Node)52 NodeDefinition (javax.jcr.nodetype.NodeDefinition)44 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)41 RepositoryException (javax.jcr.RepositoryException)33 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)27 Session (javax.jcr.Session)20 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)13 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)11 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)6 InputStreamReader (java.io.InputStreamReader)5 NodeIterator (javax.jcr.NodeIterator)5