Search in sources :

Example 96 with VersionManager

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

the class VersionLabelTest method testGetVersionLabelsJcr2.

/**
     * Test VersionHistory.getVersionLabels() returns all labels present on the version history.
     *
     * @throws RepositoryException
     * @see javax.jcr.version.VersionHistory#getVersionLabels()
     */
public void testGetVersionLabelsJcr2() throws RepositoryException {
    Set<String> testLabels = new HashSet<String>(Arrays.asList(vHistory.getVersionLabels()));
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    versionManager.checkout(path);
    Version v = versionManager.checkin(path);
    vHistory.addVersionLabel(v.getName(), versionLabel, false);
    testLabels.add(versionLabel);
    vHistory.addVersionLabel(version.getName(), versionLabel2, false);
    testLabels.add(versionLabel2);
    String[] labels = vHistory.getVersionLabels();
    for (int i = 0; i < labels.length; i++) {
        String l = labels[i];
        if (!testLabels.contains(l)) {
            fail("VersionHistory.getVersionLabels() must only return labels, that have been added to the history.");
        }
        testLabels.remove(l);
    }
    assertTrue("VersionHistory.getVersionLabels() must return all labels, that have been added to the history.", testLabels.isEmpty());
}
Also used : Version(javax.jcr.version.Version) VersionManager(javax.jcr.version.VersionManager) HashSet(java.util.HashSet)

Example 97 with VersionManager

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

the class FrozenNodeTest method testFrozenChildNodeType.

/**
     * @throws RepositoryException
     */
public void testFrozenChildNodeType() throws RepositoryException {
    Node n1 = versionableNode.addNode("child");
    versionableNode.getSession().save();
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    Version v = versionManager.checkin(path);
    Node n = v.getFrozenNode().getNode("child");
    String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString();
    String ruuid = n1.getPrimaryNodeType().getName();
    assertEquals("jcr:frozenPrimaryType needs to be equal to the getPrimaryNodeType() return value.", ruuid, fuuid);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 98 with VersionManager

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

the class VersionGraphTest method testInitialBaseVersionPointsToRootVersionJcr2.

/**
     * Test that the initial base version after creation of a versionable node
     * points to the root version.
     *
     * @throws javax.jcr.RepositoryException
     */
public void testInitialBaseVersionPointsToRootVersionJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    Version rV = versionManager.getVersionHistory(path).getRootVersion();
    Version bV = versionManager.getBaseVersion(path);
    assertTrue("After creation of a versionable node the node's baseVersion must point to the rootVersion in the version history.", rV.isSame(bV));
}
Also used : Version(javax.jcr.version.Version) VersionManager(javax.jcr.version.VersionManager)

Example 99 with VersionManager

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

the class VersionHistoryTest method testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion.

/**
     * Test if the iterator returned by {@link javax.jcr.version.VersionHistory#getAllLinearVersions()}
     * contains both the root and the base version upon creation of the version history.
     * @since JCR 2.0
     */
public void testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion() throws RepositoryException {
    VersionManager vm = versionableNode.getSession().getWorkspace().getVersionManager();
    List<String> lvh = new ArrayList<String>();
    for (VersionIterator it = vHistory.getAllLinearVersions(); it.hasNext(); ) {
        lvh.add(it.nextVersion().getName());
    }
    String rootVersion = vm.getVersionHistory(versionableNode.getPath()).getRootVersion().getName();
    String baseVersion = vm.getBaseVersion(versionableNode.getPath()).getName();
    assertTrue("root version " + rootVersion + " must be part of the linear version history: " + lvh, lvh.contains(rootVersion));
    assertTrue("base version " + baseVersion + " must be part of the linear version history: " + lvh, lvh.contains(baseVersion));
}
Also used : ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) VersionManager(javax.jcr.version.VersionManager)

Example 100 with VersionManager

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

the class WorkspaceRestoreTest method testWorkspaceRestoreOnCheckedInNodeJcr2.

/**
     * Test if workspace-restoring a node works on checked-in node.
     */
public void testWorkspaceRestoreOnCheckedInNodeJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    if (versionManager.isCheckedOut(path)) {
        versionManager.checkin(path);
    }
    superuser.getWorkspace().getVersionManager().restore(new Version[] { version }, true);
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2