Search in sources :

Example 56 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class RestoreTest method testRestoreChild1Jcr2_2.

public void testRestoreChild1Jcr2_2() throws RepositoryException {
    versionableNode.addNode("child1");
    versionableNode.getSession().save();
    Version v1 = versionManager.checkin(versionableNode.getPath());
    versionManager.checkout(versionableNode.getPath());
    Version v2 = versionManager.checkin(versionableNode.getPath());
    versionManager.restore(v1, true);
    assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
    versionManager.restore(version, true);
    assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
    try {
        versionManager.restore(v2, true);
    } catch (RepositoryException e) {
        fail("Node.restore('1.3') must fail.");
    }
}
Also used : Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

Example 57 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class RestoreTest method testRestoreChild1Jcr2_3.

public void testRestoreChild1Jcr2_3() throws RepositoryException {
    versionableNode.addNode("child1");
    versionableNode.getSession().save();
    Version v1 = versionManager.checkin(versionableNode.getPath());
    versionManager.checkout(versionableNode.getPath());
    Version v2 = versionManager.checkin(versionableNode.getPath());
    versionManager.restore(versionableNode.getPath(), v1.getName(), true);
    assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
    versionManager.restore(versionableNode.getPath(), version.getName(), true);
    assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
    try {
        versionManager.restore(versionableNode.getPath(), v2.getName(), true);
    } catch (RepositoryException e) {
        fail("Node.restore('1.3') must fail.");
    }
}
Also used : Version(javax.jcr.version.Version) RepositoryException(javax.jcr.RepositoryException)

Example 58 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class UpdateTest method testPendingChangesOnOtherNode.

public void testPendingChangesOnOtherNode() throws RepositoryException, NotExecutableException {
    try {
        Node root = testRootNode.getSession().getRootNode();
        if (root.isSame(testRootNode)) {
            throw new NotExecutableException();
        }
        if (root.canAddMixin(mixLockable)) {
            root.addMixin(mixLockable);
        } else {
            root.setProperty(propertyName1, "anyValue");
        }
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    String srcWorkspace = getAnotherWorkspace();
    try {
        testRootNode.update(srcWorkspace);
        fail("Update while changes are pending must fail with InvalidItemStateException");
    } catch (InvalidItemStateException e) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 59 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class WorkspaceMoveTest method testMovePropertyExists.

/**
     * Tries to move a node using to a location where a property already exists
     * with same name.
     * <br/> <br/>
     * With JCR 1.0 this should throw an <code>{@link javax.jcr.ItemExistsException}</code>.
     * With JCR 2.0 the support for same-named property and node is optional and
     * the expected behaviour depends on the
     * {@link Repository#OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED} descriptor.
     */
@Override
public void testMovePropertyExists() throws RepositoryException, NotExecutableException {
    // try to create a property with the name of the node to be moved
    // to the destination parent
    Property destProperty;
    try {
        destProperty = destParentNode.setProperty(nodeName2, "anyString");
        destParentNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException("Cannot create property with name '" + nodeName2 + "' and value 'anyString' at move destination.");
    }
    // TODO: fix 2.0 behaviour according to the OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED descriptor
    if ("1.0".equals(getHelper().getRepository().getDescriptor(Repository.SPEC_VERSION_DESC))) {
        try {
            // move the node
            doMove(moveNode.getPath(), destProperty.getPath());
            fail("Moving a node to a location where a property exists must throw ItemExistsException");
        } catch (ItemExistsException e) {
        // ok, works as expected
        }
    } else {
        // JCR 2.0 move the node: same name property and node must be supported
        doMove(moveNode.getPath(), destProperty.getPath());
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 60 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class AddMixinTest method testImplicitMixinOnNewNode.

/**
     * Implementation specific test adding a new Node with a nodeType, that has
     * a mixin-supertype. The mixin must only take effect upon save.
     *
     * @throws NotExecutableException
     * @throws RepositoryException
     */
public void testImplicitMixinOnNewNode() throws NotExecutableException, RepositoryException {
    Node newNode;
    try {
        String ntResource = superuser.getNamespacePrefix(NS_NT_URI) + ":resource";
        newNode = testRootNode.addNode(nodeName1, ntResource);
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    assertFalse("Implict Mixin inherited by primary Nodetype must not be active before Node has been saved.", newNode.isNodeType(mixReferenceable));
    NodeType[] mixins = newNode.getMixinNodeTypes();
    for (int i = 0; i < mixins.length; i++) {
        if (mixins[i].getName().equals(testNodeType)) {
            fail("Implict Mixin inherited by primary Nodetype must not be active before Node has been saved.");
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50