use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SessionTest method testSaveConstraintViolationException.
/**
* Tries to create and save a node using {@link javax.jcr.Session#save()}
* with an mandatory property that is not set on saving time.
* <p>
* Prerequisites: <ul> <li><code>javax.jcr.tck.SessionTest.testSaveConstraintViolationException.nodetype2</code>
* must reference a nodetype that has one at least one property that is
* mandatory but not autocreated</li> </ul>
*/
public void testSaveConstraintViolationException() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create a node with at least one mandatory, not autocreated property
defaultRootNode.addNode(nodeName1, getProperty("nodetype2"));
// save changes
try {
superuser.save();
fail("Trying to use Session.save() with a node that has a mandatory property not set, should throw ConstraintViolationException");
} catch (ConstraintViolationException e) {
// ok
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class SetPropertyConstraintViolationExceptionTest method testBinaryProperty.
/**
* Tests if setProperty(String name, InputStream value) and
* setProperty(String name, Value value) where value is a BinaryValue throw
* a ConstraintViolationException either immediately (by setProperty()), or
* on save, if the change would violate a node type constraint
*/
public void testBinaryProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BINARY, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
}
// find a Value that does not satisfy the ValueConstraints of propDef
Value valueNotSatisfied1 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
Value valueNotSatisfied2 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (valueNotSatisfied1 == null || valueNotSatisfied2 == null) {
throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
Node node;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
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 setProperty(String name, InputStream value)
InputStream in = valueNotSatisfied1.getStream();
try {
node.setProperty(propDef.getName(), in);
node.save();
fail("setProperty(String name, InputStream value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
// test of signature setProperty(String name, Value value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied2);
node.save();
fail("setProperty(String name, 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 SetPropertyConstraintViolationExceptionTest method testDateProperty.
/**
* Tests if setProperty(String name, Calendar value) and setProperty(String
* name, Value value) where value is a DateValue throw a
* ConstraintViolationException either immediately (by setProperty()), or on
* save, if the change would violate a node type constraint
*/
public void testDateProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.DATE, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No date 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 date property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
Node node;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
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 setProperty(String name, Calendar value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied.getDate());
node.save();
fail("setProperty(String name, Calendar value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
// test of signature setProperty(String name, Value value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied);
node.save();
fail("setProperty(String name, 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 SetPropertyConstraintViolationExceptionTest method testLongProperty.
/**
* Tests if setProperty(String name, long value) and setProperty(String
* name, Value value) where value is a LongValue throw a
* ConstraintViolationException either immediately (by setProperty()), or on
* save, if the change would violate a node type constraint
*/
public void testLongProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.LONG, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No 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 long property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
Node node;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
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 setProperty(String name, long value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied.getLong());
node.save();
fail("setProperty(String name, long value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
// test of signature setProperty(String name, Value value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied);
node.save();
fail("setProperty(String name, 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 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