Search in sources :

Example 71 with InvalidItemStateException

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

the class SkipDeletedNodesTest method testRemoveSomeNodeAfterHasNext.

/**
     * 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 testRemoveSomeNodeAfterHasNext() 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();
    NodeIterator it = res.getNodes();
    it.hasNext();
    // now remove the second node
    n2.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 72 with InvalidItemStateException

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

the class SessionTest method testSaveInvalidStateException.

/**
     * Tries to save a node using {@link javax.jcr.Session#save()} that was
     * already deleted by an other session.
     * <p>
     * Procedure: <ul>
     * <li>Creates a new node with session 1, saves it, adds a child node.</li>
     * <li>Access new node with session 2,deletes the node, saves it.</li>
     * <li>session 1 tries to save modifications .</li> </ul> This should throw
     * an {@link javax.jcr.InvalidItemStateException}.
     * <p>
     * Prerequisites:
     * <ul> <li><code>javax.jcr.tck.nodetype</code> must accept children of same
     * nodetype</li> </ul>
     */
public void testSaveInvalidStateException() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node
    Node nodeSession1 = defaultRootNode.addNode(nodeName1, testNodeType);
    // save new node
    superuser.save();
    // make a modification
    nodeSession1.addNode(nodeName2, testNodeType);
    // get the new node with a different session
    Session testSession = getHelper().getReadWriteSession();
    try {
        Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());
        // delete the node with the new session
        nodeSession2.remove();
        // make node removal persistent
        testSession.save();
        // save changes made with superuser session
        try {
            superuser.save();
            fail("Saving a modified Node using Session.save() already deleted by an other session should throw InvalidItemStateException");
        } catch (InvalidItemStateException e) {
        // ok, works as expected
        }
    } finally {
        testSession.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 73 with InvalidItemStateException

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

the class SessionUUIDTest method testSaveMovedRefNode.

/**
     * Moves a referencable node using {@link javax.jcr.Session#move(String, String)} with one session and
     * saves afterward changes made with a second session to the moved node using {@link Session#save()}.
     * <p>
     * Procedure:
     * <ul>
     * <li>Creates node 1 and node 2 with session 1</li>
     * <li>Gets reference to node 1 using session 2</li>
     * <li>Session 1 moves node 1 under node 2, saves changes</li>
     * <li>Session 2 modifes node 1, saves</li>
     * </ul>
     * This should work (since the modified node is identified by its UUID, not by position in repository)
     * or throw an <code>InvalidItemStateException</code> if 'move' is reported
     * to the second session as a sequence of remove and add events.
     * <br><br>Prerequisites:
     * <ul>
     * <li><code>javax.jcr.tck.SessionUUIDTest.nodetype2</code> must have the mixin type <code>mix:referenceable</code> assigned.</li>
     * <li><code>javax.jcr.tck.SessionUUIDTest.testSaveMovedRefNode.propertyname1</code>
     * name of a property that can be modified in <code>nodetype2</code> for testing</li>
     * </ul>
     */
public void testSaveMovedRefNode() throws RepositoryException, NotExecutableException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node
    Node newParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // create a referenceable node
    Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
    // save the new nodes
    superuser.save();
    if (!refTargetNode.isNodeType(mixReferenceable)) {
        throw new NotExecutableException("Cannot test referential integrity. Node is not referenceable.");
    }
    // get the moving node with session 2
    Session testSession = getHelper().getReadWriteSession();
    try {
        Node refTargetNodeSession2 = (Node) testSession.getItem(refTargetNode.getPath());
        // move the node with session 1
        superuser.move(refTargetNode.getPath(), newParentNode.getPath() + "/" + nodeName2);
        // make the move persistent with session 1
        superuser.save();
        try {
            // modify some prop of the moved node with session 2
            refTargetNodeSession2.setProperty(propertyName1, "test");
            // save it
            testSession.save();
        // ok, works as expected
        } catch (InvalidItemStateException e) {
        // ok as well.
        }
    } finally {
        testSession.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 74 with InvalidItemStateException

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

the class IsSameTest method testIsSameNode6.

public void testIsSameNode6() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixReferenceable);
    testRootNode.save();
    // transiently move the node.
    String srcPath = n.getPath();
    String destPath = testRootNode.getPath() + "/" + nodeName2;
    Session otherSession = getHelper().getReadOnlySession();
    try {
        Node otherNode = (Node) otherSession.getItem(srcPath);
        testRootNode.getSession().getWorkspace().move(srcPath, destPath);
        otherNode.refresh(false);
        try {
            assertTrue(n.isSame(otherNode));
        } catch (InvalidItemStateException e) {
        // ok as well.
        }
        try {
            assertTrue(otherNode.isSame(n));
        } catch (InvalidItemStateException e) {
        // ok as well.
        }
    } finally {
        otherSession.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 75 with InvalidItemStateException

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

the class RefreshFalseTest method testRemovedNewProperty.

public void testRemovedNewProperty() throws RepositoryException, LockException, ConstraintViolationException, VersionException {
    Property p = testRootNode.setProperty(propertyName1, testValue);
    p.remove();
    testRootNode.refresh(false);
    try {
        p.getString();
        fail("Refresh 'false' must not bring a removed new child property back to life.");
    } catch (InvalidItemStateException e) {
    // ok
    }
    assertFalse("Refresh 'false' must not bring a removed new child property back to life.", testRootNode.hasProperty(propertyName1));
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Property(javax.jcr.Property)

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