Search in sources :

Example 16 with InvalidItemStateException

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

the class ConcurrentAddRemoveMoveTest method testRemoveRemove.

//-------------------------< concurrent remove >----------------------------
public void testRemoveRemove() throws Exception {
    Node d = testRootNode.getNode("A").addNode("D");
    superuser.save();
    d.remove();
    session.getNode(testRoot).getNode("A").getNode("B").remove();
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw exception");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 17 with InvalidItemStateException

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

the class SkipDeletedNodesTest method testRemoveLastNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveLastNode() throws RepositoryException {
    testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the last node
    n3.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 18 with InvalidItemStateException

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

the class SkipDeletedNodesTest method testRemoveFirstNodeAfterHasNext.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     * </p>This test is different from the other tests that it removes the
     * node after another session has called hasNext() to retrieve the node
     * that gets deleted.
     */
public void testRemoveFirstNodeAfterHasNext() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    NodeIterator it = res.getNodes();
    it.hasNext();
    // now remove the first node
    n1.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    while (it.hasNext()) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 19 with InvalidItemStateException

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

the class SkipDeletedNodesTest method testRemoveSomeNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveSomeNode() throws RepositoryException {
    testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the second node
    n2.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 20 with InvalidItemStateException

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

the class NodeStateMergerTest method testMixinRemovedInSessionA.

//---------------- Tests removing jcr:mixinType property in the SessionA ---
/**
     * Remove the jcr:mixinType property by removing all mixin types. Merge
     * to changes made in the overlayed state should fail.
     * @throws Exception
     */
public void testMixinRemovedInSessionA() throws Exception {
    for (int i = 1; i <= 5; i++) {
        testNode.addMixin("test:mixinProp_" + i);
    }
    superuser.save();
    testNodeB.refresh(false);
    // remove all mixin types
    for (NodeType mixin : testNode.getMixinNodeTypes()) {
        testNode.removeMixin(mixin.getName());
    }
    assertFalse(testNode.hasProperty("jcr:mixinTypes"));
    testNodeB.addNode(nodeName1, "nt:unstructured");
    testNodeB.setProperty(propertyName1, "anyValue");
    sessionB.save();
    try {
        superuser.save();
        fail();
    } catch (InvalidItemStateException e) {
    // expected
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) NodeType(javax.jcr.nodetype.NodeType)

Aggregations

InvalidItemStateException (javax.jcr.InvalidItemStateException)100 Node (javax.jcr.Node)67 Session (javax.jcr.Session)35 Test (org.junit.Test)21 Property (javax.jcr.Property)15 RepositoryException (javax.jcr.RepositoryException)14 NodeIterator (javax.jcr.NodeIterator)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 QueryResult (javax.jcr.query.QueryResult)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 NodeType (javax.jcr.nodetype.NodeType)3 SessionImpl (org.apache.jackrabbit.core.SessionImpl)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)3 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Version (javax.jcr.version.Version)2