Search in sources :

Example 91 with PropertyDefinition

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

the class CanRemoveItemTest method testProtectedProperty.

/**
     * Tests if {@link NodeType#canRemoveItem(String)} and
     * {@link NodeType#canRemoveProperty(String)} return false
     * if the specified property is a protected property.
     */
public void testProtectedProperty() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No protected property def found.");
    }
    NodeType type = propDef.getDeclaringNodeType();
    assertFalse("NodeType.canRemoveItem(String itemName) must return false " + "if itemName is a protected property def.", type.canRemoveItem(propDef.getName()));
    assertFalse("NodeType.canRemoveProperty(String propertyName) must return false " + "if propertyName is a protected property def.", type.canRemoveProperty(propDef.getName()));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 92 with PropertyDefinition

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

the class CanRemoveItemTest method testMandatoryProperty.

/**
     * Tests if {@link NodeType#canRemoveItem(String)} and
     * {@link NodeType#canRemoveProperty(String)} return false
     * if the specified property is a mandatory property.
     */
public void testMandatoryProperty() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, false, true);
    if (propDef == null) {
        throw new NotExecutableException("No mandatory property def found.");
    }
    NodeType type = propDef.getDeclaringNodeType();
    assertFalse("NodeType.canRemoveItem(String itemName) must return false " + "if itemName is a mandatory property def.", type.canRemoveItem(propDef.getName()));
    assertFalse("NodeType.canRemoveProperty(String propertyName) must return false " + "if propertyName is a mandatory property def.", type.canRemoveProperty(propDef.getName()));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 93 with PropertyDefinition

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

the class CanSetPropertyBinaryTest method testConversions.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns true if value and its type are convertible to BinaryValue.
     */
public void testConversions() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BINARY, 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(session, PropertyType.STRING);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Binary 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 Binary and value is a BinaryValue", nodeType.canSetProperty(propDef.getName(), binaryValue));
    Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Binary 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 Binary 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 Binary 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 Binary and value is a BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValue));
    Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Binary and value is a NameValue", nodeType.canSetProperty(propDef.getName(), nameValue));
    Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Binary 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 94 with PropertyDefinition

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

the class CanSetPropertyBooleanTest 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.BOOLEAN, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No boolean property def with " + "testable value constraints has been found");
    }
    Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
    if (value == null) {
        throw new NotExecutableException("No boolean 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 95 with PropertyDefinition

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

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