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();
}
}
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
}
}
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");
}
}
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
}
}
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
}
}
Aggregations