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

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


        HttpResponse mockResponse = mock(HttpResponse.class);
        setMockStatusCode(mockResponse, 200);
        when(mockResponse.getAllHeaders()).thenReturn(mockedHeaders);
        when(mockResponse.getEntity()).thenReturn(mockEntity);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getContent(), is("こんにちは"));
    }
View Full Code Here


        HttpEntity mockEntity = mock(HttpEntity.class);
        when(mockEntity.getContentEncoding()).thenReturn(mockContentEncodingHeader);
        when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("こんにちは"));
        HttpResponse mockResponse = createMockResponse(mockEntity);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.getContent(), is(not("こんにちは")));
    }
View Full Code Here

       
        HttpEntity mockEntity = mock(HttpEntity.class);
        when(mockEntity.getContent()).thenReturn(new ByteArrayInputStream(bytes));
        HttpResponse mockResponse = createMockResponse(mockEntity);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.asBytes(), is(bytes));
    }
View Full Code Here

       
        HttpEntity mockEntity = mock(HttpEntity.class);
        when(mockEntity.getContent()).thenReturn(new ByteArrayInputStream(bytes));
        HttpResponse mockResponse = createMockResponse(mockEntity);
       
        Response response = new DefaultResponse(mockResponse, 12345);
       
        assertThat(response.asBytes(), is(bytes));
        assertThat(response.asText(), is("Jeff"));
    }
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

        assertThat(description.toString(), is("Response with body matching: a string containing \"something\""));
    }
   
    @Test
    public void matcherFailsWhenBodyDoesntMatch() {
        Response response = mock(Response.class);
        when(response.getContent()).thenReturn("This the response body, it doesn't contain anything");
       
        assertThat(matcher.matches(response), is(false));
    }
View Full Code Here

        assertThat(matcher.matches(response), is(false));
    }
   
    @Test
    public void matcherPassesWhenBodyMatches() {
        Response response = mock(Response.class);
        when(response.getContent()).thenReturn("This the response body, it contains something");
       
        assertThat(matcher.matches(response), is(true));
    }
View Full Code Here

        assertThat(description.toString(), is("Response with header named 'Header'"));
    }
   
    @Test
    public void matcherShouldFailWhenResponseHasNoHeaders() {
        Response mockResponse = mock(Response.class);
        when(mockResponse.getHeaders()).thenReturn(new ArrayList<Header>());
       
        assertThat(matcher.matches(mockResponse), is(false));
    }
View Full Code Here

    }
   
    @Test
    public void matcherShouldMatchHeaderCaseInsensitively() {
        List<Header> headers = Arrays.asList(new Header("header: value"));
        Response mockResponse = mock(Response.class);
        when(mockResponse.getHeaders()).thenReturn(headers);
       
        assertThat(matcher.matches(mockResponse), is(true));
    }
View Full Code Here

TOP

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

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.