rootNode.save();
String uuid = n.getUUID();
// lock this new node
Lock lock = n.lock(true, false);
String lockToken = lock.getLockToken();
// assert: session must get a non-null lock token
assertNotNull("session must get a non-null lock token", lockToken);
// assert: session must hold lock token
assertTrue("session must hold lock token", containsLockToken(superuser, lockToken));
superuser.removeLockToken(lockToken);
assertNull("session must get a null lock token", lock.getLockToken());
// commit
utx.commit();
// refresh Lock Info
lock = n.getLock();
assertNull("session must get a null lock token", lock.getLockToken());
Session other = getHelper().getSuperuserSession();
try {
// start new Transaction and try to add lock token
utx = new UserTransactionImpl(other);
utx.begin();
Node otherNode = other.getNodeByUUID(uuid);
assertTrue("Node not locked", otherNode.isLocked());
try {
otherNode.setProperty(propertyName1, "foo");
fail("Lock exception should be thrown");
} catch (LockException e) {
// expected
}
// add lock token
other.addLockToken(lockToken);
// refresh Lock Info
lock = otherNode.getLock();
// assert: session must hold lock token
assertTrue("session must hold lock token", containsLockToken(other, lock.getLockToken()));
otherNode.unlock();
assertFalse("Node is locked", otherNode.isLocked());