Search in sources :

Example 76 with InvalidItemStateException

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

the class MoveToNewTest method testMoveTwice.

public void testMoveTwice() throws RepositoryException {
    Session s = testRootNode.getSession();
    String srcPath = moveNode.getPath();
    s.move(srcPath, destinationPath);
    srcParentNode.remove();
    // create new parent
    Node newParent = testRootNode.addNode(nodeName1);
    s.move(destinationPath, srcPath);
    assertTrue(newParent.isNew());
    assertTrue(newParent.hasNode(nodeName2));
    assertTrue(destParentNode.isNew());
    assertFalse(destParentNode.hasNode(nodeName2));
    // remove the tmp destination parent node.
    destParentNode.remove();
    assertTrue(newParent.isNew());
    assertTrue(newParent.hasNode(nodeName2));
    assertTrue(moveNode.isModified());
    testRootNode.save();
    assertFalse(s.itemExists(Text.getRelativeParent(destinationPath, 1)));
    assertTrue(s.itemExists(srcPath));
    assertFalse(moveNode.isModified() || newParent.isNew() || srcParentNode.isModified());
    try {
        srcParentNode.getNode(nodeName2);
        fail("src parent must be removed");
    } catch (InvalidItemStateException e) {
    // ok.
    }
    assertTrue(moveNode.isSame(newParent.getNode(nodeName2)));
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 77 with InvalidItemStateException

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

the class IsSameTest method testShadowingItems3.

public void testShadowingItems3() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    Property p = n.setProperty(propertyName1, "anyValue");
    testRootNode.save();
    p.remove();
    Property p2 = n.setProperty(propertyName1, "anyValue");
    try {
        assertFalse(p2.isSame(p));
    } catch (InvalidItemStateException e) {
    // ok as well.
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 78 with InvalidItemStateException

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

the class RefreshTrueTest method testRemovedProperty.

public void testRemovedProperty() throws RepositoryException {
    Property p = testRootNode.setProperty(propertyName1, testValue);
    testRootNode.save();
    p.remove();
    testRootNode.refresh(true);
    // Property p must remain removed
    try {
        p.getString();
        fail("Refresh 'true' must not revert removal of an item.");
    } catch (InvalidItemStateException e) {
    //ok
    }
    assertFalse("Refresh 'true' must not revert removal of an item.", testRootNode.hasProperty(propertyName1));
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Property(javax.jcr.Property)

Example 79 with InvalidItemStateException

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

the class RefreshFalseTest method testShadowingProperty.

public void testShadowingProperty() throws RepositoryException, LockException, ConstraintViolationException, VersionException {
    Property p = testRootNode.setProperty(propertyName1, testValue);
    testRootNode.save();
    p.remove();
    Property pNew = testRootNode.setProperty(propertyName1, "SomeOtherTestValue");
    testRootNode.refresh(false);
    try {
        pNew.getString();
        fail("Refresh 'false' must remove a new (shadowing) property and bring 'removed' persistent property back to life.");
    } catch (InvalidItemStateException e) {
    // ok
    }
    // Property p must be reverted to 'existing' -> getString must succeed.
    p.getString();
    // similarly accessing the property again must succeed.
    Property pAgain = testRootNode.getProperty(propertyName1);
    assertTrue("Refresh 'false' must remove a new property and bring 'removed' persistent property back to life.", p.isSame(pAgain));
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Property(javax.jcr.Property)

Example 80 with InvalidItemStateException

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

the class RefreshFalseTest method testNewProperty.

public void testNewProperty() throws RepositoryException, LockException, ConstraintViolationException, VersionException {
    Property p = testRootNode.setProperty(propertyName1, testValue);
    testRootNode.refresh(false);
    try {
        p.getString();
        fail("Refresh 'false' must invalidate a new child property");
    } catch (InvalidItemStateException e) {
    // ok
    }
    assertFalse("Refresh 'false' must remove a new child property", 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