Search in sources :

Example 81 with InvalidItemStateException

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

the class RefreshMovedTest method testRefreshOtherSession.

/**
     * Test if refresh(false) affecting a node that has been moved by another
     * session invalidates the node properly in termes of either moving it to
     * the new destination or marking it 'removed'.
     *
     * @throws RepositoryException
     */
public void testRefreshOtherSession() throws RepositoryException {
    Session readSession = getHelper().getReadOnlySession();
    try {
        Node anotherNode = (Node) readSession.getItem(srcPath);
        // workspace move
        testRootNode.getSession().getWorkspace().move(srcPath, destinationPath);
        readSession.refresh(false);
        try {
            String p = anotherNode.getPath();
            // unless InvalidItemStateException is thrown the node must have
            // been 'moved' to its new position.
            assertTrue("Upon refresh of a node moved by another session it must be moved to the new destination (or removed).", p.equals(destinationPath));
        } catch (InvalidItemStateException e) {
        // ok as well.
        }
    } finally {
        readSession.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 82 with InvalidItemStateException

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

the class RefreshTrueTest method testRemovedNewItem.

public void testRemovedNewItem() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName2);
    Property p = n.setProperty(propertyName1, testValue);
    n.remove();
    testRootNode.refresh(true);
    // n must still be new and accessible
    String msg = "Refresh 'true' must revert the removal of new a Node/Property.";
    assertFalse(msg, testRootNode.hasNode(nodeName2));
    assertFalse(msg, n.isNew() && n.isModified());
    assertFalse(msg, p.isNew() && p.isModified());
    try {
        n.hasProperty(propertyName1);
        fail(msg);
    } catch (InvalidItemStateException e) {
    // success
    }
    try {
        p.getString();
        fail(msg);
    } catch (InvalidItemStateException e) {
    // success
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 83 with InvalidItemStateException

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

the class JcrClient method getPrompt.

/**
     * Prompt message
     * @return prompt the prompt message
     * @throws RepositoryException
     *         if the current <code>Repository</code> throws a
     *         <code>RepositoryException</code>
     */
private String getPrompt() throws RepositoryException {
    try {
        CommandHelper.getRepository(ctx);
    } catch (CommandException e) {
        return bundle.getString("phrase.not.connected");
    }
    boolean unsaved = false;
    try {
        unsaved = CommandHelper.getSession(ctx).hasPendingChanges();
    } catch (CommandException e) {
        return bundle.getString("phrase.not.logged.in");
    }
    try {
        Node n = CommandHelper.getCurrentNode(ctx);
        // the current node might be Invalid
        String path;
        try {
            path = n.getPath();
        } catch (InvalidItemStateException e) {
            CommandHelper.setCurrentNode(ctx, CommandHelper.getSession(ctx).getRootNode());
            path = CommandHelper.getCurrentNode(ctx).getPath();
        }
        if (unsaved) {
            return path + "*";
        } else {
            return path;
        }
    } catch (CommandException e) {
        return bundle.getString("phrase.not.logged.in");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) CommandException(org.apache.jackrabbit.standalone.cli.CommandException)

Example 84 with InvalidItemStateException

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

the class CheckinTest method testCheckinWithPendingChangesJcr2.

/**
     * Test if VersionManager.checkin(P) throws InvalidItemStateException if
     * the path P resolves to a node that has unsaved changes pending.
     *
     * @throws RepositoryException
     */
public void testCheckinWithPendingChangesJcr2() throws RepositoryException {
    try {
        // modify node without calling save()
        versionableNode.setProperty(propertyName1, propertyValue);
        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
        String path = versionableNode.getPath();
        versionManager.checkin(path);
        fail("InvalidItemStateException must be thrown on attempt to checkin a node having any unsaved changes pending.");
    } catch (InvalidItemStateException e) {
    // ok
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) VersionManager(javax.jcr.version.VersionManager)

Example 85 with InvalidItemStateException

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

the class WorkspaceRestoreTest method testWorkspaceRestoreWithPendingChangesJcr2.

/**
     * Test if InvalidItemStateException is thrown if the session affected by
     * VersionManager.restore(Version[], boolean) has pending changes.
     */
public void testWorkspaceRestoreWithPendingChangesJcr2() throws RepositoryException {
    versionableNode.getSession().getWorkspace().getVersionManager().checkout(versionableNode.getPath());
    try {
        // modify node without calling save()
        versionableNode.setProperty(propertyName1, propertyValue);
        // create version in second workspace
        Version v = wVersionableNode.getSession().getWorkspace().getVersionManager().checkin(wVersionableNode.getPath());
        // try to restore that version
        superuser.getWorkspace().getVersionManager().restore(new Version[] { v }, false);
        fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
    } catch (InvalidItemStateException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) InvalidItemStateException(javax.jcr.InvalidItemStateException)

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