Package org.apache.wink.client

Examples of org.apache.wink.client.ClientResponse


     *
     * @throws IOException
     * @throws HttpException
     */
    public void testCookiesManyGiven() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/cookies")
                .cookie(new Cookie("foo", "bar")).cookie(new Cookie("foo2", "bar2")).post(null);
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("cookies:foo=bar:foo2=bar2:", responseBody);

        response =
            client.resource(getBaseURI() + "/context/httpheaders/cookies").cookie("foo=bar")
                .cookie("foo2=bar2").post(null);
        assertEquals(200, response.getStatusCode());
        responseBody = response.getEntity(String.class);
        assertEquals("cookies:foo=bar:foo2=bar2:", responseBody);
    }
View Full Code Here


     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeaderNoneGivenIllegalArgument() throws HttpException, IOException {
        ClientResponse response = client.resource(getBaseURI() + "/context/httpheaders/").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("requestheader:null:", responseBody);
    }
View Full Code Here

     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeaderNonexistentHeader() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/" + "?name=foo").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("requestheader:null:", responseBody);

        response =
            client.resource(getBaseURI() + "/context/httpheaders/").queryParam("name", "foo").get();
        assertEquals(200, response.getStatusCode());
        responseBody = response.getEntity(String.class);
        assertEquals("requestheader:null:", responseBody);

        MultivaluedMap<String, String> map = new MultivaluedMapImpl<String, String>();
        map.put("name", new ArrayList<String>());
        response = client.resource(getBaseURI() + "/context/httpheaders/").queryParams(map).get();
        assertEquals(200, response.getStatusCode());
        responseBody = response.getEntity(String.class);
        assertEquals("requestheader:null:", responseBody);
    }
View Full Code Here

     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeaderSingleValue() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/" + "?name=foo").header("foo",
                                                                                         "bar")
                .get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("requestheader:[bar]", responseBody);
    }
View Full Code Here

     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeaderMultipleValue() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/" + "?name=foo").header("foo",
                                                                                         "bar")
                .header("foo", "bar2").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("requestheader:[bar, bar2]", responseBody);
    }
View Full Code Here

     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeaderCaseInsensitive() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/" + "?name=foo").header("FOO",
                                                                                         "bar")
                .header("FoO", "bar2").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);
        assertEquals("requestheader:[bar, bar2]", responseBody);
    }
View Full Code Here

     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeadersBasicHeader() throws HttpException, IOException {

        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/requestheaders").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);

        assertTrue(responseBody, responseBody.contains("requestheaders:"));
        assertTrue(responseBody, responseBody.contains(":host=") || responseBody.contains(":Host="));
        assertTrue(responseBody, responseBody.contains(":user-agent=") || responseBody
            .contains(":User-Agent="));
View Full Code Here

     *
     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeadersSingleValue() throws HttpException, IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/requestheaders").header("fOo",
                                                                                         "bAr")
                .get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);

        assertTrue(responseBody, responseBody.contains("requestheaders:"));
        assertTrue(responseBody, responseBody.contains(":fOo=[bAr]") || responseBody
            .contains(":foo=[bAr]"));
    }
View Full Code Here

     * @throws IOException
     * @throws HttpException
     */
    public void testRequestHeadersMultipleValues() throws HttpException, IOException {

        ClientResponse response =
            client.resource(getBaseURI() + "/context/httpheaders/requestheaders").header("fOo",
                                                                                         "bAr")
                .header("fOo", "2bAr").header("abc", "xyz").get();
        assertEquals(200, response.getStatusCode());
        String responseBody = response.getEntity(String.class);

        assertTrue(responseBody, responseBody.contains("requestheaders:"));
        assertTrue(responseBody, responseBody.contains(":fOo=[2bAr, bAr]") || responseBody
            .contains(":foo=[2bAr, bAr]"));
        assertTrue(responseBody, responseBody.contains(":abc=[xyz]"));
View Full Code Here

        String isWeak = isEntityTagWeak ? "true" : "false";

        /*
         * sets an entity tag
         */
        ClientResponse response =
            client.resource(getBaseURI() + "/context/request/etag").contentType("text/string")
                .put(setETag);
        assertEquals(204, response.getStatusCode());

        /*
         * verifies that if the exact etag is sent in, then the response is a
         * 304
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, setETag).get();
        assertEquals(304, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));

        /*
         * verifies that if a "*" etag is sent in, then the response returns a
         * 304
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"*\"").get();
        assertEquals(304, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));

        /*
         * verifies that if a "*" etag is sent in, then the response returns a
         * 412
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"*\"").post(null);
        assertEquals(412, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));

        /*
         * verifies that if the set etag is sent in, then the response returns a
         * 412
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, setETag).post(null);
        assertEquals(412, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));

        /*
         * verifies that a request without an If-None-Match header will still
         * proceed
         */
        response = client.resource(getBaseURI() + "/context/request/etag").get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that a request without an If-None-Match header will still
         * proceed
         */
        response = client.resource(getBaseURI() + "/context/request/etag").get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that an unquoted entity tag is invalid
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, setETag.substring(1, setETag.length() - 1))
                .get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that a misquoted entity tag is invalid
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, setETag.substring(0, setETag.length() - 1))
                .get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that a misquoted entity tag is invalid
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, setETag.substring(1, setETag.length())).get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that if an etag is sent that does not match the server etag,
         * that request is allowed to proceed
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"someothervalue\"").get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that if multiple etags are sent that do not match the server
         * etag, that the request is allowed to proceed
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"austin\", \"powers\"").get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that if multiple etags are sent that do not match the server
         * etag, then a 200 and the request entity is returned
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"austin\", \"powers\"").post(null);
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that if multiple etags are sent that do match the server
         * etag, that a 304 is returned
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"austin\", " + setETag + " , \"powers\"")
                .get();
        assertEquals(304, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));

        /*
         * verifies that a request with an If-None-Match header will fail
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_NONE_MATCH, "\"austin\", " + setETag + " , \"powers\"")
                .post(null);
        assertEquals(412, response.getStatusCode());
        assertEquals(setETag, response.getHeaders().getFirst(HttpHeaders.ETAG));
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.client.ClientResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.