Search in sources :

Example 6 with VersionException

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

the class HoldTest method testAddHoldOnCheckedInNode.

public void testAddHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    child.checkin();
    // get another session.
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.addHold(child.getPath(), getHoldName(), false);
        otherS.save();
        fail("Adding hold on a checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear holds (in case of test failure)
        child.checkout();
        Hold[] holds = retentionMgr.getHolds(child.getPath());
        for (int i = 0; i < holds.length; i++) {
            retentionMgr.removeHold(child.getPath(), holds[i]);
        }
        superuser.save();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) Hold(javax.jcr.retention.Hold) VersionException(javax.jcr.version.VersionException)

Example 7 with VersionException

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

the class OnParentVersionAbortTest method testRestorePropJcr2.

/**
     * Test the restore of a OnParentVersion-ABORT property
     *
     * @throws javax.jcr.RepositoryException
     */
public void testRestorePropJcr2() throws RepositoryException {
    try {
        VersionManager versionManager = p.getSession().getWorkspace().getVersionManager();
        String path = p.getParent().getPath();
        versionManager.checkout(path);
        versionManager.checkin(path);
        fail("On checkin of N which has a property with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown.");
    } catch (VersionException e) {
    // success
    }
}
Also used : VersionManager(javax.jcr.version.VersionManager) VersionException(javax.jcr.version.VersionException)

Example 8 with VersionException

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

the class VersionLabelTest method testGetVersionLabelsForInvalidVersion.

/**
     * Test if versionHistory.getVersionLabels(Version) throws a VersionException if the
     * specified version is not in this version history.
     */
public void testGetVersionLabelsForInvalidVersion() throws Exception {
    // build a second versionable node below the testroot to get it's version.
    Node versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
    Version invalidV = versionableNode2.checkin();
    try {
        vHistory.getVersionLabels(invalidV);
        fail("VersionHistory.getVersionLabels(Version) must throw a VersionException if the specified version is not in this version history");
    } catch (VersionException ve) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 9 with VersionException

use of javax.jcr.version.VersionException 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 10 with VersionException

use of javax.jcr.version.VersionException 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)

Aggregations

VersionException (javax.jcr.version.VersionException)78 Node (javax.jcr.Node)25 Version (javax.jcr.version.Version)25 RepositoryException (javax.jcr.RepositoryException)19 Name (org.apache.jackrabbit.spi.Name)8 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 Property (javax.jcr.Property)6 Session (javax.jcr.Session)6 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)6 VersionIterator (javax.jcr.version.VersionIterator)5 VersionManager (javax.jcr.version.VersionManager)5 NodeId (org.apache.jackrabbit.core.id.NodeId)5 Nonnull (javax.annotation.Nonnull)4 ItemExistsException (javax.jcr.ItemExistsException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 RetentionManager (javax.jcr.retention.RetentionManager)4 LabelExistsVersionException (javax.jcr.version.LabelExistsVersionException)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4