Search in sources :

Example 91 with InvalidItemStateException

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

the class CRUDTest method testRemoveMissingProperty.

@Test
public void testRemoveMissingProperty() throws RepositoryException {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    Property p = root.setProperty("missing", (String) null);
    assertNotNull(p);
    try {
        p.getValue();
        fail("must throw InvalidItemStateException");
    } catch (InvalidItemStateException e) {
    // expected
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 92 with InvalidItemStateException

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

the class CompatibilityIssuesTest method move.

@Test
public void move() throws RepositoryException {
    Session session = getAdminSession();
    Node node = session.getNode("/");
    node.addNode("source").addNode("node");
    node.addNode("target");
    session.save();
    session.refresh(true);
    Node sourceNode = session.getNode("/source/node");
    session.move("/source/node", "/target/moved");
    // assertEquals("/target/moved", sourceNode.getPath());  // passes on JR2, fails on Oak
    try {
        sourceNode.getPath();
    } catch (InvalidItemStateException expected) {
    // sourceNode is stale
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Example 93 with InvalidItemStateException

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

the class CRUDTest method checkPathInInvalidItemStateException.

@Test
public void checkPathInInvalidItemStateException() throws Exception {
    Session s1 = getAdminSession();
    Node root = s1.getRootNode();
    Node a = root.addNode("a");
    String path = a.getPath();
    s1.save();
    Session s2 = getAdminSession();
    s2.getRootNode().getNode("a").remove();
    s2.save();
    s1.refresh(false);
    try {
        a.getPath();
    } catch (InvalidItemStateException e) {
        assertThat(e.getMessage(), containsString(path));
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Session(javax.jcr.Session) Test(org.junit.Test)

Example 94 with InvalidItemStateException

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

the class CRUDTest method testRemoveMissingMVProperty.

@Test
public void testRemoveMissingMVProperty() throws RepositoryException {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    Property p = root.setProperty("missing", (String[]) null);
    assertNotNull(p);
    try {
        p.getValues();
        fail("must throw InvalidItemStateException");
    } catch (InvalidItemStateException e) {
    // expected
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 95 with InvalidItemStateException

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

the class MoveRemoveTest method removeNewNodeParent.

@Test
public void removeNewNodeParent() throws RepositoryException {
    Session session = getAdminSession();
    session.getRootNode().addNode("parent").addNode("new");
    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)

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