Search in sources :

Example 31 with NodeType

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

the class CanSetPropertyPathTest method testConversions.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value value)
     * returns true if value and its type are convertible to PathValue.
     */
public void testConversions() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.PATH, false, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No path property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value pathStringValue = superuser.getValueFactory().createValue("abc");
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Path and value is a StringValue " + "that is convertible to a PathValue", nodeType.canSetProperty(propDef.getName(), pathStringValue));
    Value noPathStringValue = superuser.getValueFactory().createValue("a:b:c");
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Path and value is a StringValue " + "that is not convertible to a PathValue", nodeType.canSetProperty(propDef.getName(), noPathStringValue));
    Value pathBinaryValue = superuser.getValueFactory().createValue("abc", PropertyType.BINARY);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Path and value is a UTF-8 " + "BinaryValue that is convertible to a PathValue", nodeType.canSetProperty(propDef.getName(), pathBinaryValue));
    Value noPathBinaryValue = superuser.getValueFactory().createValue("a:b:c", PropertyType.BINARY);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Path and value is a BinaryValue" + "that is not convertible to a PathValue", nodeType.canSetProperty(propDef.getName(), noPathBinaryValue));
    Value dateValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DATE);
    assertFalse("canSetProperty(String propertyName, Value value) must return " + "false if the property is of type Path 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 Path 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 Path 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 Path and value is a BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValue));
    Value pathValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.NAME);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Path and value is a NameValue", nodeType.canSetProperty(propDef.getName(), pathValue));
    Value relPathValue = superuser.getValueFactory().createValue("abc", PropertyType.PATH);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Path and value is a PathValue", nodeType.canSetProperty(propDef.getName(), relPathValue));
    Value absPathValue = superuser.getValueFactory().createValue("/abc", PropertyType.PATH);
    assertTrue("canSetProperty(String propertyName, Value value) must return " + "true if the property is of type Path and value is a PathValue", nodeType.canSetProperty(propDef.getName(), absPathValue));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 32 with NodeType

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

the class CanSetPropertyPathTest method testConversionsMultiple.

/**
     * Tests if NodeType.canSetProperty(String propertyName, Value[] values)
     * returns true if all values and its types are convertible to PathValue.
     */
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.PATH, true, false, false, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple path property def that meets the " + "requirements of the test has been found");
    }
    NodeType nodeType = propDef.getDeclaringNodeType();
    Value pathValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.PATH);
    Value pathStringValue = superuser.getValueFactory().createValue("abc");
    Value[] pathStringValues = new Value[] { pathStringValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Path and values are of type StringValue " + "that are convertible to PathValues", nodeType.canSetProperty(propDef.getName(), pathStringValues));
    Value notPathStringValue = superuser.getValueFactory().createValue("a:b:c");
    Value[] notPathStringValues = new Value[] { pathValue, notPathStringValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type StringValue " + "that are not convertible to PathValues ", nodeType.canSetProperty(propDef.getName(), notPathStringValues));
    Value pathBinaryValue = superuser.getValueFactory().createValue("abc", PropertyType.BINARY);
    Value[] pathBinaryValues = new Value[] { pathBinaryValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Path and values are of type BinaryValue " + "that are convertible to PathValues", nodeType.canSetProperty(propDef.getName(), pathBinaryValues));
    Value notPathBinaryValue = superuser.getValueFactory().createValue("a:b:c", PropertyType.BINARY);
    Value[] notPathBinaryValues = new Value[] { pathValue, notPathBinaryValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type BinaryValue " + "that are not convertible to PathValues", nodeType.canSetProperty(propDef.getName(), notPathBinaryValues));
    Value dateValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DATE);
    Value[] dateValues = new Value[] { pathValue, dateValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
    Value doubleValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DOUBLE);
    Value[] doubleValues = new Value[] { pathValue, doubleValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
    Value longValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG);
    Value[] longValues = new Value[] { pathValue, longValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
    Value booleanValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BOOLEAN);
    Value[] booleanValues = new Value[] { booleanValue };
    assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Path and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
    Value nameValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.NAME);
    Value[] nameValues = new Value[] { nameValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Path and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
    Value[] pathValues = new Value[] { pathValue, pathValue };
    assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Path 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 33 with NodeType

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

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

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

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