use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class NodeTest method testSaveInvalidStateException.
/**
* Tries to save a node using {@link javax.jcr.Node#save()} that was already
* deleted by an other session.
* <p>
* Procedure: <ul> <li>Creates a new
* node with session 1, saves it, adds a child node.</li> <li>Access new
* node with session 2,deletes the node, saves it.</li> <li>Session 1 tries
* to save modifications using <code>Node.save()</code> on root node .</li>
* </ul> This should throw an {@link javax.jcr.InvalidItemStateException}.
* <p>
* Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
* must accept children of same nodetype</li> </ul>
*/
public void testSaveInvalidStateException() throws RepositoryException {
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create a node
Node nodeSession1 = defaultRootNode.addNode(nodeName1, testNodeType);
// save new node
superuser.save();
// make a modification
nodeSession1.addNode(nodeName2, testNodeType);
// get the new node with a different session
Session testSession = getHelper().getReadWriteSession();
try {
Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());
// delete the node with the new session
nodeSession2.remove();
// make node removal persistent
testSession.save();
// save changes made wit superuser session
try {
defaultRootNode.save();
fail("Saving a modified Node using Node.save() already deleted by an other session should throw InvalidItemStateException");
} catch (InvalidItemStateException e) {
// ok, works as expected
}
} finally {
testSession.logout();
}
}
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
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class HierarchyEntryImpl method transientRemove.
/**
* {@inheritDoc}
* @see HierarchyEntry#transientRemove()
*/
public void transientRemove() throws InvalidItemStateException, RepositoryException {
ItemState state = internalGetItemState();
if (state == null) {
// nothing to do -> correct status must be set upon resolution.
return;
}
// it in order to determine the current status.
if (state.getStatus() == Status.INVALIDATED) {
reload(false);
}
switch(state.getStatus()) {
case Status.NEW:
state.setStatus(Status.REMOVED);
parent.internalRemoveChildEntry(this);
break;
case Status.EXISTING:
case Status.EXISTING_MODIFIED:
state.setStatus(Status.EXISTING_REMOVED);
// if a conflict with a new entry occurs.
break;
case Status.REMOVED:
case Status.STALE_DESTROYED:
throw new InvalidItemStateException("Item has already been removed by someone else. Status = " + Status.getName(state.getStatus()));
default:
throw new RepositoryException("Cannot transiently remove an ItemState with status " + Status.getName(state.getStatus()));
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class ConcurrentWriteACLTest method runTest.
@Override
public void runTest() throws Exception {
Session session = null;
try {
session = loginWriter();
for (int i = 0; i < numItems; i++) {
session.refresh(false);
int a = random.nextInt(NODE_COUNT);
int b = random.nextInt(NODE_COUNT);
String path = "/" + ROOT_NODE_NAME + "/node" + a + "/node" + b;
AccessControlManager acMgr = session.getAccessControlManager();
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, path);
if (acl.isEmpty()) {
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
acMgr.setPolicy(path, acl);
}
} else {
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
acl.removeAccessControlEntry(ace);
}
acMgr.setPolicy(path, acl);
}
session.save();
}
} catch (InvalidItemStateException e) {
System.out.printf("error: %s%n", e);
// ignore
} finally {
if (session != null) {
session.logout();
}
}
}
Aggregations