use of org.apache.commons.httpclient.methods.PutMethod in project lobcder by skoulouzis.
the class WebDAVTest method testBindOverwrite.
@Test
public void testBindOverwrite() throws Exception {
System.out.println("testBindOverwrite");
String testcol = root + "testSimpleBind/";
String subcol1 = testcol + "bindtest1/";
String testres1 = subcol1 + "res1";
String subcol2 = testcol + "bindtest2/";
String testres2 = subcol2 + "res2";
int status;
try {
MkColMethod mkcol = new MkColMethod(testcol);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(subcol1);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(subcol2);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
// create new resource R with path bindtest1/res1
PutMethod put = new PutMethod(testres1);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
// create new resource R' with path bindtest2/res2
put = new PutMethod(testres2);
put.setRequestEntity(new StringRequestEntity("bar", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
// try to create new binding of R with path bindtest2/res2 and Overwrite:F
// DavMethodBase bind = new BindMethod(subcol2, new BindInfo(testres1, "res2"));
// bind.addRequestHeader(new Header("Overwrite", "F"));
// status = client.executeMethod(bind);
// assertEquals(412, status);
// verify that bindtest2/res2 still points to R'
// GetMethod get = new GetMethod(testres2);
// status = client.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals("bar", get.getResponseBodyAsString());
// create new binding of R with path bindtest2/res2
// bind = new BindMethod(subcol2, new BindInfo(testres1, "res2"));
// status = client.executeMethod(bind);
// assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT);
// verify that bindtest2/res2 now points to R
// get = new GetMethod(testres2);
// status = client.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals("foo", get.getResponseBodyAsString());
// verify that the initial binding is still there
// HeadMethod head = new HeadMethod(testres1);
// status = client.executeMethod(head);
// assertEquals(HttpStatus.SC_OK, status);
} finally {
utils.deleteResource(testcol, true);
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project lobcder by skoulouzis.
the class WebDAVTest method testFileConsistency.
@Test
public void testFileConsistency() throws IOException, NoSuchAlgorithmException {
System.out.println("testFileConsistency");
File testUploadFile = File.createTempFile("tmp", null);
Random generator = new Random();
byte[] buffer = new byte[1024];
OutputStream out = new FileOutputStream(testUploadFile);
for (int i = 0; i < 10; i++) {
generator.nextBytes(buffer);
out.write(buffer);
}
String lobcderFilePath = root + testUploadFile.getName();
try {
PutMethod method = new PutMethod(lobcderFilePath);
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(testUploadFile));
method.setRequestEntity(requestEntity);
int status = client.executeMethod(method);
assertEquals(HttpStatus.SC_CREATED, status);
String localMD5 = utils.checkChecksum(new FileInputStream(testUploadFile));
GetMethod get = new GetMethod(lobcderFilePath);
status = client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, status);
InputStream in = get.getResponseBodyAsStream();
String remoteMD5 = utils.checkChecksum(in);
assertEquals(localMD5, remoteMD5);
} finally {
utils.deleteResource(lobcderFilePath, true);
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project lobcder by skoulouzis.
the class WebDAVTest method testUnbind.
// will fail until <https://issues.apache.org/jira/browse/JCR-1773> is fixed
@Test
public void testUnbind() throws Exception {
System.out.println("testUnbind");
String testcol = root + "testUnbind/";
String subcol1 = testcol + "bindtest1/";
String testres1 = subcol1 + "res1";
String subcol2 = testcol + "bindtest2/";
String testres2 = subcol2 + "res2";
int status;
try {
MkColMethod mkcol = new MkColMethod(testcol);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(subcol1);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(subcol2);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
// create new resource R with path testSimpleBind/bindtest1/res1
PutMethod put = new PutMethod(testres1);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
//
// //create new binding of R with path testSimpleBind/bindtest2/res2
// DavMethodBase bind = new BindMethod(subcol2, new BindInfo(testres1, "res2"));
// status = client.executeMethod(bind);
// assertEquals(HttpStatus.SC_CREATED, status);
// //check if both bindings report the same DAV:resource-id
// assertEquals(this.getResourceId(testres1), this.getResourceId(testres2));
//
// //remove new path
// UnbindMethod unbind = new UnbindMethod(subcol2, new UnbindInfo("res2"));
// status = client.executeMethod(unbind);
// assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT);
//
// //verify that the new binding is gone
// HeadMethod head = new HeadMethod(testres2);
// status = client.executeMethod(head);
// assertEquals(HttpStatus.SC_NOT_FOUND, status);
//
// //verify that the initial binding is still there
// head = new HeadMethod(testres1);
// status = client.executeMethod(head);
// assertEquals(HttpStatus.SC_OK, status);
} finally {
utils.deleteResource(testcol, true);
}
}
use of org.apache.commons.httpclient.methods.PutMethod 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);
}
}
use of org.apache.commons.httpclient.methods.PutMethod 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);
}
}
Aggregations