Search in sources :

Example 81 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 82 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 83 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 84 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 85 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)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