Search in sources :

Example 11 with DeleteMethod

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

the class WebDAVTest method testGetSetDRICheckSumProp.

@Test
public void testGetSetDRICheckSumProp() throws UnsupportedEncodingException, IOException, DavException {
    System.out.println("testGetSetDRICheckSumProp");
    String testcol1 = root + "testResourceForGetSetDRICheckSumProp/";
    String testuri1 = testcol1 + "file1";
    String testuri2 = testcol1 + "file2";
    String testuri3 = testcol1 + "file3";
    String testcol2 = testcol1 + "folder4/";
    String testuri4 = testcol2 + "file5";
    try {
        DeleteMethod delete = new DeleteMethod(testcol1);
        int status = client.executeMethod(delete);
        MkColMethod mkcol = new MkColMethod(testcol1);
        status = client.executeMethod(mkcol);
        assertEquals(HttpStatus.SC_CREATED, status);
        PutMethod put = new PutMethod(testuri1);
        put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri2);
        put.setRequestEntity(new StringRequestEntity("dar", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri3);
        put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        mkcol = new MkColMethod(testcol2);
        status = client.executeMethod(mkcol);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri4);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        DavPropertyNameSet driSupervisedNameSet = new DavPropertyNameSet();
        DavPropertyName driChecksumName = DavPropertyName.create("dri-checksum-MD5", Namespace.getNamespace("custom:"));
        driSupervisedNameSet.add(driChecksumName);
        PropFindMethod propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
        status = client.executeMethod(propFind);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
        MultiStatusResponse[] responses = multiStatus.getResponses();
        for (MultiStatusResponse r : responses) {
            // System.out.println("Response: " + r.getHref());
            DavPropertySet allProp = utils.getProperties(r);
            DavPropertyIterator iter = allProp.iterator();
            while (iter.hasNext()) {
                DavProperty<?> p = iter.nextProperty();
                assertEquals(p.getName(), driChecksumName);
            }
        }
        DavPropertySet driSuper = new DavPropertySet();
        Long checksum = Long.valueOf(10000);
        DavProperty<Long> driProp = new DefaultDavProperty<Long>(driChecksumName, checksum);
        driSuper.add(driProp);
        PropPatchMethod proPatch = new PropPatchMethod(testcol1, driSuper, driSupervisedNameSet);
        status = client.executeMethod(proPatch);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
        status = client.executeMethod(propFind);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        multiStatus = propFind.getResponseBodyAsMultiStatus();
        responses = multiStatus.getResponses();
        for (MultiStatusResponse r : responses) {
            DavPropertySet allProp = utils.getProperties(r);
            DavPropertyIterator iter = allProp.iterator();
            while (iter.hasNext()) {
                DavProperty<?> p = iter.nextProperty();
                assertEquals(p.getName(), driChecksumName);
                // assertNotNull(p.getValue());
                if (new URL(testcol1).getPath().equals(r.getHref())) {
                    Long val = Long.valueOf(p.getValue().toString());
                    assertEquals(checksum, val);
                }
            }
        }
    } finally {
        utils.deleteResource(testcol1, true);
    }
}
Also used : DeleteMethod(org.apache.jackrabbit.webdav.client.methods.DeleteMethod) URL(java.net.URL) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Example 12 with DeleteMethod

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

the class WebDAVTest method testGetSetDriLastValidationdateProp.

@Test
public void testGetSetDriLastValidationdateProp() throws UnsupportedEncodingException, IOException, DavException {
    System.out.println("testGetSetDriLastValidationdateProp");
    String testcol1 = root + "testResourceForGetSetDriLastValidationdateProp/";
    String testuri1 = testcol1 + "file1";
    String testuri2 = testcol1 + "file2";
    String testuri3 = testcol1 + "file3";
    String testcol2 = testcol1 + "folder4/";
    String testuri4 = testcol2 + "file5";
    try {
        DeleteMethod delete = new DeleteMethod(testcol1);
        int status = client.executeMethod(delete);
        MkColMethod mkcol = new MkColMethod(testcol1);
        status = client.executeMethod(mkcol);
        assertEquals(HttpStatus.SC_CREATED, status);
        PutMethod put = new PutMethod(testuri1);
        put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri2);
        put.setRequestEntity(new StringRequestEntity("dar", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri3);
        put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        mkcol = new MkColMethod(testcol2);
        status = client.executeMethod(mkcol);
        assertEquals(HttpStatus.SC_CREATED, status);
        put = new PutMethod(testuri4);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        status = client.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        DavPropertyNameSet driSupervisedNameSet = new DavPropertyNameSet();
        DavPropertyName driLastValidationName = DavPropertyName.create("dri-last-validation-date-ms", Namespace.getNamespace("custom:"));
        driSupervisedNameSet.add(driLastValidationName);
        PropFindMethod propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
        status = client.executeMethod(propFind);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
        MultiStatusResponse[] responses = multiStatus.getResponses();
        for (MultiStatusResponse r : responses) {
            // System.out.println("Response: " + r.getHref());
            DavPropertySet allProp = utils.getProperties(r);
            DavPropertyIterator iter = allProp.iterator();
            while (iter.hasNext()) {
                DavProperty<?> p = iter.nextProperty();
                // System.out.println(p.getName() + " : " + p.getValue());
                assertEquals(p.getName(), driLastValidationName);
            }
        }
        DavPropertySet driSuper = new DavPropertySet();
        Long date = System.currentTimeMillis();
        DavProperty<Long> driProp = new DefaultDavProperty<Long>(driLastValidationName, date);
        driSuper.add(driProp);
        PropPatchMethod proPatch = new PropPatchMethod(testcol1, driSuper, driSupervisedNameSet);
        status = client.executeMethod(proPatch);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
        status = client.executeMethod(propFind);
        assertEquals(HttpStatus.SC_MULTI_STATUS, status);
        multiStatus = propFind.getResponseBodyAsMultiStatus();
        responses = multiStatus.getResponses();
        for (MultiStatusResponse r : responses) {
            // System.out.println("Response: " + r.getHref());
            DavPropertySet allProp = utils.getProperties(r);
            DavPropertyIterator iter = allProp.iterator();
            while (iter.hasNext()) {
                DavProperty<?> p = iter.nextProperty();
                assertEquals(p.getName(), driLastValidationName);
                // System.out.println(p.getName() + " : " + p.getValue());
                assertNotNull(p.getValue());
                if (new URL(testcol1).getPath().equals(r.getHref())) {
                    Long val = Long.valueOf(p.getValue().toString());
                    assertEquals(date, val);
                }
            }
        }
    } finally {
        utils.deleteResource(testcol1, true);
    }
}
Also used : DeleteMethod(org.apache.jackrabbit.webdav.client.methods.DeleteMethod) URL(java.net.URL) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Test(org.junit.Test)

Aggregations

DeleteMethod (org.apache.jackrabbit.webdav.client.methods.DeleteMethod)12 Test (org.junit.Test)10 PutMethod (org.apache.commons.httpclient.methods.PutMethod)7 URL (java.net.URL)4 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)3 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)3 URI (java.net.URI)2 DecryptedFolderMetadata (com.owncloud.android.datamodel.DecryptedFolderMetadata)1 EncryptedFolderMetadata (com.owncloud.android.datamodel.EncryptedFolderMetadata)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 GetMetadataOperation (com.owncloud.android.lib.resources.files.GetMetadataOperation)1 LockFileOperation (com.owncloud.android.lib.resources.files.LockFileOperation)1 UnlockFileOperation (com.owncloud.android.lib.resources.files.UnlockFileOperation)1 UpdateMetadataOperation (com.owncloud.android.lib.resources.files.UpdateMetadataOperation)1 Header (org.apache.commons.httpclient.Header)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 AclMethod (org.apache.jackrabbit.webdav.client.methods.AclMethod)1 PropFindMethod (org.apache.jackrabbit.webdav.client.methods.PropFindMethod)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)1