Package com.github.restdriver.serverdriver.http.response

Examples of com.github.restdriver.serverdriver.http.response.DefaultResponse


        try {
            long startTime = System.currentTimeMillis();
            response = httpClient.execute(httpUriRequest);
            long endTime = System.currentTimeMillis();
           
            return new DefaultResponse(response, (endTime - startTime));
           
        } catch (ClientProtocolException cpe) {
            throw new RuntimeClientProtocolException(cpe);
           
        } catch (UnknownHostException uhe) {
View Full Code Here


    public void asJsonErrorGivesClearMessage() throws IOException {
       
        HttpEntity mockEntity = mock(HttpEntity.class);
        when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("This is not really json, is it?", "utf-8"));
        HttpResponse mockResponse = createMockResponse(mockEntity);
        Response response = new DefaultResponse(mockResponse, 12345);
       
        try {
            response.asJson();
            Assert.fail();
           
        } catch (RuntimeMappingException rme) {
            assertThat(rme.getMessage(), is("Can't parse JSON.  Bad content >> This is not real..."));
           
View Full Code Here

    public void asXmlErrorGivesClearMessage() throws IOException {
       
        HttpEntity mockEntity = mock(HttpEntity.class);
        when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("This is not really xml, is it?", "utf-8"));
        HttpResponse mockResponse = createMockResponse(mockEntity);
        Response response = new DefaultResponse(mockResponse, 12345);
       
        try {
            response.asXml();
            Assert.fail();
           
        } catch (RuntimeXmlParseException rxpe) {
            assertThat(rxpe.getMessage(), is("Can't parse XML.  Bad content >> This is not real..."));
           
View Full Code Here

    public void statusCodeIsTakenFromApacheClass() {
        HttpResponse mockResponse = mock(HttpResponse.class);
        setMockStatusCode(mockResponse, 456);
        when(mockResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[0]);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getStatusCode(), is(456));
    }
View Full Code Here

    public void responseTimeIsReportedCorrectly() {
        HttpResponse mockResponse = mock(HttpResponse.class);
        setMockStatusCode(mockResponse, 456);
        when(mockResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[0]);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getResponseTime(), is(12345L));
    }
View Full Code Here

       
        Header[] mockedHeaders = new Header[] { new BasicHeader("headerA", "valueA") };
       
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getHeaders(), Matchers.<Object> hasSize(1));
        assertThat(response.getHeaders().get(0), equalTo(header("headerA", "valueA")));
    }
View Full Code Here

       
        Header[] mockedHeaders = new Header[] {};
       
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getHeader("myheader"), nullValue());
        assertThat(response.getHeaders("myheader").size(), is(0));
    }
View Full Code Here

       
        Header[] mockedHeaders = new Header[] { new BasicHeader("myheader", "myValue") };
       
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        com.github.restdriver.serverdriver.http.Header expectedHeader =
                new com.github.restdriver.serverdriver.http.Header("myheader", "myValue");
       
        assertThat(response.getHeader("myheader"), equalTo(expectedHeader));
        assertThat(response.getHeaders("myheader").size(), equalTo(1));
    }
View Full Code Here

        };
       
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
       
        // throws exception
        new DefaultResponse(mockResponse, 12345).getHeader("myheader");
    }
View Full Code Here

                new BasicHeader("myheader", "myOtherValue")
        };
       
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getHeaders("myheader").size(), is(2));
    }
View Full Code Here

TOP

Related Classes of com.github.restdriver.serverdriver.http.response.DefaultResponse

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.