Search in sources :

Example 16 with NodeType

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

the class CanSetPropertyDateTest method testConversions.

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

Example 17 with NodeType

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

the class CanSetPropertyDoubleTest method testConversions.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns true if value and its type are convertible to DoubleValue.
     */
public void testConversions() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.DOUBLE, false, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No double property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value anyStringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Double and value is a StringValue " + "that is not convertible to a DoubleValue", nodeType.canSetProperty(propDef.getName(), anyStringValue));
    Value doubleStringValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE).getString());
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Double and value is a StringValue " + "that is convertible to a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleStringValue));
    Value anyBinaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Double and value is a UTF-8 " + "BinaryValue that is not convertible to a DoubleValue", nodeType.canSetProperty(propDef.getName(), anyBinaryValue));
    Value doubleBinaryValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE).getString(), PropertyType.BINARY);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Double and value is a UTF-8 " + "BinaryValue that is convertible to a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleBinaryValue));
    Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Double and value is a DateValue", nodeType.canSetProperty(propDef.getName(), dateValue));
    Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Double and value is a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValue));
    Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Double and value is a LongValue", nodeType.canSetProperty(propDef.getName(), longValue));
    Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Double 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 Double 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 Double 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)

Example 18 with NodeType

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

the class CanSetPropertyLongTest method testConversionsMultiple.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value[] values)
     * returns true if all values and its types are convertible to LongValue.
     */
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG, true, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple long property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value longValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG);
    Value anyStringValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.STRING);
    Value[] anyStringValues = new Value[] { longValue, anyStringValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type StringValue " + "that are not convertible to LongValues", nodeType.canSetProperty(propDef.getName(), anyStringValues));
    Value longStringValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG).getString());
    Value[] longStringValues = new Value[] { longStringValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type StringValue " + "that are convertible to LongValues", nodeType.canSetProperty(propDef.getName(), longStringValues));
    Value anyBinaryValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BINARY);
    Value[] anyBinaryValues = new Value[] { longValue, anyBinaryValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type BinaryValue " + "that are not convertible to LongValues", nodeType.canSetProperty(propDef.getName(), anyBinaryValues));
    Value longBinaryValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG).getString(), PropertyType.BINARY);
    Value[] longBinaryValues = new Value[] { longBinaryValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type BinaryValue " + "that are convertible to LongValues", nodeType.canSetProperty(propDef.getName(), longBinaryValues));
    Value dateValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DATE);
    Value[] dateValues = new Value[] { dateValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
    Value doubleValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DOUBLE);
    Value[] doubleValues = new Value[] { doubleValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
    Value[] longValues = new Value[] { longValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
    Value booleanValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BOOLEAN);
    Value[] booleanValues = new Value[] { longValue, booleanValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
    Value nameValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.NAME);
    Value[] nameValues = new Value[] { longValue, nameValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
    Value pathValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.PATH);
    Value[] pathValues = new Value[] { longValue, pathValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long 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 19 with NodeType

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

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

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

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