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));
}
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));
}
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));
}
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));
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CanSetPropertyBinaryTest method testConversionsMultiple.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value[] values)
* returns true if all values and its types are convertible to BinaryValue.
*/
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BINARY, true, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No multiple string property def that meets the " + "requirements of the test has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
Value[] stringValues = new Value[] { stringValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type StringValue", nodeType.canSetProperty(propDef.getName(), stringValues));
Value[] binaryValues = new Value[] { binaryValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BinaryValue", nodeType.canSetProperty(propDef.getName(), binaryValues));
Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
Value[] dateValues = new Value[] { dateValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
Value[] doubleValues = new Value[] { doubleValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
Value[] longValues = new Value[] { longValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
Value[] booleanValues = new Value[] { booleanValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
Value[] nameValues = new Value[] { nameValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
Value[] pathValues = new Value[] { pathValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Binary and values are of type PathValue", nodeType.canSetProperty(propDef.getName(), pathValues));
}
Aggregations