Search in sources :

Example 56 with Version

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

the class WorkspaceRestoreTest method testWorkspaceRestoreWithRemoveExistingJcr2.

/**
     * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
     */
public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
    // create version for parentNode of childNode
    superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
    Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
    // move child node in order to produce the uuid conflict
    String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
    wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
    wSuperuser.save();
    // restore the parent with removeExisting == true >> moved child node
    // must be removed.
    wSuperuser.getWorkspace().getVersionManager().restore(new Version[] { parentV }, true);
    if (wSuperuser.itemExists(newChildPath)) {
        fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
    }
}
Also used : Version(javax.jcr.version.Version)

Example 57 with Version

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

the class WorkspaceRestoreTest method testWorkspaceRestoreWithUUIDConflict.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException {
    try {
        // Verify that nodes used for the test are indeed versionable
        NodeDefinition nd = wVersionableNode.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Nodes must be versionable in order to run this test.");
        }
        Version v = wVersionableNode.checkin();
        wVersionableNode.checkout();
        wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName());
        wSuperuser.save();
        wSuperuser.getWorkspace().restore(new Version[] { v }, false);
        fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
    } catch (ItemExistsException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 58 with Version

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

the class WorkspaceRestoreTest method testWorkspaceRestoreWithPendingChanges.

/**
     * Test if InvalidItemStateException is thrown if the session affected by
     * Workspace.restore(Version[], boolean) has pending changes.
     */
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithPendingChanges() throws RepositoryException {
    versionableNode.checkout();
    try {
        // modify node without calling save()
        versionableNode.setProperty(propertyName1, propertyValue);
        // create version in second workspace
        Version v = wVersionableNode.checkin();
        // try to restore that version
        superuser.getWorkspace().restore(new Version[] { v }, false);
        fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
    } catch (InvalidItemStateException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Example 59 with Version

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

the class RestoreTest method testRestoreOrderJcr2_4.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrderJcr2_4() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // remove node 1
    versionManager.checkout(testRoot.getPath());
    child1.remove();
    testRoot.getSession().save();
    versionManager.checkout(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(new Version[] { v1 }, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 60 with Version

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

the class RestoreTest method testRestoreOrderJcr2_2.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrderJcr2_2() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // remove node 1
    versionManager.checkout(testRoot.getPath());
    child1.remove();
    testRoot.getSession().save();
    versionManager.checkout(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(v1, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Aggregations

Version (javax.jcr.version.Version)265 Node (javax.jcr.Node)155 VersionManager (javax.jcr.version.VersionManager)65 RepositoryException (javax.jcr.RepositoryException)45 VersionHistory (javax.jcr.version.VersionHistory)29 VersionException (javax.jcr.version.VersionException)25 NodeIterator (javax.jcr.NodeIterator)23 Session (javax.jcr.Session)19 Test (org.junit.Test)19 Property (javax.jcr.Property)16 VersionIterator (javax.jcr.version.VersionIterator)16 Value (javax.jcr.Value)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)14 ItemExistsException (javax.jcr.ItemExistsException)13 HashSet (java.util.HashSet)12 NodeDefinition (javax.jcr.nodetype.NodeDefinition)12 ArrayList (java.util.ArrayList)11 Set (java.util.Set)7 DavException (org.apache.jackrabbit.webdav.DavException)7 UserTransaction (javax.transaction.UserTransaction)6