use of javax.jcr.ReferentialIntegrityException in project jackrabbit-oak by apache.
the class ReferencesTest method testRecreateWithDifferentUUID.
public void testRecreateWithDifferentUUID() throws RepositoryException {
Node ref = testRootNode.addNode(nodeName1, testNodeType);
ref.addMixin(mixReferenceable);
superuser.save();
String uuid = ref.getIdentifier();
Node n1 = testRootNode.addNode(nodeName2, testNodeType);
n1.setProperty("ref", ref);
assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
superuser.save();
// recreate
ref.remove();
ref = testRootNode.addNode(nodeName1, testNodeType);
ref.addMixin(mixReferenceable);
assertFalse(uuid.equals(ref.getIdentifier()));
try {
superuser.save();
fail("must fail with ReferentialIntegrityException");
} catch (ReferentialIntegrityException e) {
// expected
}
}
use of javax.jcr.ReferentialIntegrityException in project jackrabbit-oak by apache.
the class ReferencesTest method testRemoveReferenced3.
public void testRemoveReferenced3() throws RepositoryException {
Node ref = testRootNode.addNode(nodeName1, testNodeType);
ref.addMixin(mixReferenceable);
superuser.save();
Node n1 = testRootNode.addNode(nodeName2, testNodeType);
n1.setProperty("ref", ref);
assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
superuser.save();
Node n2 = testRootNode.addNode(nodeName3, testNodeType);
n2.setProperty("ref", ref);
assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
ref.remove();
n1.remove();
try {
superuser.save();
fail("must fail with ReferentialIntegrityException");
} catch (ReferentialIntegrityException e) {
// expected
}
}
use of javax.jcr.ReferentialIntegrityException in project jackrabbit-oak by apache.
the class VersionTest method testRemoveVersion.
// OAK-3130
public void testRemoveVersion() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
superuser.save();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
vMgr.checkin(n.getPath());
Version v = vMgr.getBaseVersion(n.getPath());
try {
v.getContainingHistory().removeVersion(v.getName());
fail("removeVersion() must fail with ReferentialIntegrityException");
} catch (ReferentialIntegrityException e) {
// expected
}
vMgr.checkout(n.getPath());
v = vMgr.getBaseVersion(n.getPath());
try {
v.getContainingHistory().removeVersion(v.getName());
fail("removeVersion() must fail with ReferentialIntegrityException");
} catch (ReferentialIntegrityException e) {
// expected
}
}
use of javax.jcr.ReferentialIntegrityException in project jackrabbit by apache.
the class CheckinRemoveVersionTest method testCheckinRemoveVersionWithXA.
public void testCheckinRemoveVersionWithXA() throws Exception {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
UserTransactionImpl tx = new UserTransactionImpl(superuser);
tx.begin();
try {
Version v10 = n.checkin();
assertTrue("Version.getReferences() must return base version", v10.getReferences().hasNext());
try {
n.getVersionHistory().removeVersion(v10.getName());
fail("VersionHistory.removeVersion() must throw ReferentialIntegrityException when" + " version is still referenced.");
} catch (ReferentialIntegrityException e) {
// expected
}
} finally {
tx.rollback();
}
}
use of javax.jcr.ReferentialIntegrityException in project jackrabbit by apache.
the class NodeUUIDTest method testSaveReferentialIntegrityException.
/**
* Tries to remove a node that is a reference target using {@link
* Node#save()}.<br> <br>Procedure: <ul> <li>Creates two nodes with same
* session</li> <li>One has a referencing property pointing to the other
* node</li> <li>Target node gets removed.</li> </ul> This should
* generate a {@link javax.jcr.ReferentialIntegrityException} upon save.
* <br><br>Prerequisites: <ul> <li><code>javax.jcr.tck.NodeUUIDTest.nodetype</code>
* must allow a property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
* <li><code>javax.jcr.tck.NodeUUIDTest.propertyname1</code> name of the
* property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
* <li><code>javax.jcr.tck.NodeUUIDTest.nodetype2</code> must have the mixin
* type <code>mix:referenceable</code> assigned.</li> </ul>
*/
public void testSaveReferentialIntegrityException() throws RepositoryException, NotExecutableException {
checkMixReferenceable();
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create a node with a property of type PropertyType.REFERENCE
Node referencingNode = defaultRootNode.addNode(nodeName1, testNodeType);
// create a node with a jcr:uuid property to serve as target
Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
// make sure, mix:referenceable is effective. some impls may require a save() call.
defaultRootNode.save();
// abort test if the repository does not allow setting
// reference properties on this node
ensureCanSetProperty(referencingNode, propertyName1, referencingNode.getSession().getValueFactory().createValue(refTargetNode));
// set the reference
referencingNode.setProperty(propertyName1, refTargetNode);
// save the new nodes
defaultRootNode.save();
// remove the referenced node
refTargetNode.remove();
// try to save
try {
defaultRootNode.save();
fail("Saving a deleted node using Node.save() that is a reference target should throw ReferentialIntegrityException");
} catch (ReferentialIntegrityException e) {
// ok, works as expected
}
}
Aggregations