Search in sources :

Example 61 with Version

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

the class RestoreTest method testRestoreNameJcr2.

/**
     * Test the restore of the OPV=Version child nodes.
     * @throws RepositoryException
     */
public void testRestoreNameJcr2() throws RepositoryException, NotExecutableException {
    // V1.0 of versionableNode has no child
    Node child1 = versionableNode.addNode(nodeName4);
    ensureMixinType(child1, mixVersionable);
    versionableNode.getSession().save();
    // create v1.0 of child
    Version v1Child = child1.checkin();
    // V1 of versionable node has child1
    String v1 = versionManager.checkin(versionableNode.getPath()).getName();
    // create V1.1 of child
    versionManager.checkout(child1.getPath());
    Version v11Child = versionManager.checkin(child1.getPath());
    // V2 of versionable node has child1
    versionManager.checkout(versionableNode.getPath());
    String v2 = versionManager.checkin(versionableNode.getPath()).getName();
    // restore 1.0 of versionable node --> no child
    versionManager.restore(version, true);
    assertFalse("restore must remove child node.", versionableNode.hasNode(nodeName4));
    // restore V1 via name. since child was checkin first, 1.0 should be restored
    versionManager.restore(versionableNode.getPath(), v1, true);
    assertTrue("restore must restore child node.", versionableNode.hasNode(nodeName4));
    child1 = versionableNode.getNode(nodeName4);
    assertEquals("restore must restore child node version 1.0.", v1Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName());
    // restore V2 via name. child should be 1.1
    versionManager.restore(versionableNode.getPath(), v2, true);
    child1 = versionableNode.getNode(nodeName4);
    assertEquals("Node.restore('foo') must restore child node version 1.1.", v11Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName());
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 62 with Version

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

the class RestoreTest method testRestoreOrder2Jcr2_3.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrder2Jcr2_3() 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());
    // reoder nodes
    versionManager.checkout(testRoot.getPath());
    testRoot.orderBefore(nodeName2, nodeName1);
    testRoot.getSession().save();
    versionManager.checkin(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)

Example 63 with Version

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

the class CheckinTest method testMultipleCheckinHasNoEffectJcr2.

/**
     * Test if VersionManager.checkin(P) has no effect if the path P resolves
     * to a checked-in node.
     *
     * @throws RepositoryException
     */
public void testMultipleCheckinHasNoEffectJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    Version v = versionManager.checkin(path);
    try {
        Version v2 = versionManager.checkin(path);
        assertTrue("Calling VersionManager.checkin(P) must not have an if the path P resolves to a node that is already checked-in.", v.isSame(v2));
    } catch (RepositoryException e) {
        fail("Calling VersionManager.checkin(P) must not throw an exception if the path P resolves to a node that is already checked-in.");
    }
}
Also used : Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager)

Example 64 with Version

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

the class RestoreTest method testRestoreWithUUIDConflictJcr2_3.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException {
    try {
        Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
        // Verify that nodes used for the test have proper opv behaviour
        NodeDefinition nd = naa.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
        }
        Version v = versionManager.checkin(versionableNode.getPath());
        versionManager.checkout(versionableNode.getPath());
        superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
        superuser.save();
        versionManager.restore(versionableNode.getPath(), v.getName(), 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) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 65 with Version

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

the class RestoreTest method testRestoreOrder.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreOrder() 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();
    child1.checkin();
    child2.checkin();
    Version v1 = testRoot.checkin();
    // remove node 1
    testRoot.checkout();
    child1.remove();
    testRoot.getSession().save();
    testRoot.checkin();
    // restore version 1.0
    testRoot.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