Search in sources :

Example 36 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)

Example 37 with NodeType

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

the class CanSetPropertyBinaryTest method testValueConstraintNotSatisfied.

/**
     * Tests if canSetProperty(String propertyName, Value value) returns false
     * if value does not satisfy the value constraints of the property def
     */
public void testValueConstraintNotSatisfied() throws NotExecutableException, ParseException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BINARY, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No binary 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)

Example 38 with NodeType

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

the class CanSetPropertyBinaryTest 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.BINARY, true, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple binary property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No multiple binary 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 39 with NodeType

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

the class CanSetPropertyBinaryTest method testConversionsMultiple.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value[] values)
     * returns true if all values and its types are convertible to BinaryValue.
     */
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BINARY, true, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple string property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
    Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
    Value[] stringValues = new Value[] { stringValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type StringValue", nodeType.canSetProperty(propDef.getName(), stringValues));
    Value[] binaryValues = new Value[] { binaryValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BinaryValue", nodeType.canSetProperty(propDef.getName(), binaryValues));
    Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
    Value[] dateValues = new Value[] { dateValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
    Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
    Value[] doubleValues = new Value[] { doubleValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
    Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
    Value[] longValues = new Value[] { longValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
    Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
    Value[] booleanValues = new Value[] { booleanValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
    Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
    Value[] nameValues = new Value[] { nameValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
    Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
    Value[] pathValues = new Value[] { pathValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type PathValue", nodeType.canSetProperty(propDef.getName(), pathValues));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 40 with NodeType

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

the class CanSetPropertyBooleanTest method testConversions.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns true if value and its type are convertible to BooleanValue.
     */
public void testConversions() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, false, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No boolean property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a StringValue", nodeType.canSetProperty(propDef.getName(), stringValue));
    Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a BinaryValue" + "in UTF-8", nodeType.canSetProperty(propDef.getName(), binaryValue));
    Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a DateValue", nodeType.canSetProperty(propDef.getName(), dateValue));
    Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValue));
    Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a LongValue", nodeType.canSetProperty(propDef.getName(), longValue));
    Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Boolean and value is a BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValue));
    Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a NameValue", nodeType.canSetProperty(propDef.getName(), nameValue));
    Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Boolean and value is a PathValue", nodeType.canSetProperty(propDef.getName(), pathValue));
}
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