Search in sources :

Example 41 with Version

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

the class RemoveOrphanVersionHistoryTest method testRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in a single workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    // Second version
    Version v11 = n.checkin();
    n.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    // Remove the second and last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 42 with Version

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

the class RemoveOrphanVersionHistoryTest method testEmptyNonOrphanVersionHistory.

/**
     * Test that an emptied version history that is still being referenced
     * from another workspace does not get removed.
     *
     * @throws RepositoryException if an error occurs.
     */
public void testEmptyNonOrphanVersionHistory() throws RepositoryException {
    Session session = testRootNode.getSession();
    // Create versionable test node
    Node node = testRootNode.addNode(nodeName1);
    node.addMixin(mixVersionable);
    session.save();
    VersionHistory history = node.getVersionHistory();
    String uuid = history.getUUID();
    // Create version 1.0
    Version v10 = node.checkin();
    // Remove the test node
    node.checkout();
    node.remove();
    session.save();
    Session otherSession = getHelper().getReadWriteSession(workspaceName);
    try {
        // create a reference to the version history in another workspace
        Node otherRoot = otherSession.getRootNode();
        Property reference = otherRoot.setProperty("RemoveOrphanVersionTest", uuid, PropertyType.REFERENCE);
        otherSession.save();
        // Now remove the contents of the version history
        history.removeVersion(v10.getName());
        // Check that the version history still exists!
        try {
            session.getNodeByUUID(uuid);
        } catch (ItemNotFoundException e) {
            fail("Referenced empty version history must note be removed");
        }
        // Cleanup
        reference.remove();
        otherSession.save();
    } finally {
        otherSession.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 43 with Version

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

the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in multiple workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    Workspace defaultWorkspace = n.getSession().getWorkspace();
    Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
    // Clone the node in another workspace
    otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
    Node otherWsRootNode = otherWsSession.getRootNode();
    Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
    // Ensure that version histories are the same
    assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
    Version v11 = clonedNode.checkin();
    clonedNode.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove cloned node
    clonedNode.remove();
    otherWsRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the default workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
    try {
        otherWsSession.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the other workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 44 with Version

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

the class RemoveVersionLabelTest method testRemoveVersionLabel.

public void testRemoveVersionLabel() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Version v10 = n.checkin();
    n.checkout();
    n.checkin();
    VersionHistory vh = n.getVersionHistory();
    vh.addVersionLabel(v10.getName(), "test", true);
    // the next call must not fail
    vh.removeVersion(v10.getName());
    // now the label must be gone
    String[] labels = vh.getVersionLabels();
    assertEquals("Label of a removed version must be removed as well", 0, labels.length);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 45 with Version

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

the class RestoreNodeWithSNSTest method testRestoreWithSNS.

public void testRestoreWithSNS() throws Exception {
    int childCount = 5;
    // create a test node with /childCount/ children with the same name
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    for (int i = 0; i < childCount; i++) {
        Node child = n.addNode(nodeName2);
        child.setProperty("name", nodeName2 + i);
    }
    testRootNode.getSession().save();
    // check the number of children
    assertEquals(childCount, n.getNodes().getSize());
    VersionManager vm = testRootNode.getSession().getWorkspace().getVersionManager();
    vm.checkin(n.getPath());
    // modify one child
    vm.checkout(n.getPath());
    n.getNode(nodeName2).setProperty("name", "modified");
    testRootNode.getSession().save();
    // check the number of children again
    assertEquals(childCount, n.getNodes().getSize());
    // restore base versiob
    Version baseVersion = vm.getBaseVersion(n.getPath());
    vm.restore(baseVersion, true);
    n.getSession().refresh(false);
    // check the number of children again
    assertEquals(childCount, n.getNodes().getSize());
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

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