use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RestoreTest method testRestoreWithInvalidVersionJcr2.
/**
* Test if restoring a node with an invalid Version throws a VersionException
*
* @throws RepositoryException
*/
public void testRestoreWithInvalidVersionJcr2() throws RepositoryException {
Version invalidVersion = versionManager.checkin(versionableNode2.getPath());
try {
versionManager.restore(versionableNode.getPath(), invalidVersion, true);
fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
} catch (VersionException e) {
// success
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RestoreTest method testRestoreInvalidVersion2.
/**
* VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
String invalidName;
do {
invalidName = createRandomString(3);
for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
Version v = it.nextVersion();
if (invalidName.equals(v.getName())) {
invalidName = null;
break;
}
}
} while (invalidName == null);
try {
versionableNode.restore(invalidName, true);
fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
} catch (VersionException e) {
// ok
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RestoreTest method testRestoreWithInvalidVersion.
/**
* Test if restoring a node with an invalid Version throws a VersionException
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreWithInvalidVersion() throws RepositoryException {
Version invalidVersion = versionableNode2.checkin();
try {
versionableNode.restore(invalidVersion, true);
fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
} catch (VersionException e) {
// success
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class RestoreTest method testRestoreInvalidVersion.
/**
* VersionException expected on Node.restore(Version, boolean) if the
* specified version is not part of this node's version history.
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion() throws RepositoryException {
Version vNode2 = versionableNode2.checkin();
try {
versionableNode.restore(vNode2, true);
fail("VersionException expected on Node.restore(Version, boolean) if the specified version is not part of this node's version history.");
} catch (VersionException e) {
// ok
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class NodeImpl method restore.
/**
* Common internal restore method for the various Node#restore calls.
*
* @param targetNode
* @param relQPath
* @param version
* @param removeExisting
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws VersionException
* @throws ConstraintViolationException
* @throws UnsupportedRepositoryOperationException
* @throws LockException
* @throws InvalidItemStateException
* @throws RepositoryException
*/
private void restore(NodeImpl targetNode, Path relQPath, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
if (relQPath == null) {
/* restore target already exists. */
// target must be versionable
targetNode.checkIsVersionable();
VersionHistory vH = targetNode.getVersionHistory();
// version must be a version of the target node
if (!vH.isSame(version.getContainingHistory())) {
throw new VersionException("Version " + version + " does not correspond to the restore target.");
}
// version must not be the root version
if (vH.getRootVersion().isSame(version)) {
throw new VersionException("Attempt to restore root version.");
}
targetNode.checkIsWritable();
targetNode.checkIsLocked();
} else {
/* If no node exists at relPath then a VersionException is thrown if
the parent node is not checked out. */
if (!targetNode.isCheckedOut()) {
throw new VersionException("Parent " + targetNode.safeGetJCRPath() + " for non-existing restore target '" + LogUtil.safeGetJCRPath(relQPath, session.getPathResolver()) + "' must be checked out.");
}
targetNode.checkIsLocked();
// NOTE: check for nodetype constraint violation is left to the 'server'
}
NodeState versionState = session.getVersionState(version);
session.getVersionStateManager().restore(targetNode.getNodeState(), relQPath, versionState, removeExisting);
}
Aggregations