use of org.apache.jackrabbit.webdav.lock.LockInfo in project archiva by apache.
the class DavResourceTest method testLockIfResourceUnlockable.
@Test
public void testLockIfResourceUnlockable() throws Exception {
assertEquals(0, resource.getLocks().length);
LockInfo info = new LockInfo(Scope.SHARED, Type.WRITE, "/", 0, false);
try {
lockManager.createLock(info, resource);
fail("Did not throw dav exception");
} catch (Exception e) {
// Simple lock manager will die
}
assertEquals(0, resource.getLocks().length);
}
use of org.apache.jackrabbit.webdav.lock.LockInfo in project archiva by apache.
the class DavResourceTest method testGetLock.
@Test
public void testGetLock() throws Exception {
LockInfo info = new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "/", 0, false);
lockManager.createLock(info, resource);
assertEquals(1, resource.getLocks().length);
// Lock should exist
assertNotNull(resource.getLock(Type.WRITE, Scope.EXCLUSIVE));
// Lock should not exist
assertNull(resource.getLock(Type.WRITE, Scope.SHARED));
}
use of org.apache.jackrabbit.webdav.lock.LockInfo in project archiva by apache.
the class DavResourceTest method testLock.
@Test
public void testLock() throws Exception {
assertEquals(0, resource.getLocks().length);
LockInfo info = new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "/", 0, false);
lockManager.createLock(info, resource);
assertEquals(1, resource.getLocks().length);
}
use of org.apache.jackrabbit.webdav.lock.LockInfo in project archiva by apache.
the class DavResourceTest method testUnlock.
@Test
public void testUnlock() throws Exception {
LockInfo info = new LockInfo(Scope.EXCLUSIVE, Type.WRITE, "/", 0, false);
assertEquals(0, resource.getLocks().length);
lockManager.createLock(info, resource);
assertEquals(1, resource.getLocks().length);
ActiveLock lock = resource.getLocks()[0];
lockManager.releaseLock(lock.getToken(), resource);
assertEquals(0, resource.getLocks().length);
}
use of org.apache.jackrabbit.webdav.lock.LockInfo in project lobcder by skoulouzis.
the class WebDAVTest method testPutIfLockToken.
@Test
public void testPutIfLockToken() throws HttpException, IOException, DavException, URISyntaxException {
String testuri = root + "iflocktest";
String locktoken = null;
int status;
try {
PutMethod put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("1"));
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT);
LockMethod lock = new LockMethod(testuri, new LockInfo(org.apache.jackrabbit.webdav.lock.Scope.EXCLUSIVE, org.apache.jackrabbit.webdav.lock.Type.WRITE, "testcase", 10000, true));
status = client.executeMethod(lock);
assertEquals("status", HttpStatus.SC_OK, status);
locktoken = lock.getLockToken();
assertNotNull(locktoken);
// try to read without lock token
GetMethod get = new GetMethod(testuri);
status = client.executeMethod(get);
assertEquals("status", HttpStatus.SC_OK, status);
// try to overwrite without lock token
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
status = client.executeMethod(put);
assertEquals("status: " + status, 423, status);
// try to overwrite using bad lock token
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
put.setRequestHeader("If", "(<" + "DAV:foobar" + ">)");
status = client.executeMethod(put);
assertEquals("status: " + status, 412, status);
// try to overwrite using correct lock token, using No-Tag-list format
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
put.setRequestHeader("If", "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
get = new GetMethod(testuri);
status = client.executeMethod(get);
assertEquals("status", HttpStatus.SC_OK, status);
String responce = get.getResponseBodyAsString();
assertEquals("2", responce);
// try to overwrite using correct lock token, using Tagged-list format
// and full URI
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("3"));
put.setRequestHeader("If", "<" + testuri + ">" + "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
// try to overwrite using correct lock token, using Tagged-list format
// and absolute path only
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("4"));
put.setRequestHeader("If", "<" + new URI(testuri).getRawPath() + ">" + "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
// // try to overwrite using correct lock token, using Tagged-list format
// // and bad path
// put = new PutMethod(testuri);
// put.setRequestEntity(new StringRequestEntity("5"));
// put.setRequestHeader("If", "</foobar>" + "(<" + locktoken + ">)");
// status = client.executeMethod(put);
// assertTrue("status: " + status, status == HttpStatus.SC_NOT_FOUND || status == 412);
UnLockMethod unlock = new UnLockMethod(testuri, "wrong");
status = client.executeMethod(unlock);
assertTrue("status: " + status, status == HttpStatus.SC_FAILED_DEPENDENCY || status == HttpStatus.SC_PRECONDITION_FAILED);
unlock = new UnLockMethod(testuri, locktoken);
status = client.executeMethod(unlock);
assertTrue("status: " + status, status == HttpStatus.SC_NO_CONTENT);
} finally {
DeleteMethod delete = new DeleteMethod(testuri);
if (locktoken != null) {
delete.setRequestHeader("If", "(<" + locktoken + ">)");
}
status = client.executeMethod(delete);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_FOUND);
}
}
Aggregations