Search in sources :

Example 96 with InvalidItemStateException

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

the class MoveRemoveTest method removeExistingNodeParent.

@Test
public void removeExistingNodeParent() throws RepositoryException {
    Session session = getAdminSession();
    session.getRootNode().addNode("parent").addNode("new");
    session.save();
    Node n = session.getNode("/parent/new");
    n.getParent().remove();
    try {
        n.getPath();
        fail();
    } catch (InvalidItemStateException e) {
    }
    session.getRootNode().addNode("parent").addNode("new");
    assertEquals("/parent/new", n.getPath());
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Example 97 with InvalidItemStateException

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

the class MoveRemoveTest method removeExistingNodeRefreshParent.

@Test
public void removeExistingNodeRefreshParent() throws RepositoryException {
    Session session = getAdminSession();
    session.getRootNode().addNode("parent").addNode("new");
    session.save();
    Session session2 = createAdminSession();
    Node n2 = session2.getNode("/parent/new");
    Node n = session.getNode("/parent/new");
    n.getParent().remove();
    session.save();
    session2.refresh(false);
    try {
        n2.getPath();
        fail();
    } catch (InvalidItemStateException e) {
    }
    session.getRootNode().addNode("parent").addNode("new");
    session.save();
    session2.refresh(false);
    assertEquals("/parent/new", n2.getPath());
    session2.logout();
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Example 98 with InvalidItemStateException

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

the class RepositoryTest method removeNode.

@Test
public void removeNode() throws RepositoryException {
    Node parentNode = getNode(TEST_PATH);
    parentNode.addNode("newNode");
    parentNode.getSession().save();
    Session session2 = createAdminSession();
    try {
        Node removeNode = session2.getNode(TEST_PATH + "/newNode");
        removeNode.remove();
        try {
            removeNode.getParent();
            fail("Cannot retrieve the parent from a transiently removed item.");
        } catch (InvalidItemStateException expected) {
        }
        assertTrue(session2.getNode(TEST_PATH).isModified());
        session2.save();
    } finally {
        session2.logout();
    }
    Session session3 = createAnonymousSession();
    try {
        assertFalse(session3.nodeExists(TEST_PATH + "/newNode"));
        assertFalse(session3.getNode(TEST_PATH).isModified());
    } finally {
        session3.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Example 99 with InvalidItemStateException

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

the class RepositoryTest method accessRemovedItem.

@Test
public void accessRemovedItem() throws RepositoryException {
    Node foo = getNode("/foo");
    Node bar = foo.addNode("bar");
    Property p = bar.setProperty("name", "value");
    foo.remove();
    try {
        bar.getPath();
        fail("Expected InvalidItemStateException");
    } catch (InvalidItemStateException expected) {
    }
    try {
        p.getPath();
        fail("Expected InvalidItemStateException");
    } catch (InvalidItemStateException expected) {
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Property(javax.jcr.Property) Test(org.junit.Test)

Example 100 with InvalidItemStateException

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

the class RepositoryTest method removeNode2.

@Test
public void removeNode2() throws RepositoryException {
    Node foo = getNode("/foo");
    getAdminSession().removeItem(foo.getPath());
    try {
        foo.getParent();
        fail("Cannot retrieve the parent from a transiently removed item.");
    } catch (InvalidItemStateException e) {
    // success
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Test(org.junit.Test)

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