Search in sources :

Example 31 with Version

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

the class VersionLabelTest method testAddDuplicateVersionLabel.

/**
     * Test if VersionHistory.addVersionLabel(versionName, label, moveLabel)
     * throws VersionException the label already exists and if moveLabel is false)
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testAddDuplicateVersionLabel() throws RepositoryException {
    vHistory.addVersionLabel(version.getName(), versionLabel, false);
    try {
        versionableNode.checkout();
        Version v = versionableNode.checkin();
        vHistory.addVersionLabel(v.getName(), versionLabel, false);
        fail("Adding a version label that already exist in the version history must throw a VersionException.");
    } catch (VersionException e) {
    //success
    }
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 32 with Version

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

the class VersionLabelTest method testGetVersionLabelsForVersion.

/**
     * Test VersionHistory.getVersionLabels(Version) only returns all labels present
     * for the specified version.
     *
     * @throws RepositoryException
     * @see VersionHistory#getVersionLabels(javax.jcr.version.Version)
     */
@SuppressWarnings("deprecation")
public void testGetVersionLabelsForVersion() throws RepositoryException {
    Set<String> testLabels = new HashSet<String>(Arrays.asList(vHistory.getVersionLabels(version)));
    vHistory.addVersionLabel(version.getName(), versionLabel, false);
    testLabels.add(versionLabel);
    // add a version label to another version (not added to the testLabel set)
    versionableNode.checkout();
    Version v = versionableNode.checkin();
    vHistory.addVersionLabel(v.getName(), versionLabel2, false);
    String[] labels = vHistory.getVersionLabels(version);
    for (int i = 0; i < labels.length; i++) {
        String l = labels[i];
        if (!testLabels.contains(l)) {
            fail("VersionHistory.getVersionLabels(Version) must only return labels, that have been added for this version.");
        }
        testLabels.remove(l);
    }
    assertTrue("VersionHistory.getVersionLabels(Version)  must return all labels, that have been added for this version.", testLabels.isEmpty());
}
Also used : Version(javax.jcr.version.Version) HashSet(java.util.HashSet)

Example 33 with Version

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

the class RestoreTest method testRestoreSetsBaseVersionJcr2_4.

/**
     * Test if restoring a node sets the jcr:baseVersion property correctly.
     *
     * @throws javax.jcr.RepositoryException
     */
public void testRestoreSetsBaseVersionJcr2_4() throws RepositoryException {
    versionManager.restore(new Version[] { version }, true);
    Version baseV = versionManager.getBaseVersion(versionableNode.getPath());
    assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV));
}
Also used : Version(javax.jcr.version.Version)

Example 34 with Version

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

the class RestoreTest method testRestoreInvalidVersion2Jcr2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionManager.restore(versionableNode.getPath(), invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 35 with Version

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

the class RestoreTest method testRestoreSetsBaseVersion.

/**
     * Test if restoring a node sets the jcr:baseVersion property correctly.
     *
     * @throws javax.jcr.RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreSetsBaseVersion() throws RepositoryException {
    versionableNode.restore(version, true);
    Version baseV = versionableNode.getBaseVersion();
    assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV));
}
Also used : Version(javax.jcr.version.Version)

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