use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class WorkspaceCopyVersionableTest method testCopyNodesVersionableAndCheckedIn.
/**
* 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 testCopyNodesVersionableAndCheckedIn() 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.copy(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.copy(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 MergeNodeTest method disable_testMergeNodeForceFailure.
/**
* if mergeFailedProperty is present > VersionException<br>
*/
@SuppressWarnings("deprecation")
public void disable_testMergeNodeForceFailure() throws RepositoryException {
// create 2 independent versions for a node and its corresponding node
// so merge fails for this node
// default workspace
Node originalNode = testRootNode.getNode(nodeName1);
originalNode.checkout();
originalNode.checkin();
// second workspace
nodeToMerge.checkin();
// "merge" the clonedNode with the newNode from the default workspace
// besteffort set to true to report all failures
nodeToMerge.checkout();
nodeToMerge.merge(workspace.getName(), true);
try {
nodeToMerge.merge(workspace.getName(), true);
fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty is present, merge must throw a VersionException");
} catch (VersionException e) {
// success version exception expected
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class MergeNodeTest method disable_testMergeNodeForceFailureJcr2.
/**
* if mergeFailedProperty is present > VersionException<br>
*/
public void disable_testMergeNodeForceFailureJcr2() throws RepositoryException {
// create 2 independent versions for a node and its corresponding node
// so merge fails for this node
// default workspace
Node originalNode = testRootNode.getNode(nodeName1);
VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
String originalPath = originalNode.getPath();
vmWsp1.checkout(originalPath);
vmWsp1.checkin(originalPath);
// second workspace
VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
String path = nodeToMerge.getPath();
vmWsp2.checkin(path);
// "merge" the clonedNode with the newNode from the default workspace
// besteffort set to true to report all failures
vmWsp2.checkout(path);
vmWsp2.merge(path, workspace.getName(), true);
try {
vmWsp2.merge(path, workspace.getName(), true);
fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty is present, merge must throw a VersionException");
} catch (VersionException e) {
// success version exception expected
}
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class NodeImpl method internalSetProperty.
private Property internalSetProperty(final String jcrName, final Value[] values, final int type, final boolean exactTypeMatch) throws RepositoryException {
final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
final PropertyState state = createMultiState(oakName, compact(values), Type.fromTag(type, true));
if (values.length > MV_PROPERTY_WARN_THRESHOLD) {
LOG.warn("Large multi valued property [{}/{}] detected ({} values).", dlg.getPath(), jcrName, values.length);
}
return perform(new ItemWriteOperation<Property>("internalSetProperty") {
@Override
public void checkPreconditions() throws RepositoryException {
super.checkPreconditions();
if (!isCheckedOut() && getOPV(dlg.getTree(), state) != OnParentVersionAction.IGNORE) {
throw new VersionException(format("Cannot set property. Node [%s] is checked in.", getNodePath()));
}
}
@Nonnull
@Override
public Property perform() throws RepositoryException {
return new PropertyImpl(dlg.setProperty(state, exactTypeMatch, false), sessionContext);
}
@Override
public String toString() {
return format("Setting property [%s/%s]", dlg.getPath(), jcrName);
}
});
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeClearsVersions.
@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version v1 = toCopy.checkin();
toCopy.checkout();
Version v2 = toCopy.checkin();
toCopy.checkout();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory vh = copy.getVersionHistory();
Version rootV = vh.getRootVersion();
assertEquals(0, rootV.getSuccessors().length);
VersionIterator vItr = vh.getAllVersions();
while (vItr.hasNext()) {
if (!rootV.isSame(vItr.nextVersion())) {
fail("Unexpected version in version history of copied node.");
}
}
try {
vh.getVersion(v1.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
try {
vh.getVersion(v2.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
}
Aggregations