Search in sources :

Example 21 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 = versionManager.checkin(child1.getPath());
    // V1 of versionable node has child1
    String v1 = versionManager.checkin(versionableNode.getPath()).getName();
    // create V1.1 of child
    versionManager.checkout(child1.getPath());
    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());
    // JSR283 is more clear about restoring versionable OPV=VERSION nodes
    // and states that an existing one is not restored when the parent
    // is restored (see 15.7.5 Chained Versions on Restore)
    // New JSR283 version:
    // restore V2 via name. child should still be be 1.0
    versionManager.restore(versionableNode.getPath(), v2, true);
    child1 = versionableNode.getNode(nodeName4);
    assertEquals("Node.restore('foo') must not restore child node and keep version 1.0.", v1Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName());
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 22 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 23 with Version

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

the class RestoreTest method testRestoreWithUUIDConflictJcr2_2.

/**
     * 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_2() 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(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) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 24 with Version

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

the class RemoveVersionTest method testRemoveAllBut2.

/**
     * Checks if all versions but the base and root one can be removed.
     */
public void testRemoveAllBut2() throws RepositoryException {
    String baseVersion = versionableNode.getBaseVersion().getName();
    VersionHistory vh = versionableNode.getVersionHistory();
    VersionIterator vi = vh.getAllVersions();
    while (vi.hasNext()) {
        Version currenVersion = vi.nextVersion();
        String versionName = currenVersion.getName();
        if (!versionName.equals("jcr:rootVersion") && !versionName.equals(baseVersion)) {
            vh.removeVersion(versionName);
        }
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory)

Example 25 with Version

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

the class RestoreTest method testRestoreChild1Jcr2_2.

public void testRestoreChild1Jcr2_2() throws RepositoryException {
    versionableNode.addNode("child1");
    versionableNode.getSession().save();
    Version v1 = versionManager.checkin(versionableNode.getPath());
    versionManager.checkout(versionableNode.getPath());
    Version v2 = versionManager.checkin(versionableNode.getPath());
    versionManager.restore(v1, true);
    assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
    versionManager.restore(version, true);
    assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
    try {
        versionManager.restore(v2, true);
    } catch (RepositoryException e) {
        fail("Node.restore('1.3') must fail.");
    }
}
Also used : Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

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