Package org.mockserver.model

Examples of org.mockserver.model.HttpResponse


    @Test(expected = RuntimeException.class)
    public void shouldHandleExceptionWhenReadingBody() throws IOException {
        // given
        // - an HttpResponse
        HttpResponse httpResponse = new HttpResponse();
        httpResponse.withStatusCode(HttpStatusCode.OK_200.code());
        httpResponse.withBody("somebody");
        httpResponse.withHeaders(new Header("headerName1", "headerValue1"), new Header("headerName2", "headerValue2"));
        httpResponse.withCookies(new Cookie("cookieName1", "cookieValue1"), new Cookie("cookieName2", "cookieValue2"));
        // - an HttpServletResponse
        HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
        when(httpServletResponse.getOutputStream()).thenThrow(new IOException("TEST EXCEPTION"));

        // when
View Full Code Here


    private HttpResponse[] httpResponse;

    @Before
    public void prepareTestFixture() {
        httpResponse = new HttpResponse[]{
                new HttpResponse(),
                new HttpResponse(),
                new HttpResponse()
        };
        mockServerMatcher = new MockServerMatcher();
    }
View Full Code Here

    }

    @Test
    public void shouldRemoveExpectationWhenNoMoreTimes() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");

        // when
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.exactly(2)).thenRespond(httpResponse);

        // then
View Full Code Here

    @Test
    public void shouldMapMockServerResponseToNettyResponse() {
        // given
        // - an HttpResponse
        HttpResponse httpResponse = new HttpResponse();
        httpResponse.withStatusCode(HttpStatusCode.OK_200.code());
        httpResponse.withBody("somebody");
        httpResponse.withHeaders(new Header("headerName1", "headerValue1"), new Header("headerName2", "headerValue2_1", "headerValue2_2"));
        httpResponse.withCookies(new Cookie("cookieName1", "cookieValue1"), new Cookie("cookieName2", "cookieValue2"));

        // when
        DefaultFullHttpResponse defaultFullHttpResponse = new MockServerToNettyResponseMapper().mapMockServerResponseToNettyResponse(httpResponse);

        // then
View Full Code Here

    @Test
    public void shouldMapMockServerResponseWithNullValuesToNettyResponse() {
        // given
        // - an HttpResponse
        HttpResponse httpResponse = new HttpResponse();
        httpResponse.withStatusCode(null);
        httpResponse.withBody((byte[]) null);
        httpResponse.withHeaders((Header[]) null);
        httpResponse.withCookies((Cookie[]) null);

        // when
        DefaultFullHttpResponse defaultFullHttpResponse = new MockServerToNettyResponseMapper().mapMockServerResponseToNettyResponse(httpResponse);

        // then
View Full Code Here

    @Test
    public void shouldCallMatchingFiltersAfterForwardingRequest() throws Exception {
        // given
        Filters filters = new Filters();
        HttpResponse httpResponse = new HttpResponse();
        // add first filter
        HttpRequest httpRequest = new HttpRequest();
        ProxyResponseFilter filter = mock(ProxyResponseFilter.class);
        when(filter.onResponse(any(HttpRequest.class), any(HttpResponse.class))).thenReturn(new HttpResponse());
        filters.withFilter(httpRequest, filter);
        // add first filter with other request
        HttpRequest someOtherRequest = new HttpRequest().withPath("some_other_path");
        filters.withFilter(someOtherRequest, filter);
        // add second filter
View Full Code Here

    @Test(expected = IllegalStateException.class)
    public void shouldThrowIllegalStateExceptionIfHttpResponseIsNull() throws Exception {
        // given
        Filters filters = new Filters();
        HttpResponse httpResponse = new HttpResponse();
        // add first filter
        HttpRequest httpRequest = new HttpRequest();
        ProxyResponseFilter filter = mock(ProxyResponseFilter.class);
        when(filter.onResponse(any(HttpRequest.class), any(HttpResponse.class))).thenReturn(null);
        filters.withFilter(httpRequest, filter);
View Full Code Here

    }

    @Test
    public void shouldSendFullPOSTRequest() throws Exception {
        // given
        HttpResponse httpResponse = new HttpResponse().withStatusCode(200).withBody("exampleResponse");
        when(apacheHttpClientToMockServerResponseMapper.mapApacheHttpClientResponseToMockServerResponse(closeableHttpResponse, false)).thenReturn(httpResponse);

        // when
        HttpResponse httpResponseActual = apacheHttpClient.sendRequest(new HttpRequest()
                        .withMethod("POST")
                        .withURL("http://host:8080/path")
                        .withPath("/path")
                        .withQueryStringParameters(
                                new Parameter("paramOneName", "paramOneValueOne", "paramOneValueTwo"),
View Full Code Here

    }

    @Test
    public void shouldSendBarePOSTRequest() throws Exception {
        // given
        HttpResponse httpResponse = new HttpResponse().withStatusCode(200).withBody("exampleResponse");
        when(apacheHttpClientToMockServerResponseMapper.mapApacheHttpClientResponseToMockServerResponse(closeableHttpResponse, false)).thenReturn(httpResponse);

        // when
        HttpResponse httpResponseActual = apacheHttpClient.sendRequest(new HttpRequest()
                        .withMethod("POST")
                        .withURL("http://host:8080/path"),
                false
        );
View Full Code Here

    }

    @Test
    public void shouldHandleCircularRedirectException() throws Exception {
        // given
        HttpResponse httpResponse = new HttpResponse().withStatusCode(200).withBody("exampleResponse");
        when(apacheHttpClientToMockServerResponseMapper.mapApacheHttpClientResponseToMockServerResponse(closeableHttpResponse, false)).thenReturn(httpResponse);
        when(httpClient.execute(any(HttpUriRequest.class))).thenThrow(new IOException("TEST EXCEPTION", new CircularRedirectException("TEST EXCEPTION")));

        // then
        assertEquals(new HttpResponse(), apacheHttpClient.sendRequest(new HttpRequest()
                        .withMethod("POST")
                        .withURL("http://host:8080/path")
                        .withHeaders(
                                new org.mockserver.model.Header(HTTP.CONTENT_LEN, "0")
                        )
View Full Code Here

TOP

Related Classes of org.mockserver.model.HttpResponse

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.