use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanSetPropertyLongTest 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.LONG, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple long property def with " + "testable value constraints has been found");
}
Value value = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (value == null) {
throw new NotExecutableException("No multiple long 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.NodeType in project jackrabbit by apache.
the class CanSetPropertyLongTest method testConversionsMultiple.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value[] values)
* returns true if all values and its types are convertible to LongValue.
*/
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG, true, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No multiple long property def that meets the " + "requirements of the test has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value longValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG);
Value anyStringValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.STRING);
Value[] anyStringValues = new Value[] { longValue, anyStringValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type StringValue " + "that are not convertible to LongValues", nodeType.canSetProperty(propDef.getName(), anyStringValues));
Value longStringValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG).getString());
Value[] longStringValues = new Value[] { longStringValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type StringValue " + "that are convertible to LongValues", nodeType.canSetProperty(propDef.getName(), longStringValues));
Value anyBinaryValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BINARY);
Value[] anyBinaryValues = new Value[] { longValue, anyBinaryValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type BinaryValue " + "that are not convertible to LongValues", nodeType.canSetProperty(propDef.getName(), anyBinaryValues));
Value longBinaryValue = superuser.getValueFactory().createValue(NodeTypeUtil.getValueOfType(superuser, PropertyType.LONG).getString(), PropertyType.BINARY);
Value[] longBinaryValues = new Value[] { longBinaryValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type BinaryValue " + "that are convertible to LongValues", nodeType.canSetProperty(propDef.getName(), longBinaryValues));
Value dateValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DATE);
Value[] dateValues = new Value[] { dateValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
Value doubleValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.DOUBLE);
Value[] doubleValues = new Value[] { doubleValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
Value[] longValues = new Value[] { longValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Long and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
Value booleanValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.BOOLEAN);
Value[] booleanValues = new Value[] { longValue, booleanValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
Value nameValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.NAME);
Value[] nameValues = new Value[] { longValue, nameValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
Value pathValue = NodeTypeUtil.getValueOfType(superuser, PropertyType.PATH);
Value[] pathValues = new Value[] { longValue, pathValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Long and values are of type PathValue", nodeType.canSetProperty(propDef.getName(), pathValues));
}
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));
}
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));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class PredefinedNodeTypeTest method getChildNodeDefSpec.
/**
* Creates and returns a spec string for the given node definition.
* The returned spec string follows the child node definition format
* used in the JSR 170 specification.
*
* @param node child node definition
* @return spec string
*/
private static String getChildNodeDefSpec(NodeDefinition node) {
StringWriter buffer = new StringWriter();
PrintWriter writer = new PrintWriter(buffer);
writer.println("ChildNodeDefinition");
if (node.getName().equals("*")) {
writer.println(" Name \"*\"");
} else {
writer.println(" Name " + node.getName());
}
writer.print(" RequiredPrimaryTypes [");
NodeType[] types = node.getRequiredPrimaryTypes();
Arrays.sort(types, NODE_TYPE_COMPARATOR);
for (int j = 0; j < types.length; j++) {
if (j > 0) {
writer.print(',');
}
writer.print(types[j].getName());
}
writer.println("]");
if (node.getDefaultPrimaryType() != null) {
writer.println(" DefaultPrimaryType " + node.getDefaultPrimaryType().getName());
} else {
writer.println(" DefaultPrimaryType null");
}
writer.println(" AutoCreated " + node.isAutoCreated());
writer.println(" Mandatory " + node.isMandatory());
writer.println(" OnParentVersion " + OnParentVersionAction.nameFromValue(node.getOnParentVersion()));
writer.println(" Protected " + node.isProtected());
writer.println(" SameNameSiblings " + node.allowsSameNameSiblings());
return buffer.toString();
}
Aggregations