Search in sources :

Example 6 with HttpMkcol

use of org.apache.jackrabbit.webdav.client.methods.HttpMkcol 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);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpVersionControl(org.apache.jackrabbit.webdav.client.methods.HttpVersionControl) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) RebindInfo(org.apache.jackrabbit.webdav.bind.RebindInfo) HttpHead(org.apache.http.client.methods.HttpHead) HttpRebind(org.apache.jackrabbit.webdav.client.methods.HttpRebind)

Example 7 with HttpMkcol

use of org.apache.jackrabbit.webdav.client.methods.HttpMkcol in project jackrabbit by apache.

the class BindTest method testBindCollections.

public void testBindCollections() throws Exception {
    String testcol = this.root + "testBindCollections/";
    String a1 = testcol + "a1/";
    String b1 = a1 + "b1/";
    String c1 = b1 + "c1/";
    String x1 = c1 + "x1";
    String a2 = testcol + "a2/";
    String b2 = a2 + "b2/";
    String c2 = b2 + "c2/";
    String x2 = c2 + "x2";
    int status;
    try {
        HttpMkcol mkcol = new HttpMkcol(testcol);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(a1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(a2);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create collection resource C
        mkcol = new HttpMkcol(b1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        mkcol = new HttpMkcol(c1);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create plain resource R
        HttpPut put = new HttpPut(x1);
        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 C with path a2/b2
        HttpBind bind = new HttpBind(a2, new BindInfo(b1, "b2"));
        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(b1), this.getResourceId(b2));
        mkcol = new HttpMkcol(c2);
        status = this.client.execute(mkcol, this.context).getStatusLine().getStatusCode();
        assertEquals(201, status);
        //create new binding of R with path a2/b2/c2/r2
        bind = new HttpBind(c2, new BindInfo(x1, "x2"));
        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(x1), this.getResourceId(x2));
        //verify different path alternatives
        URI rid = this.getResourceId(x1);
        assertEquals(rid, this.getResourceId(x2));
        assertEquals(rid, this.getResourceId(testcol + "a2/b2/c1/x1"));
        assertEquals(rid, this.getResourceId(testcol + "a1/b1/c2/x2"));
        Object ps = this.getParentSet(x1).getValue();
        assertTrue(ps instanceof List);
        assertEquals(2, ((List) ps).size());
        ps = this.getParentSet(x2).getValue();
        assertTrue(ps instanceof List);
        assertEquals(2, ((List) ps).size());
    } finally {
        delete(testcol);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Example 8 with HttpMkcol

use of org.apache.jackrabbit.webdav.client.methods.HttpMkcol in project jackrabbit by apache.

the class BindTest method testSimpleBind.

public void testSimpleBind() 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 binding of R with path 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));
        //compare representations retrieved with both paths
        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()));
        resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("foo", EntityUtils.toString(resp.getEntity()));
        //modify R using the new path
        put = new HttpPut(testres2);
        put.setEntity(new StringEntity("bar", ContentType.create("text/plain", "UTF-8")));
        status = this.client.execute(put, this.context).getStatusLine().getStatusCode();
        assertTrue("status: " + status, status == 200 || status == 204);
        //compare representations retrieved with both paths
        get = new HttpGet(testres1);
        resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("bar", EntityUtils.toString(resp.getEntity()));
        get = new HttpGet(testres2);
        resp = this.client.execute(get, this.context);
        status = resp.getStatusLine().getStatusCode();
        assertEquals(200, status);
        assertEquals("bar", EntityUtils.toString(resp.getEntity()));
    } finally {
        delete(testcol);
    }
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Example 9 with HttpMkcol

use of org.apache.jackrabbit.webdav.client.methods.HttpMkcol in project jackrabbit by apache.

the class BindTest method testParentSet.

public void testParentSet() throws Exception {
    String testcol = this.root + "testParentSet/";
    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));
        //verify values of parent-set properties
        List<String> hrefs1 = new ArrayList<String>();
        List<String> segments1 = new ArrayList<String>();
        List<String> hrefs2 = new ArrayList<String>();
        List<String> segments2 = new ArrayList<String>();
        Object ps1 = this.getParentSet(testres1).getValue();
        Object ps2 = this.getParentSet(testres2).getValue();
        assertTrue(ps1 instanceof List);
        assertTrue(ps2 instanceof List);
        List plist1 = (List) ps1;
        List plist2 = (List) ps2;
        assertEquals(2, plist1.size());
        assertEquals(2, plist2.size());
        for (int k = 0; k < 2; k++) {
            Object pObj1 = plist1.get(k);
            Object pObj2 = plist2.get(k);
            assertTrue(pObj1 instanceof Element);
            assertTrue(pObj2 instanceof Element);
            ParentElement p1 = ParentElement.createFromXml((Element) pObj1);
            ParentElement p2 = ParentElement.createFromXml((Element) pObj2);
            hrefs1.add(p1.getHref());
            hrefs2.add(p2.getHref());
            segments1.add(p1.getSegment());
            segments2.add(p2.getSegment());
        }
        Collections.sort(hrefs1);
        Collections.sort(hrefs2);
        Collections.sort(segments1);
        Collections.sort(segments2);
        assertEquals(hrefs1, hrefs2);
        assertEquals(segments1, segments2);
    } finally {
        delete(testcol);
    }
}
Also used : HttpBind(org.apache.jackrabbit.webdav.client.methods.HttpBind) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ParentElement(org.apache.jackrabbit.webdav.bind.ParentElement) HttpPut(org.apache.http.client.methods.HttpPut) StringEntity(org.apache.http.entity.StringEntity) HttpMkcol(org.apache.jackrabbit.webdav.client.methods.HttpMkcol) ArrayList(java.util.ArrayList) List(java.util.List) BindInfo(org.apache.jackrabbit.webdav.bind.BindInfo)

Aggregations

HttpMkcol (org.apache.jackrabbit.webdav.client.methods.HttpMkcol)9 HttpPut (org.apache.http.client.methods.HttpPut)8 StringEntity (org.apache.http.entity.StringEntity)8 BindInfo (org.apache.jackrabbit.webdav.bind.BindInfo)5 HttpBind (org.apache.jackrabbit.webdav.client.methods.HttpBind)5 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 HttpHead (org.apache.http.client.methods.HttpHead)4 URI (java.net.URI)3 HttpVersionControl (org.apache.jackrabbit.webdav.client.methods.HttpVersionControl)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RebindInfo (org.apache.jackrabbit.webdav.bind.RebindInfo)2 HttpRebind (org.apache.jackrabbit.webdav.client.methods.HttpRebind)2 InputStreamEntity (org.apache.http.entity.InputStreamEntity)1 Name (org.apache.jackrabbit.spi.Name)1 ParentElement (org.apache.jackrabbit.webdav.bind.ParentElement)1 UnbindInfo (org.apache.jackrabbit.webdav.bind.UnbindInfo)1 HttpMove (org.apache.jackrabbit.webdav.client.methods.HttpMove)1 HttpUnbind (org.apache.jackrabbit.webdav.client.methods.HttpUnbind)1