Search in sources :

Example 31 with Value

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);
    }
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager) Property(javax.jcr.Property)

Example 32 with Value

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);
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 33 with Value

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);
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager) Property(javax.jcr.Property)

Example 34 with Value

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);
}
Also used : Version(javax.jcr.version.Version) Value(javax.jcr.Value)

Example 35 with Value

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");
    }
}
Also used : Value(javax.jcr.Value)

Aggregations

Value (javax.jcr.Value)602 Node (javax.jcr.Node)158 Test (org.junit.Test)120 Property (javax.jcr.Property)99 RepositoryException (javax.jcr.RepositoryException)82 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)70 Session (javax.jcr.Session)63 NodeType (javax.jcr.nodetype.NodeType)57 ValueFormatException (javax.jcr.ValueFormatException)53 ValueFactory (javax.jcr.ValueFactory)51 QValue (org.apache.jackrabbit.spi.QValue)51 HashMap (java.util.HashMap)46 ArrayList (java.util.ArrayList)31 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)30 Privilege (javax.jcr.security.Privilege)30 InputStream (java.io.InputStream)29 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)29 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)27