Search in sources :

Example 36 with PropertyDefinition

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

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

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

the class CanSetPropertyStringTest method testConversions.

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

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

the class CanSetPropertyTest method testReturnFalseBecauseIsProtected.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns false if the property is protected.
     */
public void testReturnFalseBecauseIsProtected() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, false, true, false, false);
    // will never happen since at least jcr:primaryType of nt:base accomplish the request
    if (propDef == null) {
        throw new NotExecutableException("No protected property def found.");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value value = NodeTypeUtil.getValueOfType(superuser, propDef.getRequiredType());
    assertFalse("canSetProperty(String propertyName, Value value) must " + "return false if the property is protected.", 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 39 with PropertyDefinition

use of javax.jcr.nodetype.PropertyDefinition 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 40 with PropertyDefinition

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

Aggregations

PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)141 NodeType (javax.jcr.nodetype.NodeType)79 Value (javax.jcr.Value)70 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)61 Node (javax.jcr.Node)27 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)22 Property (javax.jcr.Property)20 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)15 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)14 RepositoryException (javax.jcr.RepositoryException)13 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)11 Test (org.junit.Test)11 InputStream (java.io.InputStream)5 Session (javax.jcr.Session)5 ValueFormatException (javax.jcr.ValueFormatException)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 Name (org.apache.jackrabbit.spi.Name)4