*/
public void testReferenceProperty()
throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef =
NodeTypeUtil.locatePropertyDef(superuser, PropertyType.REFERENCE, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No reference property def with " +
"testable value constraints has been found");
}
String constraints[] = propDef.getValueConstraints();
String nodeTypeSatisfied = constraints[0];
String nodeTypeNotSatisfied = null;
NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator types = manager.getAllNodeTypes();
// find a NodeType which is not satisfying the constraints
findNodeTypeNotSatisfied:
while (types.hasNext()) {
NodeType type = types.nextNodeType();
String name = type.getName();
for (int i = 0; i < constraints.length; i++) {
if (name.equals(constraints[i])) {
continue findNodeTypeNotSatisfied;
}
nodeTypeNotSatisfied = name;
break findNodeTypeNotSatisfied;
}
}
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);
nodeSatisfied.addMixin(mixReferenceable);
// create a referenceable node not satisfying the constraint
nodeNotSatisfied = testRootNode.addNode(nodeName4, nodeTypeNotSatisfied);
nodeNotSatisfied.addMixin(mixReferenceable);
prop = node.setProperty(propDef.getName(), nodeSatisfied);
testRootNode.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.");
}