Search in sources :

Example 1 with HttpUnbind

use of org.apache.jackrabbit.webdav.client.methods.HttpUnbind 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);
    }
}
Also used : UnbindInfo(org.apache.jackrabbit.webdav.bind.UnbindInfo) StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) HttpUnbind(org.apache.jackrabbit.webdav.client.methods.HttpUnbind) HttpPut(org.apache.http.client.methods.HttpPut) HttpHead(org.apache.http.client.methods.HttpHead) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Aggregations

HttpHead (org.apache.http.client.methods.HttpHead)1 HttpPut (org.apache.http.client.methods.HttpPut)1 StringEntity (org.apache.http.entity.StringEntity)1 BindInfo (org.apache.jackrabbit.webdav.bind.BindInfo)1 UnbindInfo (org.apache.jackrabbit.webdav.bind.UnbindInfo)1 HttpBind (org.apache.jackrabbit.webdav.client.methods.HttpBind)1 HttpMkcol (org.apache.jackrabbit.webdav.client.methods.HttpMkcol)1 HttpUnbind (org.apache.jackrabbit.webdav.client.methods.HttpUnbind)1