use of javax.jcr.lock.Lock in project jackrabbit by apache.
the class AbstractLockManagementTest method testLock4.
public void testLock4() throws RepositoryException, NotExecutableException {
Node n = createLockableNode(testRootNode);
Node trn = getTestNode();
modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
Node n2 = trn.getNode(n.getName());
n2.lock(true, true);
Lock l = n2.getLock();
String lt = l.getLockToken();
// withdraw lock-mgmt -> logout of session must still remove the lock
modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, false);
getTestSession().logout();
boolean isLocked = n.isLocked();
assertFalse(isLocked);
}
use of javax.jcr.lock.Lock in project jackrabbit by apache.
the class AbstractLockManagementTest method testLock3.
public void testLock3() throws RepositoryException, NotExecutableException {
Node n = createLockableNode(testRootNode);
Node trn = getTestNode();
modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
Node n2 = trn.getNode(n.getName());
n2.lock(true, true);
Lock l = n2.getLock();
// withdraw lock-mgmt -> must not be able to refresh the lock or
// unlock the node
modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, false);
try {
l.refresh();
fail("TestUser doesn't have permission to refresh the lock.");
} catch (AccessDeniedException e) {
// success
}
try {
n2.unlock();
fail("TestUser doesn't have permission to unlock the node.");
} catch (AccessDeniedException e) {
// success
}
// make sure the lock can be removed upon session.logout.
modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
}
use of javax.jcr.lock.Lock in project jackrabbit by apache.
the class LockTimeOutFormatTest method testfmt.
private void testfmt(long jcrtimeout, String expectedString) throws RepositoryException, URISyntaxException, ParserConfigurationException {
Lock l = new TestLock(jcrtimeout);
JcrActiveLock al = new JcrActiveLock(l);
Document d = DomUtil.createDocument();
Element activeLock = al.toXml(d);
assertEquals("activelock", activeLock.getLocalName());
NodeList nl = activeLock.getElementsByTagNameNS("DAV:", "timeout");
if (expectedString == null) {
assertEquals(0, nl.getLength());
} else {
assertEquals(1, nl.getLength());
Element timeout = (Element) nl.item(0);
String t = DomUtil.getText(timeout);
assertEquals(expectedString, t);
}
}
use of javax.jcr.lock.Lock in project jackrabbit by apache.
the class LockTokenMappingTest method testRoundtrip.
private void testRoundtrip(String token) throws RepositoryException, URISyntaxException {
Lock l = new TestLock(token);
String davtoken = LockTokenMapper.getDavLocktoken(l);
// valid URI?
URI u = new URI(davtoken);
assertTrue("lock token must be absolute URI", u.isAbsolute());
assertEquals("lock token URI must be all-ASCII", u.toASCIIString(), u.toString());
String jcrtoken = LockTokenMapper.getJcrLockToken(davtoken);
assertEquals(jcrtoken, l.getLockToken());
}
use of javax.jcr.lock.Lock in project jackrabbit by apache.
the class XATest method testLockProperties3.
/**
* Test visibility of lock properties by another session.
*
* @throws Exception
*/
public void testLockProperties3() throws Exception {
// add node that is both lockable and referenceable, save
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixLockable);
n.addMixin(mixReferenceable);
testRootNode.save();
Lock lock = n.lock(false, true);
// get user transaction object, start
UserTransaction utx = new UserTransactionImpl(superuser);
utx.begin();
// unlock
n.unlock();
Node n2 = (Node) otherSuperuser.getItem(n.getPath());
assertTrue(n2.isLocked());
assertTrue(n2.hasProperty(jcrLockOwner));
assertTrue(n2.hasProperty(jcrlockIsDeep));
Lock lock2 = n2.getLock();
// complete transaction
utx.commit();
// unlock must now be visible to other session
n2.refresh(false);
assertFalse(lock2.isLive());
assertFalse(n2.isLocked());
assertFalse(n2.hasProperty(jcrLockOwner));
assertFalse(n2.hasProperty(jcrlockIsDeep));
}
Aggregations