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
}
}
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 VersionHistoryTest method testSetProperty.
/**
* Tests if <ul> <li><code>VersionHistory.setProperty(String,
* String[])</code></li> <li><code>VersionHistory.setProperty(String,
* String[], int)</code></li> <li><code>VersionHistory.setProperty(String,
* Value[])</code></li> <li><code>VersionHistory.setProperty(String,
* Value[], int)</code></li> <li><code>VersionHistory.setProperty(String,
* boolean)</code></li> <li><code>VersionHistory.setProperty(String,
* double)</code></li> <li><code>VersionHistory.setProperty(String,
* InputStream)</code></li> <li><code>VersionHistory.setProperty(String,
* String)</code></li> <li><code>VersionHistory.setProperty(String,
* Calendar)</code></li> <li><code>VersionHistory.setProperty(String,
* Node)</code></li> <li><code>VersionHistory.setProperty(String,
* Value)</code></li> <li><code>VersionHistory.setProperty(String,
* long)</code></li> </ul> all throw a {@link javax.jcr.nodetype.ConstraintViolationException}
*/
public void testSetProperty() throws Exception {
// create Value[] object
Value[] vArray = new Value[3];
vArray[0] = superuser.getValueFactory().createValue("abc");
vArray[1] = superuser.getValueFactory().createValue("xyz");
vArray[2] = superuser.getValueFactory().createValue("123");
// create String array
String[] s = { "abc", "xyz", "123" };
try {
vHistory.setProperty(propertyName1, s);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[]) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, s, PropertyType.STRING);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[],int) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, vArray);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[]) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, vArray, PropertyType.STRING);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[],int]) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, true);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,boolean) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, 123);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,double) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
byte[] bytes = { 73, 26, 32, -36, 40, -43, -124 };
InputStream inpStream = new ByteArrayInputStream(bytes);
vHistory.setProperty(propertyName1, inpStream);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,InputStream) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, "abc");
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
Calendar c = new GregorianCalendar(1945, 1, 6, 16, 20, 0);
vHistory.setProperty(propertyName1, c);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Calendar) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, vHistory);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Node) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
Value v = superuser.getValueFactory().createValue("abc");
vHistory.setProperty(propertyName1, v);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
try {
vHistory.setProperty(propertyName1, -2147483650L);
vHistory.getSession().save();
fail("VersionHistory should be read-only: VersionHistory.setProperty(String,long) did not throw a ConstraintViolationException");
} catch (ConstraintViolationException success) {
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin2.
public void testAddItemsDefinedByMixin2() throws NotExecutableException, RepositoryException {
// register mixin
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testMixin");
ntd.setMixin(true);
NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
nodeDef.setName("child");
nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
ntd.getNodeDefinitionTemplates().add(nodeDef);
ntm.registerNodeType(ntd, true);
// create node and add mixin
Node node = testRootNode.addNode(nodeName1, "nt:resource");
node.setProperty("jcr:data", "abc");
node.addMixin("testMixin");
superuser.save();
// node type
try {
node.addNode("child");
fail();
} catch (ConstraintViolationException e) {
// success as ChildNode Definition doesn't specify a default primary
// type -> see comment in ItemDefinitionProvider#getQNodeDefinition
}
}
Aggregations