Search in sources :

Example 26 with InvalidItemStateException

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

the class ExternalModificationTest method testStaleDestroyed.

public void testStaleDestroyed() throws RepositoryException, NotExecutableException {
    Node refNode2 = (Node) testSession.getItem(refNode.getPath());
    refNode2.addMixin(mixLockable);
    superuser.move(refNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
    superuser.save();
    testSession.getItem(destParentNode.getPath() + "/" + nodeName2);
    assertItemStatus(refNode2, Status.STALE_DESTROYED);
    try {
        refNode2.refresh(false);
        fail();
    } catch (InvalidItemStateException e) {
    // correct behaviour
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 27 with InvalidItemStateException

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

the class ExternalModificationTest method testExternalRemoval2.

public void testExternalRemoval2() throws RepositoryException, NotExecutableException {
    Node childN = refNode.addNode(nodeName3);
    Property p = childN.setProperty(propertyName1, "anyvalue");
    refNode.save();
    String uuid = refNode.getUUID();
    Node refNode2 = testSession.getNodeByUUID(uuid);
    Node c2 = (Node) testSession.getItem(childN.getPath());
    Property p2 = (Property) testSession.getItem(p.getPath());
    // transiently remove the property -> test effect of external removal.
    p2.remove();
    String srcPath = refNode.getPath();
    String destPath = destParentNode.getPath() + "/" + nodeName2;
    superuser.move(srcPath, destPath);
    superuser.save();
    try {
        refNode2.refresh(true);
        Node parent = refNode2.getParent();
    } catch (InvalidItemStateException e) {
    }
    assertItemStatus(refNode2, Status.REMOVED);
    assertItemStatus(c2, Status.STALE_DESTROYED);
    assertItemStatus(p2, Status.REMOVED);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 28 with InvalidItemStateException

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

the class ExternalModificationTest method testConflictingAddMixin.

public void testConflictingAddMixin() throws RepositoryException, NotExecutableException {
    Node refNode2 = (Node) testSession.getItem(refNode.getPath());
    refNode2.addMixin(mixLockable);
    superuser.move(refNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
    superuser.save();
    try {
        refNode2.refresh(true);
        Node parent = refNode2.getParent();
        if (parent.isSame(testSession.getItem(destParentNode.getPath()))) {
            // node has been automatically moved to new place
            assertItemStatus(refNode2, Status.EXISTING_MODIFIED);
        } else if (!isItemStatus(refNode2, Status.EXISTING_MODIFIED)) {
            // external removal was detected either by observation or be
            // batch-reading the parent -> status must be stale.
            assertItemStatus(refNode2, Status.STALE_DESTROYED);
        }
    } catch (InvalidItemStateException e) {
        // no automatic move of the externally moved node. ok.
        log.debug(e.getMessage());
        // since refNode2 has pending modifications its status should be
        // changed to STALE_DESTROYED.
        assertItemStatus(refNode2, Status.STALE_DESTROYED);
        Node refAgain = testSession.getNodeByUUID(refNode.getUUID());
        assertTrue(refAgain.getParent().isSame(testSession.getItem(destParentNode.getPath())));
        assertFalse(refAgain.isNodeType(mixLockable));
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 29 with InvalidItemStateException

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

the class ExternalModificationTest method testRefreshMovedReferenceableNode.

public void testRefreshMovedReferenceableNode() throws RepositoryException, NotExecutableException {
    Node refNode2 = (Node) testSession.getItem(refNode.getPath());
    superuser.move(refNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
    superuser.save();
    try {
        refNode2.refresh(true);
        Node parent = refNode2.getParent();
        if (parent.isSame(testSession.getItem(destParentNode.getPath()))) {
            // node has been automatically moved to new place
            assertItemStatus(refNode2, Status.EXISTING);
        } else {
            assertItemStatus(refNode2, Status.REMOVED);
        }
    } catch (InvalidItemStateException e) {
        // no automatic move of the externally moved node. ok.
        log.debug(e.getMessage());
        // since node had no pending changes -> status should be changed
        // to REMOVED.
        assertItemStatus(refNode2, Status.REMOVED);
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 30 with InvalidItemStateException

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

the class GetPropertyTest method testGetPropertyOfRemovedAncestor.

public void testGetPropertyOfRemovedAncestor() throws RepositoryException {
    Session rw = getHelper().getReadWriteSession();
    try {
        // add modification to a property.
        Property p = (Property) rw.getItem(prop1Path);
        p.setValue("changedValue");
        // transiently remove the test root node
        rw.getItem(testRootNode.getPath()).remove();
        try {
            p.getValue();
            fail("modified property must be marked removed upon parent removal");
        } catch (InvalidItemStateException e) {
        // success
        }
        try {
            rw.getItem(prop1Path);
            fail("modified property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        try {
            Property p2 = (Property) rw.getItem(prop2Path);
            fail("existing property must be marked removed upon parent removal");
        } catch (PathNotFoundException e) {
        // success
        }
        // revert all transient modifications
        rw.refresh(false);
        Property pAgain = (Property) rw.getItem(prop1Path);
        // TODO: for generic jsr 170 test: change assert to p.isSame(pAgain)
        assertTrue(p.isSame(pAgain));
        assertEquals("string1", p.getString());
    } finally {
        rw.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) Session(javax.jcr.Session)

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