use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class SetValueConstraintViolationExceptionTest method testMultipleReferenceProperty.
/**
* Tests if setValue(Value[] values) where values are of type ReferenceValue
* throw a ConstraintViolationException if the change would violate a value
* constraint
*/
public void testMultipleReferenceProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.REFERENCE, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple reference property def with " + "testable value constraints has been found");
}
String[] valueConstraints = propDef.getValueConstraints();
if (valueConstraints == null || valueConstraints.length == 0) {
throw new NotExecutableException("No reference property def with " + "testable value constraints has been found");
}
List<String> constraints = Arrays.asList(valueConstraints);
String nodeTypeSatisfied = constraints.get(0);
String nodeTypeNotSatisfied = null;
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator types = manager.getAllNodeTypes();
// find a NodeType which is not satisfying the constraints
while (types.hasNext()) {
NodeType type = types.nextNodeType();
String name = type.getName();
if (constraints.contains(name) || ntFrozenNode.equals(name)) {
continue;
}
if (type.getChildNodeDefinitions() != null && type.getChildNodeDefinitions().length > 0) {
continue;
}
nodeTypeNotSatisfied = name;
break;
}
if (nodeTypeNotSatisfied == null) {
throw new NotExecutableException("No reference property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
// and add a property with constraints to this node
Node node;
Property prop;
Node nodeSatisfied;
Node nodeNotSatisfied;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
// create a referenceable node satisfying the constraint
nodeSatisfied = testRootNode.addNode(nodeName3, nodeTypeSatisfied);
ensureMixinType(nodeSatisfied, mixReferenceable);
// create a referenceable node not satisfying the constraint
nodeNotSatisfied = testRootNode.addNode(nodeName4, nodeTypeNotSatisfied);
ensureMixinType(nodeNotSatisfied, mixReferenceable);
// some implementations may require a save after addMixin()
testRootNode.getSession().save();
Value valueSatisfied = superuser.getValueFactory().createValue(nodeSatisfied);
prop = node.setProperty(propDef.getName(), new Value[] { valueSatisfied });
testRootNode.getSession().save();
} catch (ConstraintViolationException e) {
// implementation specific constraints do not allow to set up test environment
throw new NotExecutableException("Not able to create required test items.");
}
// test of signature setValue(Value value)
try {
Value valueNotSatisfied = superuser.getValueFactory().createValue(nodeNotSatisfied);
prop.setValue(new Value[] { valueNotSatisfied });
node.save();
fail("setValue(Value[] values) must throw a ConstraintViolationException " + "if the change would violate a node type constraint " + "either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithoutNodeTypeTest method testResidualWithDefault.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
* true if <code>NodeType</code> contains a residual <code>NodeDef</code>
* with a default primary type.
*/
public void testResidualWithDefault() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, true, true);
if (nodeDef == null) {
throw new NotExecutableException("No residual child node def " + "without a defaultPrimaryType found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
assertTrue("NodeType.canAddChildNode(String childNodeName) must return " + "true for a not defined childNodeName if NodeType has a residual child node " + "definition with a defaultPrimaryType", nodeType.canAddChildNode(undefinedName));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithoutNodeTypeTest method testResidualWithoutDefault.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
* true if <code>NodeType</code> contains a residual <code>NodeDef</code>
* without a default primary type.
*/
public void testResidualWithoutDefault() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, true);
if (nodeDef == null) {
throw new NotExecutableException("No residual child node def " + "with a defaultPrimaryType found.");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
String undefinedName = NodeTypeUtil.getUndefinedChildNodeName(nodeType);
assertFalse("NodeType.canAddChildNode(String childNodeName) must return " + "false for a not defiend childNodeName if NodeType has a " + "residual child node definition without a defaultPrimaryType", nodeType.canAddChildNode(undefinedName));
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class CanAddChildNodeCallWithoutNodeTypeTest method testDefinedWithoutDefault.
/**
* Tests if <code>NodeType.canAddChildNode(String childNodeName)</code> returns
* true if <code>NodeType</code> contains a <code>NodeDef</code> named
* <code>childNodeName</code> without a default primary type.
*/
public void testDefinedWithoutDefault() throws NotExecutableException, RepositoryException {
NodeDefinition nodeDef = NodeTypeUtil.locateChildNodeDef(session, true, false, false);
if (nodeDef == null) {
throw new NotExecutableException("No child node def without " + "defaultPrimaryType found");
}
NodeType nodeType = nodeDef.getDeclaringNodeType();
assertFalse("NodeType.canAddChildNode(String childNodeName) must return false " + "if child node def 'childNodeName' does not define a defaultPrimaryType.", nodeType.canAddChildNode(nodeDef.getName()));
}
use of javax.jcr.nodetype.NodeType 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