use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SetValueConstraintViolationExceptionTest method testMultipleBooleanProperty.
/**
* Tests if setValue(Value[] values) where values are of type BooleanValue
* throw a ConstraintViolationException if the change would violate a value
* constraint
*/
public void testMultipleBooleanProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BOOLEAN, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
}
// find a Value that does not satisfy the ValueConstraints of propDef
Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (valueNotSatisfied == null) {
throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
}
// find a Value that does satisfy the ValueConstraints of propDef
Value valueSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, true);
if (valueSatisfied == null) {
throw new NotExecutableException("The value constraints do not allow any value.");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
// and add a property with constraints to this node
Node node;
Property prop;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
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.");
}
try {
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.ConstraintViolationException in project jackrabbit by apache.
the class SetPropertyAssumeTypeTest method testValueConstraintViolationExceptionBecauseOfInvalidTypeParameter.
/**
* Tests if <code>Node.setProperty(String, Value, int)</code> throws a
* ConstraintViolationException if the type parameter and the type of the
* property do not match. The exception has to be thrown either immediately
* (by this method) or on save.
*/
public void testValueConstraintViolationExceptionBecauseOfInvalidTypeParameter() throws NotExecutableException, RepositoryException {
try {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(0));
Value v = superuser.getValueFactory().createValue(ISO8601.format(cal));
testNode.setProperty(propertyName1, v, PropertyType.DATE);
testRootNode.getSession().save();
fail("Node.setProperty(String, Value, int) must throw a " + "ConstraintViolationExcpetion if the type parameter and the " + "type of the property do not match.");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SetPropertyAssumeTypeTest method testStringConstraintViolationExceptionBecauseOfInvalidTypeParameter.
/**
* Tests if <code>Node.setProperty(String, String, int)</code> throws a
* ConstraintViolationException if the type parameter and the type of the
* property do not match. The exception has to be thrown either immediately
* (by this method) or on save.
*/
public void testStringConstraintViolationExceptionBecauseOfInvalidTypeParameter() throws NotExecutableException, RepositoryException {
try {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(0));
testNode.setProperty(propertyName1, ISO8601.format(cal), PropertyType.DATE);
testRootNode.getSession().save();
fail("Node.setProperty(String, Value, int) must throw a " + "ConstraintViolationExcpetion if the type parameter and the " + "type of the property do not match.");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SessionTest method testMoveConstraintViolationExceptionSrc.
/**
* Moves a node using {@link javax.jcr.Session#move(String src, String dest)},
* afterwards it tries to only save the old parent node.
* <p>
* This should throw {@link javax.jcr.nodetype.ConstraintViolationException}.
* <p>
* Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
* must accept children of same nodetype</li> </ul>
*/
public void testMoveConstraintViolationExceptionSrc() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create parent node
Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
// create node to be moved
Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
// create a node that will serve as new parent
Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
// save the new nodes
superuser.save();
// move the node
superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
// save only old parent node
try {
srcParentNode.save();
fail("Saving only the source parent node after a Session.move() operation must throw ConstraintViolationException");
} catch (ConstraintViolationException e) {
// ok both work as expected
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SessionTest method testMoveConstraintViolationExceptionDest.
/**
* Moves a node using {@link javax.jcr.Session#move(String src, String dest)},
* afterwards it tries to only save the destination parent
* node.
* <p>
* This should throw a {@link javax.jcr.nodetype.ConstraintViolationException}.
* <p>
* Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
* must accept children of same nodetype</li> </ul>
*/
public void testMoveConstraintViolationExceptionDest() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create parent node
Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
// create node to be moved
Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
// create a node that will serve as new parent
Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
// save the new nodes
superuser.save();
// move the node
superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
// save only moved node
try {
destParentNode.save();
fail("Saving only moved node after a Session.move() operation should throw ConstraintViolationException");
} catch (ConstraintViolationException e) {
// ok try to save the source
}
}
Aggregations