Search in sources :

Example 46 with VersionException

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

the class SerializationTest method doTestVersioningExceptionFileChild.

public void doTestVersioningExceptionFileChild(boolean useWorkspace, boolean useHandler) throws Exception {
    Node n = initVersioningException(false);
    FileInputStream in = new FileInputStream(file);
    try {
        doImport(n.getPath(), in, useWorkspace, useHandler);
        fail("Importing to a child of a checked-in node must throw a ConstraintViolationException.");
    } catch (VersionException e) {
    // success
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
}
Also used : Node(javax.jcr.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VersionException(javax.jcr.version.VersionException)

Example 47 with VersionException

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

the class SerializationTest method doTestVersioningExceptionFileParent.

public void doTestVersioningExceptionFileParent(boolean useWorkspace, boolean useHandler) throws Exception {
    Node n = initVersioningException(true);
    FileInputStream in = new FileInputStream(file);
    try {
        doImport(n.getPath(), in, useWorkspace, useHandler);
        fail("Importing to a checked-in node must throw a ConstraintViolationException.");
    } catch (VersionException e) {
    // success
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
}
Also used : Node(javax.jcr.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VersionException(javax.jcr.version.VersionException)

Example 48 with VersionException

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

the class HoldTest method testRemoveHoldOnCheckedInNode.

public void testRemoveHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node vn = getVersionableChildNode();
    vn.checkout();
    Node n = vn.addNode(nodeName2);
    Hold h = retentionMgr.addHold(n.getPath(), getHoldName(), false);
    superuser.save();
    // checkin on the parent node make the hold-containing node checked-in.
    vn.checkin();
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        Hold[] holds = rmgr.getHolds(n.getPath());
        if (holds.length > 0) {
            rmgr.removeHold(n.getPath(), holds[0]);
            otherS.save();
            fail("Removing a hold on a checked-in node must throw VersionException.");
        }
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear hold added before
        vn.checkout();
        try {
            retentionMgr.removeHold(n.getPath(), h);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold) VersionException(javax.jcr.version.VersionException)

Example 49 with VersionException

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

the class RetentionPolicyTest method testSetRetentionPolicyOnCheckedInNode.

public void testSetRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    child.checkin();
    String childPath = child.getPath();
    // get another session.
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
        otherS.save();
        fail("Setting a retention policy on a checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear policies (in case of test failure)
        try {
            retentionMgr.removeRetentionPolicy(childPath);
            superuser.save();
        } catch (RepositoryException e) {
        // ignore.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException)

Example 50 with VersionException

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

the class RemoveVersionTest method testRemoveInvalidVersion.

/**
     * Test if removing a version from the version history throws a VersionException
     * if the specified version does not exist.
     *
     * @throws RepositoryException
     * @throws NotExecutableException
     */
public void testRemoveInvalidVersion() throws RepositoryException, NotExecutableException {
    Version invalidV = versionableNode2.checkin();
    String invalidName = invalidV.getName();
    // build a version name that is not present in the current history
    boolean found = false;
    for (int i = 0; i < 10 && !found; i++) {
        try {
            vHistory.getVersion(invalidName);
            invalidName += i;
        } catch (VersionException e) {
            // ok > found a name that is invalid.
            found = true;
        }
    }
    if (!found) {
        throw new NotExecutableException("Failed to create an invalid name in order to test the removal of versions.");
    }
    try {
        vHistory.removeVersion(invalidName);
        fail("Removing a version that does not exist must fail with a VersionException.");
    } catch (VersionException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) 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