Search in sources :

Example 1 with LockInfo

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);
}
Also used : LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) DavException(org.apache.jackrabbit.webdav.DavException) Test(org.junit.Test)

Example 2 with LockInfo

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));
}
Also used : LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) Test(org.junit.Test)

Example 3 with LockInfo

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);
}
Also used : LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) Test(org.junit.Test)

Example 4 with LockInfo

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);
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) Test(org.junit.Test)

Example 5 with LockInfo

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);
    }
}
Also used : DeleteMethod(org.apache.jackrabbit.webdav.client.methods.DeleteMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)13 Test (org.junit.Test)9 DavException (org.apache.jackrabbit.webdav.DavException)4 HttpLock (org.apache.jackrabbit.webdav.client.methods.HttpLock)3 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)3 URI (java.net.URI)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 HttpResponse (org.apache.http.HttpResponse)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 StringEntity (org.apache.http.entity.StringEntity)1 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 DeleteMethod (org.apache.jackrabbit.webdav.client.methods.DeleteMethod)1 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)1