Search in sources :

Example 66 with VersionHistory

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

the class CopyVersionHistoryTest method assertVersionablePaths.

private static void assertVersionablePaths(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 Node node = session.getNode(path);
            assertTrue("Node " + path + " should have mix:versionable mixin", node.isNodeType(MIX_VERSIONABLE));
            final VersionHistory history = getVersionHistoryForPath(session, path);
            assertVersionablePath(history, path);
        }
    }
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 67 with VersionHistory

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

the class CopyVersionHistoryTest method assertVersionsCanBeRestored.

private static void assertVersionsCanBeRestored(final Session session, final String... names) throws RepositoryException {
    VersionManager vMgr = session.getWorkspace().getVersionManager();
    for (final String mixin : MIXINS) {
        final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
        for (final String name : names) {
            final String path = pathPrefix + name;
            VersionHistory history = vMgr.getVersionHistory(path);
            assertEquals("1.2", session.getNode(path).getProperty("version").getString());
            vMgr.restore(history.getVersion("1.0"), false);
            Node versionable = session.getNode(path);
            assertEquals("1.0", versionable.getProperty("version").getString());
            // restored node should have correct properties
            String versionHistoryUuid = versionable.getProperty(JCR_VERSIONHISTORY).getString();
            assertEquals(history.getIdentifier(), versionHistoryUuid);
            final Version baseVersion = vMgr.getBaseVersion(path);
            assertEquals("1.0", baseVersion.getName());
            final Value[] predecessors = versionable.getProperty(JCR_PREDECESSORS).getValues();
            assertEquals(0, predecessors.length);
            assertFalse(vMgr.isCheckedOut(path));
        }
    }
    // after restoring, the paths should be still versionable
    assertVersionablePaths(session, names);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 68 with VersionHistory

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

the class RepositorySidegradeTest method verifyVersionHistory.

@Test
public void verifyVersionHistory() throws RepositoryException {
    Session session = createAdminSession();
    try {
        assertTrue(session.nodeExists("/versionable"));
        Node versionable = session.getNode("/versionable");
        assertTrue(versionable.hasNode("child"));
        Node child = versionable.getNode("child");
        assertTrue(child.hasNode("child2"));
        Node child2 = child.getNode("child2");
        assertFalse(versionable.isCheckedOut());
        assertTrue(versionable.hasProperty(JCR_UUID));
        assertFalse(child.isCheckedOut());
        assertTrue(child.hasProperty(JCR_UUID));
        assertFalse(child2.isCheckedOut());
        assertFalse(child2.hasProperty(JCR_UUID));
        VersionManager manager = session.getWorkspace().getVersionManager();
        Version version = manager.getBaseVersion("/versionable");
        Node frozen = version.getFrozenNode();
        assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
        assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild = frozen.getNode("child");
        assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild2 = frozenChild.getNode("child2");
        assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
        VersionHistory history = manager.getVersionHistory("/versionable");
        assertTrue(history.isNodeType("rep:VersionablePaths"));
        Property versionablePath = history.getProperty("default");
        assertEquals("/versionable", versionablePath.getString());
    } finally {
        session.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 69 with VersionHistory

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

the class RepositoryUpgradeTest method verifyVersionHistory.

@Test
public void verifyVersionHistory() throws RepositoryException {
    Session session = createAdminSession();
    try {
        assertTrue(session.nodeExists("/versionable"));
        Node versionable = session.getNode("/versionable");
        assertTrue(versionable.hasNode("child"));
        Node child = versionable.getNode("child");
        assertTrue(child.hasNode("child2"));
        Node child2 = child.getNode("child2");
        assertFalse(versionable.isCheckedOut());
        assertTrue(versionable.hasProperty(JCR_UUID));
        assertFalse(child.isCheckedOut());
        assertTrue(child.hasProperty(JCR_UUID));
        assertFalse(child2.isCheckedOut());
        assertFalse(child2.hasProperty(JCR_UUID));
        VersionManager manager = session.getWorkspace().getVersionManager();
        Version version = manager.getBaseVersion("/versionable");
        Node frozen = version.getFrozenNode();
        assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
        assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild = frozen.getNode("child");
        assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild2 = frozenChild.getNode("child2");
        assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
        VersionHistory history = manager.getVersionHistory("/versionable");
        assertTrue(history.isNodeType("rep:VersionablePaths"));
        Property versionablePath = history.getProperty("default");
        assertEquals("/versionable", versionablePath.getString());
    } finally {
        session.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 70 with VersionHistory

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

the class VersionCopyTestUtils method createLabeledVersions.

public static String createLabeledVersions(Node node) throws RepositoryException, InterruptedException {
    final Session session = node.getSession();
    final VersionManager versionManager = session.getWorkspace().getVersionManager();
    node.setProperty("version", "root");
    session.save();
    final String path = node.getPath();
    final List<String> versionNames = new ArrayList<String>();
    for (final String label : LABELS) {
        node.setProperty("version", label);
        session.save();
        final Version v = versionManager.checkpoint(path);
        versionNames.add(v.getName());
    }
    final VersionHistory history = versionManager.getVersionHistory(path);
    for (final String versionName : versionNames) {
        history.addVersionLabel(versionName, String.format("version %s", versionName), false);
    }
    return history.getPath();
}
Also used : Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)73 Node (javax.jcr.Node)45 Version (javax.jcr.version.Version)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)17 VersionManager (javax.jcr.version.VersionManager)17 Session (javax.jcr.Session)12 VersionIterator (javax.jcr.version.VersionIterator)12 Property (javax.jcr.Property)7 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)4 Workspace (javax.jcr.Workspace)3 VersionException (javax.jcr.version.VersionException)3 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)3 PathNotFoundException (javax.jcr.PathNotFoundException)2