Search in sources :

Example 16 with VersionException

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

the class RestoreTest method testRestoreWithInvalidVersion.

/**
     * Test if restoring a node with an invalid Version throws a VersionException
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreWithInvalidVersion() throws RepositoryException {
    Version invalidVersion = versionableNode2.checkin();
    try {
        versionableNode.restore(invalidVersion, true);
        fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 17 with VersionException

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

the class SetValueVersionExceptionTest method testInputStream.

/**
     * Tests if setValue(InputStream) throws a VersionException immediately
     * or on save if the parent node of this property is checked-in.
     */
public void testInputStream() throws RepositoryException {
    try {
        byte[] bytes = { 123 };
        InputStream value = new ByteArrayInputStream(bytes);
        property.setValue(value);
        node.save();
        fail("Property.setValue(InputStream) must throw a VersionException " + "immediately or on save if the parent node of this property " + "is checked-in.");
    } catch (VersionException e) {
    // success
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VersionException(javax.jcr.version.VersionException)

Example 18 with VersionException

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

the class RetentionPolicyTest method testRemoveRetentionPolicyOnCheckedInNode.

public void testRemoveRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    retentionMgr.setRetentionPolicy(child.getPath(), getApplicableRetentionPolicy());
    superuser.save();
    child.checkin();
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.removeRetentionPolicy(child.getPath());
        otherS.save();
        fail("Removing a retention policy on a checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear policy added before
        child.checkout();
        try {
            retentionMgr.removeRetentionPolicy(child.getPath());
            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) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException)

Example 19 with VersionException

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

the class SaveTest method testVersionException.

/**
     * Tests if a {@link javax.jcr.version.VersionException} is thrown when a
     * query is stored under a checked in node.
     * <p>
     * The tests creates a node under <code>testRoot</code> with name
     * <code>nodeName1</code> and adds a mix:versionable mixin if the node is
     * not already versionable.
     * Then the test tries to store a query as <code>nodeName2</code> under node
     * <code>nodeName1</code>.
     * @throws NotExecutableException if nt:query is not supported.
     */
public void testVersionException() throws RepositoryException, NotExecutableException {
    checkNtQuery();
    // check if repository supports versioning
    if (!isSupported(Repository.OPTION_VERSIONING_SUPPORTED)) {
        throw new NotExecutableException();
    }
    Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
    // create a node that is versionable
    Node versionable = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it versionable if it is not
    ensureMixinType(versionable, mixVersionable);
    testRootNode.getSession().save();
    versionable.checkin();
    try {
        query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
        fail("Query.storeAsNode() must throw VersionException, parent node is checked in.");
    } catch (VersionException e) {
    // expected behaviour
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Query(javax.jcr.query.Query) Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 20 with VersionException

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

the class VersionHistoryImpl method getVersionByLabel.

/**
     *
     * @param qLabel
     * @return
     * @throws VersionException
     * @throws RepositoryException
     */
private Version getVersionByLabel(Name qLabel) throws VersionException, RepositoryException {
    refreshEntry(labelNodeEntry);
    // retrieve reference property value -> and retrieve referenced node
    PropertyEntry pEntry = labelNodeEntry.getPropertyEntry(qLabel, true);
    if (pEntry == null) {
        throw new VersionException("Version with label '" + qLabel + "' does not exist.");
    }
    Node version = ((Property) getItemManager().getItem(pEntry)).getNode();
    return (Version) version;
}
Also used : Version(javax.jcr.version.Version) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) Node(javax.jcr.Node) Property(javax.jcr.Property) 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