use of javax.jcr.Value in project jackrabbit by apache.
the class MergeNodeTest method testMergeNodeBestEffortTrueCheckMergeFailedPropertyJcr2.
/**
* VersionManager.merge(): bestEffort is true > any merge-failure (represented by the
* version in the workspace) is reported in the jcrMergeFailed property<br>
*/
public void testMergeNodeBestEffortTrueCheckMergeFailedPropertyJcr2() 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);
// success merge exception was raised as expected
// jcrMergeFailed should contains reference to the V' as it is a different branche
String expectedReferenceUUID = originalNode.getBaseVersion().getUUID();
Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
Value[] references = mergeFailedProperty.getValues();
boolean referenceFound = false;
if (references != null) {
for (int i = 0; i < references.length; i++) {
String referenceUUID = references[i].getString();
if (referenceUUID.equals(expectedReferenceUUID)) {
referenceFound = true;
// it's not necessary to loop thru all the references
break;
}
}
assertTrue("reference to expected version that give the failure wasnt found in the mergeFailed", referenceFound);
}
}
use of javax.jcr.Value in project jackrabbit by apache.
the class MergeCancelMergeTest method testMergeNodeCancelMerge.
/**
* Merge.cancelMerge(V): has the effect of removing the reference to V' from
* the jcr:mergeFailed property of N. <br> without adding it to
* jcr:predecessors.<br> Branches will not be joined.<br>
*/
@SuppressWarnings("deprecation")
public void testMergeNodeCancelMerge() 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
nodeToMerge.checkout();
nodeToMerge.merge(workspace.getName(), true);
// get predecessors
Version[] predecessors = nodeToMerge.getBaseVersion().getPredecessors();
// get mergeFailed property
Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
Value[] mergeFailedReferences = mergeFailedProperty.getValues();
for (int i = 0; i < mergeFailedReferences.length; i++) {
String uuid = mergeFailedReferences[i].getString();
nodeToMerge.cancelMerge((Version) superuser.getNodeByUUID(uuid));
}
// check predecessors - unchanged
Version[] predecessorsAfterCancel = nodeToMerge.getBaseVersion().getPredecessors();
assertTrue(predecessors.length == predecessorsAfterCancel.length);
// check mergeFailed property - reference removed
if (nodeToMerge.hasProperty(jcrMergeFailed)) {
Property mergeFailedPropertyAfterCancelMerge = nodeToMerge.getProperty(jcrMergeFailed);
Value[] mergeFailedReferencesAfterCancelMerge = mergeFailedPropertyAfterCancelMerge.getValues();
assertTrue(mergeFailedReferences.length > mergeFailedReferencesAfterCancelMerge.length);
}
}
use of javax.jcr.Value in project jackrabbit by apache.
the class MergeCancelMergeTest method testMergeNodeCancelMergeJcr2.
/**
* Merge.cancelMerge(V): has the effect of removing the reference to V' from
* the jcr:mergeFailed property of N. <br> without adding it to
* jcr:predecessors.<br> Branches will not be joined.<br>
*/
public void testMergeNodeCancelMergeJcr2() 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
vmWsp2.checkout(path);
vmWsp2.merge(path, workspace.getName(), true);
// get predecessors
Version[] predecessors = vmWsp2.getBaseVersion(path).getPredecessors();
// get mergeFailed property
Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
Value[] mergeFailedReferences = mergeFailedProperty.getValues();
for (int i = 0; i < mergeFailedReferences.length; i++) {
String id = mergeFailedReferences[i].getString();
vmWsp2.cancelMerge(path, (Version) superuser.getNodeByIdentifier(id));
}
// check predecessors - unchanged
Version[] predecessorsAfterCancel = vmWsp2.getBaseVersion(path).getPredecessors();
assertTrue(predecessors.length == predecessorsAfterCancel.length);
// check mergeFailed property - reference removed
if (nodeToMerge.hasProperty(jcrMergeFailed)) {
Property mergeFailedPropertyAfterCancelMerge = nodeToMerge.getProperty(jcrMergeFailed);
Value[] mergeFailedReferencesAfterCancelMerge = mergeFailedPropertyAfterCancelMerge.getValues();
assertTrue(mergeFailedReferences.length > mergeFailedReferencesAfterCancelMerge.length);
}
}
use of javax.jcr.Value in project jackrabbit by apache.
the class CheckinTest method testBaseVersionAfterCheckin.
/**
* Test if versionable node N's jcr:baseVersion property is set to refer to
* the new version after checkin.
*
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testBaseVersionAfterCheckin() throws RepositoryException {
Version v = versionableNode.checkin();
Value baseVersionRef = versionableNode.getProperty(jcrBaseVersion).getValue();
assertEquals("Checked-in node's jcr:baseVersion property is set to refer to the version created on checkin.", superuser.getValueFactory().createValue(v), baseVersionRef);
}
use of javax.jcr.Value in project jackrabbit by apache.
the class CheckoutTest method testCheckoutCopiesBaseValueToPredecessorProperty.
/**
* Test if Node.checkout() copies the node's jcr:baseVersion to node's
* jcr:predecessors property (no save required).
*/
@SuppressWarnings("deprecation")
public void testCheckoutCopiesBaseValueToPredecessorProperty() throws RepositoryException {
Value baseVersionValue = versionableNode.getProperty(jcrBaseVersion).getValue();
versionableNode.checkout();
Value[] predecessorsValues = versionableNode.getProperty(jcrPredecessors).getValues();
// loop over all values of jcr:predecessors property as it's not sure
// on which position jcr:baseVersion is copied.
boolean foundBaseVersionProp = false;
int i = 0;
while (i < predecessorsValues.length && !foundBaseVersionProp) {
if (predecessorsValues[i].equals(baseVersionValue)) {
foundBaseVersionProp = true;
}
i++;
}
if (!foundBaseVersionProp) {
fail("After calling Node.checkout() the current value of node's jcr:baseVersion must be copied to node's jcr:predecessors property");
}
}
Aggregations