use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class WorkspaceMoveVersionableTest method testMoveNodesVersionableAndCheckedIn.
/**
* A VersionException is thrown if the parent node of destAbsPath is
* versionable and checked-in, or is non-versionable but its nearest
* versionable ancestor is checked-in.
*/
public void testMoveNodesVersionableAndCheckedIn() throws RepositoryException, NotExecutableException {
// prepare the test data
// create a non-versionable node below a versionable node
// required for having a nearest versionable ancestor to a nonversionable sub node
String dstAbsPath = node1.getPath() + "/" + node2.getName();
workspace.copy(node2.getPath(), dstAbsPath);
try {
// make parent node versionable and check-in
addMixinVersionableToNode(testRootNode, node1);
node1.checkin();
} catch (ConstraintViolationException ex) {
throw new NotExecutableException("server does not support making the parent versionable: " + ex.getMessage());
}
// 1. parent node of destAbsPath is non-versionable but its nearest versionable ancestor is checked-in
try {
workspace.move(node2.getPath(), dstAbsPath + "/" + node2.getName());
fail("Copying a node to a node's versionable and checked-in nearest ancestor node of destAbsPath should throw VersionException.");
} catch (VersionException e) {
// successful
}
// 2. parent node of destAbsPath is versionable and checked-in
try {
workspace.move(node2.getPath(), node1.getPath() + "/" + node2.getName());
fail("Copying a node to a versionable and checked-in parent node of destAbsPath should throw VersionException.");
} catch (VersionException e) {
// successful
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class BatchedItemOperations method verifyCheckedOut.
//----------------------------------------------------< protected methods >
/**
* Verifies that the node at <code>nodePath</code> is checked-out; throws a
* <code>VersionException</code> if that's not the case.
* <p>
* A node is considered <i>checked-out</i> if it is versionable and
* checked-out, or is non-versionable but its nearest versionable ancestor
* is checked-out, or is non-versionable and there are no versionable
* ancestors.
*
* @param nodePath
* @throws PathNotFoundException
* @throws VersionException
* @throws RepositoryException
*/
protected void verifyCheckedOut(Path nodePath) throws PathNotFoundException, VersionException, RepositoryException {
// search nearest ancestor that is versionable, start with node at nodePath
/**
* FIXME should not only rely on existence of jcr:isCheckedOut property
* but also verify that node.isNodeType("mix:versionable")==true;
* this would have a negative impact on performance though...
*/
NodeState nodeState = getNodeState(nodePath);
while (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
if (nodePath.denotesRoot()) {
return;
}
nodePath = nodePath.getAncestor(1);
nodeState = getNodeState(nodePath);
}
PropertyId propId = new PropertyId(nodeState.getNodeId(), NameConstants.JCR_ISCHECKEDOUT);
PropertyState propState;
try {
propState = (PropertyState) stateMgr.getItemState(propId);
} catch (ItemStateException ise) {
String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(propId);
log.debug(msg);
throw new RepositoryException(msg, ise);
}
boolean checkedOut = propState.getValues()[0].getBoolean();
if (!checkedOut) {
throw new VersionException(safeGetJCRPath(nodePath) + " is checked-in");
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class XATest method testSetVersionLabel.
/**
* Test new version label becomes available to other sessions on commit.
*/
public void testSetVersionLabel() throws Exception {
final String versionLabel = "myVersion";
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser);
// add node and save
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
testRootNode.save();
// reference node in other session
Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
// create another version
Version v = n.checkin();
// start transaction
utx.begin();
// add new version label
n.getVersionHistory().addVersionLabel(v.getName(), versionLabel, false);
// assert: version label unknown in other session
try {
nOther.getVersionHistory().getVersionByLabel(versionLabel);
fail("Version label visible outside tx.");
} catch (VersionException e) {
// expected
}
// commit
utx.commit();
// assert: version label known in other session
nOther.getVersionHistory().getVersionByLabel(versionLabel);
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class XATest method testCheckin.
//-----------------------------------------------------------< versioning >
/**
* Checkin inside tx should not be visible to other users.
*/
public void testCheckin() throws Exception {
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser);
// add node and save
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
testRootNode.save();
// reference node in other session
Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
// start transaction
utx.begin();
// checkin node
n.checkin();
// assert: base versions must differ
if (n.getBaseVersion().getName().equals(nOther.getBaseVersion().getName())) {
fail("Base versions must differ");
}
// assert: version must not be visible to other session
try {
nOther.getVersionHistory().getVersion(n.getBaseVersion().getName());
fail("Version must not be visible to other session.");
} catch (VersionException e) {
// expected.
}
// commit
utx.commit();
// assert: base versions must be equal
assertEquals("Base versions must be equal", n.getBaseVersion().getName(), nOther.getBaseVersion().getName());
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class SessionRemoveItemTest method testRemoveCheckedInItem.
public void testRemoveCheckedInItem() throws RepositoryException, NotExecutableException {
// add a child property and a child node to test deep lock effect.
Node childN = removeNode.addNode(nodeName2);
Value v = getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE2, RepositoryStub.PROP_PROP_TYPE2, "propvalue2");
Property childP = removeNode.setProperty(propertyName2, v);
removeNode.save();
ensureMixinType(removeNode, mixVersionable);
removeNode.save();
removeNode.checkin();
try {
adminSession.removeItem(childP.getPath());
adminSession.save();
fail("child property of a checked-in node cannot be removed.");
} catch (VersionException e) {
// success
}
try {
adminSession.removeItem(childN.getPath());
adminSession.save();
fail("child node of a checked-in node cannot be removed.");
} catch (VersionException e) {
// success
}
}
Aggregations