Package org.mockserver.model

Examples of org.mockserver.model.HttpRequest


    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldPreventCallbackAfterForward() {
        // given
        HttpRequest httpRequest = new HttpRequest();
        HttpResponse httpResponse = new HttpResponse();
        HttpCallback httpCallback = new HttpCallback();

        // then
        new Expectation(httpRequest, Times.once()).thenCallback(httpCallback).thenRespond(httpResponse);
View Full Code Here


    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldPreventCallbackAfterResponse() {
        // given
        HttpRequest httpRequest = new HttpRequest();
        HttpCallback httpCallback = new HttpCallback();
        HttpForward httpForward = new HttpForward();

        // then
        new Expectation(httpRequest, Times.once()).thenCallback(httpCallback).thenForward(httpForward);
View Full Code Here

    @Test
    public void shouldWriteAllExpectationsToTheLog() {
        // given
        mockServerMatcher
                .when(
                        new HttpRequest()
                                .withPath("some_path")
                )
                .thenRespond(
                        new HttpResponse()
                                .withBody("some_response_body")
                );
        mockServerMatcher
                .when(
                        new HttpRequest()
                                .withPath("some_other_path")
                )
                .thenRespond(
                        new HttpResponse()
                                .withBody("some_other_response_body")
View Full Code Here

    @Test
    public void shouldWriteOnlyMatchingExpectationsToTheLog() {
        // given
        mockServerMatcher
                .when(
                        new HttpRequest()
                                .withPath("some_path")
                )
                .thenRespond(
                        new HttpResponse()
                                .withBody("some_response_body")
                );
        mockServerMatcher
                .when(
                        new HttpRequest()
                                .withPath("some_other_path")
                )
                .thenRespond(
                        new HttpResponse()
                                .withBody("some_other_response_body")
                );

        // when
        mockServerMatcher.dumpToLog(new HttpRequest().withPath("some_path"));

        // then
        verify(requestLogger).warn("{" + System.getProperty("line.separator") +
                "  \"httpRequest\" : {" + System.getProperty("line.separator") +
                "    \"path\" : \"some_path\"" + System.getProperty("line.separator") +
View Full Code Here

                .withBody("a_callback_response");

        // then
        // - in http
        HttpResponse actual = makeRequest(
                new HttpRequest()
                        .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "callback")
                        .withMethod("POST")
                        .withHeaders(
                                new Header("X-Test", "test_headers_and_body"),
                                new Header("Content-Type", "text/plain")
                        )
                        .withBody("an_example_body_http"),
                false
        );
        assertEquals(
                TestClasspathTestExpectationCallback.httpResponse,
                actual
        );
        assertEquals(TestClasspathTestExpectationCallback.httpRequests.get(0).getBody().getValue(), "an_example_body_http");
        assertEquals(TestClasspathTestExpectationCallback.httpRequests.get(0).getPath(), "/callback");

        // - in https
        assertEquals(
                TestClasspathTestExpectationCallback.httpResponse,
                makeRequest(
                        new HttpRequest()
                                .withURL("https://localhost:" + getMockServerSecurePort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "callback")
                                .withMethod("POST")
                                .withHeaders(
                                        new Header("X-Test", "test_headers_and_body"),
                                        new Header("Host", "127.0.0.1:" + getTestServerPort()),
View Full Code Here

    }

    @Test
    public void respondWhenPathMatchesMultipleSequentialExpectation() {
        // when
        mockServerMatcher.when(new HttpRequest().withPath("somepath")).thenRespond(httpResponse[0].withBody("somebody1"));
        mockServerMatcher.when(new HttpRequest().withPath("somepath")).thenRespond(httpResponse[1].withBody("somebody2"));
        mockServerMatcher.when(new HttpRequest().withPath("somepath")).thenRespond(httpResponse[2].withBody("somebody3"));

        // then
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[1], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[2], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
    }
View Full Code Here

    }

    @Test
    public void respondWhenPathMatchesExpectationWithMultipleResponses() {
        // when
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.exactly(2)).thenRespond(httpResponse[0].withBody("somebody1"));
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.exactly(1)).thenRespond(httpResponse[1].withBody("somebody2"));
        mockServerMatcher.when(new HttpRequest().withPath("somepath")).thenRespond(httpResponse[2].withBody("somebody3"));

        // then
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[1], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[2], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
    }
View Full Code Here

    }

    @Test
    public void respondWhenPathMatchesMultipleDifferentResponses() {
        // when
        mockServerMatcher.when(new HttpRequest().withPath("somepath1")).thenRespond(httpResponse[0].withBody("somebody1"));
        mockServerMatcher.when(new HttpRequest().withPath("somepath2")).thenRespond(httpResponse[1].withBody("somebody2"));

        // then
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath1")));
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath1")));
        assertEquals(httpResponse[1], mockServerMatcher.handle(new HttpRequest().withPath("somepath2")));
        assertEquals(httpResponse[1], mockServerMatcher.handle(new HttpRequest().withPath("somepath2")));
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath1")));
        assertEquals(httpResponse[1], mockServerMatcher.handle(new HttpRequest().withPath("somepath2")));
    }
View Full Code Here

    }

    @Test
    public void doesNotRespondAfterMatchesFinishedExpectedTimes() {
        // when
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.exactly(2)).thenRespond(httpResponse[0].withBody("somebody"));

        // then
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse[0], mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertNull(mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
    }
View Full Code Here

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

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

        // then
        assertEquals(httpResponse, mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertEquals(httpResponse, mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
        assertArrayEquals(new Expectation[]{}, mockServerMatcher.expectations.toArray());
        assertEquals(null, mockServerMatcher.handle(new HttpRequest().withPath("somepath")));
    }
View Full Code Here

TOP

Related Classes of org.mockserver.model.HttpRequest

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.