use of org.apache.http.client.methods.HttpHead in project jackrabbit by apache.
the class BindTest method testRebindOverwrite.
public void testRebindOverwrite() throws Exception {
String testcol = this.root + "testSimpleBind/";
String subcol1 = testcol + "bindtest1/";
String testres1 = subcol1 + "res1";
String subcol2 = testcol + "bindtest2/";
String testres2 = subcol2 + "res2";
int status;
try {
HttpMkcol mkcol = new HttpMkcol(testcol);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol1);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol2);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// create new resource R with path testSimpleBind/bindtest1/res1
HttpPut put = new HttpPut(testres1);
put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// enabling version control always makes the resource referenceable
HttpVersionControl versioncontrol = new HttpVersionControl(testres1);
status = this.client.execute(versioncontrol, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 201);
// create new resource R' with path testSimpleBind/bindtest2/res2
put = new HttpPut(testres2);
put.setEntity(new StringEntity("bar", ContentType.create("text/plain", "UTF-8")));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// try rebind R with path testSimpleBind/bindtest2/res2 and Overwrite:F
HttpRebind rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
rebind.addHeader("Overwrite", "F");
status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
assertEquals(412, status);
// verify that testSimpleBind/bindtest2/res2 still points to R'
HttpGet get = new HttpGet(testres2);
HttpResponse resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("bar", EntityUtils.toString(resp.getEntity()));
// rebind R with path testSimpleBind/bindtest2/res2
rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 204);
// verify that testSimpleBind/bindtest2/res2 now points to R
get = new HttpGet(testres2);
resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("foo", EntityUtils.toString(resp.getEntity()));
// verify that the initial binding is gone
HttpHead head = new HttpHead(testres1);
status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
assertEquals(404, status);
} finally {
delete(testcol);
}
}
use of org.apache.http.client.methods.HttpHead in project jackrabbit by apache.
the class BindTest method testBindOverwrite.
public void testBindOverwrite() throws Exception {
String testcol = this.root + "testSimpleBind/";
String subcol1 = testcol + "bindtest1/";
String testres1 = subcol1 + "res1";
String subcol2 = testcol + "bindtest2/";
String testres2 = subcol2 + "res2";
int status;
try {
HttpMkcol mkcol = new HttpMkcol(testcol);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol1);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol2);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// create new resource R with path bindtest1/res1
HttpPut put = new HttpPut(testres1);
put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// create new resource R' with path bindtest2/res2
put = new HttpPut(testres2);
put.setEntity(new StringEntity("bar", ContentType.create("text/plain", "UTF-8")));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// try to create new binding of R with path bindtest2/res2 and Overwrite:F
HttpBind bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
bind.addHeader("Overwrite", "F");
status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
assertEquals(412, status);
// verify that bindtest2/res2 still points to R'
HttpGet get = new HttpGet(testres2);
HttpResponse resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("bar", EntityUtils.toString(resp.getEntity()));
// create new binding of R with path bindtest2/res2
bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 204);
// verify that bindtest2/res2 now points to R
get = new HttpGet(testres2);
resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("foo", EntityUtils.toString(resp.getEntity()));
// verify that the initial binding is still there
HttpHead head = new HttpHead(testres1);
status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
assertEquals(200, status);
} finally {
delete(testcol);
}
}
use of org.apache.http.client.methods.HttpHead in project jackrabbit by apache.
the class BindTest method testUnbind.
// will fail until <https://issues.apache.org/jira/browse/JCR-1773> is fixed
public void testUnbind() throws Exception {
String testcol = this.root + "testUnbind/";
String subcol1 = testcol + "bindtest1/";
String testres1 = subcol1 + "res1";
String subcol2 = testcol + "bindtest2/";
String testres2 = subcol2 + "res2";
int status;
try {
HttpMkcol mkcol = new HttpMkcol(testcol);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol1);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
mkcol = new HttpMkcol(subcol2);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// create new resource R with path testSimpleBind/bindtest1/res1
HttpPut put = new HttpPut(testres1);
put.setEntity(new StringEntity("foo", ContentType.create("text/plain", "UTF-8")));
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// create new binding of R with path testSimpleBind/bindtest2/res2
HttpBind bind = new HttpBind(subcol2, new BindInfo(testres1, "res2"));
status = this.client.execute(bind, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
// check if both bindings report the same DAV:resource-id
assertEquals(this.getResourceId(testres1), this.getResourceId(testres2));
// remove new path
HttpUnbind unbind = new HttpUnbind(subcol2, new UnbindInfo("res2"));
status = this.client.execute(unbind, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 204);
// verify that the new binding is gone
HttpHead head = new HttpHead(testres2);
status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
assertEquals(404, status);
// verify that the initial binding is still there
head = new HttpHead(testres1);
status = this.client.execute(head, this.context).getStatusLine().getStatusCode();
assertEquals(200, status);
} finally {
delete(testcol);
}
}
use of org.apache.http.client.methods.HttpHead in project jackrabbit by apache.
the class ContentCodingTest method testPutGzipContentCoding.
public void testPutGzipContentCoding() throws IOException {
String testUri = this.uri.toString() + (this.uri.toString().endsWith("/") ? "" : "/") + "testPutGzipContentCoding";
int status = -1;
try {
byte[] bytes = "foobarfoobarfoobar".getBytes("UTF-8");
HttpPut put = new HttpPut(testUri);
byte[] gzbytes = asGzipOctets(bytes);
assertTrue(gzbytes.length != bytes.length);
ByteArrayEntity entity = new ByteArrayEntity(gzbytes);
entity.setContentEncoding(new BasicHeader("Content-Encoding", "gzip"));
put.setEntity(entity);
status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
assertTrue("server create or signal error, got: " + status, status == 201 || status == 415);
if (status / 2 == 100) {
// check length
HttpHead head = new HttpHead(testUri);
HttpResponse response = this.client.execute(head, this.context);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(bytes.length, Integer.parseInt(response.getFirstHeader("Content-Length").getValue()));
}
} finally {
if (status / 2 == 100) {
delete(testUri);
}
}
}
use of org.apache.http.client.methods.HttpHead in project jackrabbit by apache.
the class RFC4918DestinationHeaderTest method testMove.
public void testMove() throws IOException, URISyntaxException {
String testuri = this.root + "movetest";
String destinationuri = testuri + "2";
String destinationpath = new URI(destinationuri).getRawPath();
// make sure the scheme is removed
assertFalse(destinationpath.contains(":"));
HttpRequestBase requestBase = null;
try {
requestBase = new HttpPut(testuri);
int status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
requestBase.releaseConnection();
// try to move outside the servlet's name space
requestBase = new HttpMove(testuri, "/foobar", true);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 502);
requestBase.releaseConnection();
// try a relative path
requestBase = new HttpMove(testuri, "foobar", true);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 400);
requestBase.releaseConnection();
requestBase = new HttpMove(testuri, destinationpath, true);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 201 || status == 204);
requestBase.releaseConnection();
requestBase = new HttpHead(destinationuri);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200);
requestBase.releaseConnection();
requestBase = new HttpHead(testuri);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 404);
} finally {
requestBase.releaseConnection();
requestBase = new HttpDelete(testuri);
int status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
requestBase.releaseConnection();
requestBase = new HttpDelete(destinationuri);
status = this.client.execute(requestBase, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 204 || status == 404);
requestBase.releaseConnection();
}
}
Aggregations