Search in sources :

Example 1 with VersionHistory

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

the class BackwardsCompatibilityIT method assertVersionable.

@SuppressWarnings("deprecation")
private Node assertVersionable(Node test) throws RepositoryException {
    assertTrue(test.hasNode("versionable"));
    Node versionable = test.getNode("versionable");
    assertTrue(versionable.isNodeType("nt:myversionable"));
    assertTrue(versionable.isNodeType("nt:unstructured"));
    assertTrue(versionable.isNodeType("mix:versionable"));
    assertFalse(versionable.isCheckedOut());
    VersionHistory history = versionable.getVersionHistory();
    Version versionB = versionable.getBaseVersion();
    String[] labels = history.getVersionLabels(versionB);
    assertEquals(1, labels.length);
    assertEquals("labelB", labels[0]);
    Version versionA = history.getVersionByLabel("labelA");
    versionable.restore(versionA, true);
    assertEquals("A", versionable.getProperty("foo").getString());
    versionable.restore(versionB, true);
    assertEquals("B", versionable.getProperty("foo").getString());
    return versionable;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 2 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class ReferencesTest method testVersionReferencesVH.

public void testVersionReferencesVH() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    VersionHistory vh = vMgr.getVersionHistory(p);
    // check if versionable node has references to root version
    assertEquals("Version History", vh.getIdentifier(), n.getProperty(Property.JCR_VERSION_HISTORY).getString());
    checkReferences("Version History", vh.getReferences(), p + "/jcr:versionHistory");
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 3 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class CopyVersionHistoryTest method assertExistingHistories.

private static void assertExistingHistories(final Session session, final String... names) throws RepositoryException {
    for (final String mixin : MIXINS) {
        final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
        for (final String name : names) {
            final String path = pathPrefix + name;
            final VersionHistory history = getVersionHistoryForPath(session, path);
            assertNotNull("No history found for " + path, history);
            VersionCopyTestUtils.assertLabeledVersions(history);
        }
    }
}
Also used : VersionHistory(javax.jcr.version.VersionHistory)

Example 4 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class CopyTest method testCopyVersionableNodeCreatesJcrCopiedFrom.

@Test
public void testCopyVersionableNodeCreatesJcrCopiedFrom() throws Exception {
    Session session = getAdminSession();
    Node toCopy = session.getNode(TEST_PATH + "/source/node");
    toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
    session.save();
    Version baseV = toCopy.getBaseVersion();
    session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
    Node copy = testNode.getNode("target/copied");
    VersionHistory copiedVh = copy.getVersionHistory();
    assertTrue(copiedVh.hasProperty(VersionConstants.JCR_COPIED_FROM));
    Property prop = copiedVh.getProperty(VersionConstants.JCR_COPIED_FROM);
    assertEquals(PropertyType.WEAKREFERENCE, prop.getType());
    Node copiedFrom = prop.getNode();
    assertTrue(baseV.isSame(copiedFrom));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 5 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class CopyTest method testCopyVersionableNodeClearsVersions.

@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
    Session session = getAdminSession();
    Node toCopy = session.getNode(TEST_PATH + "/source/node");
    toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
    session.save();
    Version v1 = toCopy.checkin();
    toCopy.checkout();
    Version v2 = toCopy.checkin();
    toCopy.checkout();
    session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
    Node copy = testNode.getNode("target/copied");
    VersionHistory vh = copy.getVersionHistory();
    Version rootV = vh.getRootVersion();
    assertEquals(0, rootV.getSuccessors().length);
    VersionIterator vItr = vh.getAllVersions();
    while (vItr.hasNext()) {
        if (!rootV.isSame(vItr.nextVersion())) {
            fail("Unexpected version in version history of copied node.");
        }
    }
    try {
        vh.getVersion(v1.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
    try {
        vh.getVersion(v2.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException) Test(org.junit.Test)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)88 Node (javax.jcr.Node)58 Version (javax.jcr.version.Version)42 Test (org.junit.Test)30 VersionManager (javax.jcr.version.VersionManager)25 RepositoryException (javax.jcr.RepositoryException)24 VersionIterator (javax.jcr.version.VersionIterator)22 Session (javax.jcr.Session)18 Property (javax.jcr.Property)11 ArrayList (java.util.ArrayList)8 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 Workspace (javax.jcr.Workspace)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 NodeIterator (javax.jcr.NodeIterator)4 Value (javax.jcr.Value)4 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)4 NodeType (javax.jcr.nodetype.NodeType)3