Search in sources :

Example 26 with NodeType

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

the class CanSetPropertyMultipleTest method testMultipleValuesNull.

/**
     * Tests if canSetProperty(String propertyName, Value[] values) where values
     * is null returns the same as canRemoveItem
     */
public void testMultipleValuesNull() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No not protected, multiple property def found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    assertEquals("nodeType.canSetProperty(String propertyName, Value[] values) " + "where values is null must return the same result as " + "nodeType.canRemoveItem(String propertyName)", nodeType.canRemoveItem(propDef.getName()), nodeType.canSetProperty(propDef.getName(), (Value[]) null));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 27 with NodeType

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

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

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

the class CanSetPropertyNameTest method testConversions.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns true if value and its type are convertible to NameValue.
     */
public void testConversions() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.NAME, false, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No name property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value nameStringValue = superuser.getValueFactory().createValue("abc");
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Name and value is a StringValue " + "that is convertible to a NameValue", nodeType.canSetProperty(propDef.getName(), nameStringValue));
    Value noNameStringValue = superuser.getValueFactory().createValue("a:b:c");
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a StringValue " + "that is not convertible to a NameValue", nodeType.canSetProperty(propDef.getName(), noNameStringValue));
    Value nameBinaryValue = superuser.getValueFactory().createValue("abc", PropertyType.BINARY);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Name and value is a UTF-8 " + "BinaryValue that is convertible to a NameValue", nodeType.canSetProperty(propDef.getName(), nameBinaryValue));
    Value noNameBinaryValue = superuser.getValueFactory().createValue("a:b:c", PropertyType.BINARY);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a UTF-8 " + "BinaryValue that is not convertible to a NameValue", nodeType.canSetProperty(propDef.getName(), noNameBinaryValue));
    Value dateValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DATE);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a DateValue", nodeType.canSetProperty(propDef.getName(), dateValue));
    Value doubleValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DOUBLE);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValue));
    Value longValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a LongValue", nodeType.canSetProperty(propDef.getName(), longValue));
    Value booleanValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BOOLEAN);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name 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 Name and value is a NameValue", nodeType.canSetProperty(propDef.getName(), nameValue));
    Value namePathValue = superuser.getValueFactory().createValue("abc", PropertyType.PATH);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Name and value is a PathValue " + "if Path is relative, is one element long and has no index", nodeType.canSetProperty(propDef.getName(), namePathValue));
    Value noNamePathValue = superuser.getValueFactory().createValue("/abc", PropertyType.PATH);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Name and value is a PathValue " + "if Path is not relative, is more than one element long or has an index", nodeType.canSetProperty(propDef.getName(), noNamePathValue));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 29 with NodeType

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

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

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

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

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