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 SetValueConstraintViolationExceptionTest method testMultipleLongProperty.
/**
* Tests if setValue(Value[] values) where values are of type LongValue
* throw a ConstraintViolationException if the change would violate a value
* constraint
*/
public void testMultipleLongProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.LONG, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple long 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 long 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.");
}
// test of signature setValue(Value value)
try {
prop.setValue(new Value[] { valueNotSatisfied });
node.save();
fail("setValue(Value value) 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 SetValueConstraintViolationExceptionTest method testMultipleBinaryProperty.
/**
* Tests if setValue(Value[] values) where values are of type BinaryValue
* throw a ConstraintViolationException if the change would violate a value
* constraint
*/
public void testMultipleBinaryProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BINARY, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple binary 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 binary 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 ShareableNodeTest method testRemoveMixinFromSharedNode.
/**
* Remove mix:shareable from a shareable node that has 2 nodes in the shared set.
*/
public void testRemoveMixinFromSharedNode() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.getSession().save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
Node[] shared = getSharedSet(b1);
assertEquals(2, shared.length);
b1 = shared[0];
Node b2 = shared[1];
assertTrue(b2.isSame(b1));
// (per Section 14.15 of JSR-283 specification)
try {
// remove mixin
b1.removeMixin(mixShareable);
b1.getSession().save();
// If this happens, then b1 shouldn't be shareable anymore
// ...
assertFalse(b1.isNodeType(mixShareable));
assertFalse(b2.isSame(b1));
} catch (ConstraintViolationException e) {
// one possible outcome if removing 'mix:shareable' isn't supported
} catch (UnsupportedRepositoryOperationException e) {
// also possible if the implementation doesn't support this
// capability
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class ShareableNodeTest method testRemoveSharedSetSaveOneParentOnly.
/**
* Invoke Node.removeSharedSet(), but save only one of the parent nodes
* of the shared set. This doesn't need to be supported according to the
* specification (6.13.4).
*/
public void testRemoveSharedSetSaveOneParentOnly() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
// remove shared set
b1.removeSharedSet();
try {
// save only one of the parents, should fail
a1.save();
fail("Removing a shared set requires saving all parents.");
} catch (ConstraintViolationException e) {
// expected
}
}
Aggregations