Search in sources :

Example 86 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckoutTest method testIsCheckedOutNonVersionableNodeJcr2.

/**
     * Test calling VersionManager.isCheckedOut(P) with P denoting the
     * absolute path of a non-versionable node.
     */
public void testIsCheckedOutNonVersionableNodeJcr2() throws RepositoryException {
    VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager();
    String path = nonVersionableNode.getPath();
    boolean isCheckedOut = versionManager.isCheckedOut(path);
    Node vParent = null;
    try {
        vParent = nonVersionableNode.getParent();
        while (!vParent.isNodeType(mixVersionable)) {
            vParent = vParent.getParent();
        }
    } catch (ItemNotFoundException e) {
    // root reached.
    }
    if (vParent != null && vParent.isNodeType(mixVersionable)) {
        String parentPath = vParent.getPath();
        if (versionManager.isCheckedOut(parentPath)) {
            assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-out.", isCheckedOut);
        } else {
            assertFalse("VersionManager.isCheckedOut(P) must return false if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-in.", isCheckedOut);
        }
    } else {
        assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node that has no versionable ancestor", isCheckedOut);
    }
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 87 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    versionManager.checkout(path);
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Example 88 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method testCheckinWithPendingChangesJcr2.

/**
     * Test if VersionManager.checkin(P) throws InvalidItemStateException if
     * the path P resolves to a node that has unsaved changes pending.
     *
     * @throws RepositoryException
     */
public void testCheckinWithPendingChangesJcr2() throws RepositoryException {
    try {
        // modify node without calling save()
        versionableNode.setProperty(propertyName1, propertyValue);
        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
        String path = versionableNode.getPath();
        versionManager.checkin(path);
        fail("InvalidItemStateException must be thrown on attempt to checkin a node having any unsaved changes pending.");
    } catch (InvalidItemStateException e) {
    // ok
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) VersionManager(javax.jcr.version.VersionManager)

Example 89 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method testPredecessorIsCopiedToNewVersionJcr2.

/**
     * Test if the nodes jcr:predecessors property is copied to the new version
     * on checkin.
     *
     * @throws RepositoryException
     */
public void testPredecessorIsCopiedToNewVersionJcr2() throws RepositoryException {
    Value[] nPredecessorsValue = versionableNode.getProperty(jcrPredecessors).getValues();
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    Version v = versionManager.checkin(path);
    Value[] vPredecessorsValue = v.getProperty(jcrPredecessors).getValues();
    assertEquals("The versionable checked-out node's jcr:predecessors property is copied to the new version on checkin.", Arrays.asList(nPredecessorsValue), Arrays.asList(vPredecessorsValue));
}
Also used : Version(javax.jcr.version.Version) Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager)

Example 90 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method testCheckinRemovesPredecessorPropertyJcr2.

/**
     * Test if the node's jcr:predecessors property contains an empty value array
     * after checkin.
     *
     * @throws RepositoryException
     */
public void testCheckinRemovesPredecessorPropertyJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    versionManager.checkin(path);
    Value[] predecessorsValue = versionableNode.getProperty(jcrPredecessors).getValues();
    assertTrue("Checkin must set the node's jcr:predecessors property to the empty array", predecessorsValue.length == 0);
}
Also used : Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2