use of org.apache.jackrabbit.webdav.client.methods.HttpVersionControl in project jackrabbit by apache.
the class BindTest method testResourceId.
// create test resource, make it referenceable, check resource id, move resource, check again
public void testResourceId() throws IOException, DavException, URISyntaxException {
String testcol = this.root + "testResourceId/";
String testuri1 = testcol + "bindtest1";
String testuri2 = testcol + "bindtest2";
int status;
try {
HttpMkcol mkcol = new HttpMkcol(testcol);
status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
HttpPut put = new HttpPut(testuri1);
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(testuri1);
status = this.client.execute(versioncontrol, this.context).getStatusLine().getStatusCode();
assertTrue("status: " + status, status == 200 || status == 201);
URI resourceId = getResourceId(testuri1);
HttpMove move = new HttpMove(testuri1, testuri2, true);
status = this.client.execute(move, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
URI resourceId2 = getResourceId(testuri2);
assertEquals(resourceId, resourceId2);
} finally {
delete(testcol);
}
}
use of org.apache.jackrabbit.webdav.client.methods.HttpVersionControl in project jackrabbit by apache.
the class BindTest method testRebind.
public void testRebind() throws Exception {
String testcol = this.root + "testRebind/";
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);
// 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);
URI r1 = this.getResourceId(testres1);
HttpGet get = new HttpGet(testres1);
HttpResponse resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("foo", EntityUtils.toString(resp.getEntity()));
//rebind R with path bindtest2/res2
HttpRebind rebind = new HttpRebind(subcol2, new RebindInfo(testres1, "res2"));
status = this.client.execute(rebind, this.context).getStatusLine().getStatusCode();
assertEquals(201, status);
URI r2 = this.getResourceId(testres2);
get = new HttpGet(testres2);
resp = this.client.execute(get, this.context);
status = resp.getStatusLine().getStatusCode();
assertEquals(200, status);
assertEquals("foo", EntityUtils.toString(resp.getEntity()));
//make sure that rebind did not change the resource-id
assertEquals(r1, r2);
//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.jackrabbit.webdav.client.methods.HttpVersionControl 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);
}
}
Aggregations