Search in sources :

Example 1 with CopyMethod

use of org.apache.jackrabbit.webdav.client.methods.CopyMethod in project lobcder by skoulouzis.

the class TestWebWAVFS method testCopy.

@Test
public void testCopy() throws VlException, IOException {
    System.err.println("testCopy");
    String testFileURI1 = this.uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    String testcol = root + "testResourceId/";
    try {
        PutMethod put = new PutMethod(testFileURI1);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        int status = client1.executeMethod(put);
        assertTrue(status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
        GetMethod get = new GetMethod(testFileURI1);
        status = client1.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, status);
        String cont = get.getResponseBodyAsString();
        assertEquals(TestSettings.TEST_DATA, cont);
        MkColMethod mkcol = new MkColMethod(testcol);
        status = client1.executeMethod(mkcol);
        assertEquals(HttpStatus.SC_CREATED, status);
        String targetURL = testcol + TestSettings.TEST_FILE_NAME1 + ".txt";
        CopyMethod cp = new CopyMethod(testFileURI1, targetURL, true);
        status = client1.executeMethod(cp);
        assertTrue(status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
        get = new GetMethod(targetURL);
        status = client1.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, status);
        cont = get.getResponseBodyAsString();
        System.out.println(cont);
        assertEquals(TestSettings.TEST_DATA, cont);
    } finally {
        utils.deleteResource(testcol, false);
        utils.deleteResource(testFileURI1, false);
    }
}
Also used : MkColMethod(org.apache.jackrabbit.webdav.client.methods.MkColMethod) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) CopyMethod(org.apache.jackrabbit.webdav.client.methods.CopyMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Aggregations

GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)1 CopyMethod (org.apache.jackrabbit.webdav.client.methods.CopyMethod)1 MkColMethod (org.apache.jackrabbit.webdav.client.methods.MkColMethod)1 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)1 Test (org.junit.Test)1