Search in sources :

Example 6 with PutMethod

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

the class TestWebWAVFS method testCreateAndDeleteFile.

@Test
public void testCreateAndDeleteFile() throws IOException, DavException {
    System.err.println("testCreateAndDeleteFile");
    // Make sure it's deleted
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
    DeleteMethod del = new DeleteMethod(testFileURI1);
    int status = client1.executeMethod(del);
    testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
    PutMethod put = new PutMethod(testFileURI1);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    String testFileURI2 = uri.toASCIIString() + TestSettings.TEST_TXT_FILE_NAME;
    put = new PutMethod(testFileURI2);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    utils.deleteResource(testFileURI1, true);
    utils.deleteResource(testFileURI2, true);
}
Also used : DeleteMethod(org.apache.jackrabbit.webdav.client.methods.DeleteMethod) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Example 7 with PutMethod

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

the class TestWebWAVFS method testPutGet.

// @Test
// public void testUpDownloadFileWithSpace() throws IOException, DavException {
// System.err.println("testUpDownloadFileWithSpace");
// String testFileURI1 = uri.toASCIIString() + "file with spaces";
// 
// utils.createFile(testFileURI1, true);
// 
// GetMethod get = new GetMethod(testFileURI1);
// int status = client1.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals(TestSettings.TEST_DATA, get.getResponseBodyAsString());
// 
// utils.deleteResource(testFileURI1, false);
// }
@Test
public void testPutGet() throws VlException, IOException {
    System.err.println("testPutGet");
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    try {
        PutMethod put = new PutMethod(testFileURI1);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        int status = client1.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        GetMethod get = new GetMethod(testFileURI1);
        client1.executeMethod(get);
        status = get.getStatusCode();
        assertEquals(HttpStatus.SC_OK, status);
        String content = get.getResponseBodyAsString();
        assertEquals(TestSettings.TEST_DATA.length(), content.length());
        assertTrue(content.equals(TestSettings.TEST_DATA));
    } finally {
        utils.deleteResource(testFileURI1, false);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Example 8 with PutMethod

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

the class TestWebWAVFS method testSetGetPropertySet.

@Test
public void testSetGetPropertySet() throws IOException, DavException {
    System.err.println("testSetGetPropertySet");
    String testFileURI1 = this.uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    PutMethod put = new PutMethod(testFileURI1);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    int status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    PropFindMethod propFind = new PropFindMethod(testFileURI1, DavConstants.PROPFIND_ALL_PROP_INCLUDE, DavConstants.DEPTH_0);
    status = client1.executeMethod(propFind);
    assertEquals(HttpStatus.SC_MULTI_STATUS, status);
    MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(HttpStatus.SC_OK, responses[0].getStatus()[0].getStatusCode());
    DavPropertySet allProp = utils.getProperties(responses[0]);
    // DavPropertyIterator iter = allProp.iterator();
    // while (iter.hasNext()) {
    // DavProperty<?> p = iter.nextProperty();
    // System.out.println("P: " + p.getName() + " " + p.getValue());
    // }
    String isCollStr = (String) allProp.get(DavPropertyName.ISCOLLECTION).getValue();
    Boolean isCollection = Boolean.getBoolean(isCollStr);
    assertFalse(isCollection);
    String lenStr = (String) allProp.get(DavPropertyName.GETCONTENTLENGTH).getValue();
    assertEquals(Long.valueOf(lenStr), Long.valueOf(TestSettings.TEST_DATA.length()));
    String contentType = (String) allProp.get(DavPropertyName.GETCONTENTTYPE).getValue();
    assertEquals("text/plain; charset=UTF-8", contentType);
    utils.deleteResource(testFileURI1, true);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) PropFindMethod(org.apache.jackrabbit.webdav.client.methods.PropFindMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Aggregations

StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)8 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)8 Test (org.junit.Test)8 GetMethod (org.apache.commons.httpclient.methods.GetMethod)4 DeleteMethod (org.apache.jackrabbit.webdav.client.methods.DeleteMethod)3 PropFindMethod (org.apache.jackrabbit.webdav.client.methods.PropFindMethod)2 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PDRIDesc (nl.uva.cs.lobcder.tests.TestREST.PDRIDesc)1 VlException (nl.uva.vlet.exception.VlException)1 Header (org.apache.commons.httpclient.Header)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 AuthScope (org.apache.commons.httpclient.auth.AuthScope)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 AclMethod (org.apache.jackrabbit.webdav.client.methods.AclMethod)1 CopyMethod (org.apache.jackrabbit.webdav.client.methods.CopyMethod)1 MkColMethod (org.apache.jackrabbit.webdav.client.methods.MkColMethod)1