Package org.mockserver.mock

Examples of org.mockserver.mock.Expectation


        if (httpRequest != null) {
            HttpRequestMatcher httpRequestMatcher = matcherBuilder.transformsToMatcher(httpRequest);
            for (HttpRequest key : requestResponseLog.keySet()) {
                for (HttpResponse value : requestResponseLog.getAll(key)) {
                    if (httpRequestMatcher.matches(key)) {
                        expectations.add(new Expectation(key, Times.once()).thenRespond(value));
                    }
                }
            }
        } else {
            for (HttpRequest key : requestResponseLog.keySet()) {
                for (HttpResponse value : requestResponseLog.getAll(key)) {
                    expectations.add(new Expectation(key, Times.once()).thenRespond(value));
                }
            }
        }
        return expectations.toArray(new Expectation[expectations.size()]);
    }
View Full Code Here


        HttpResponse httpResponse = new HttpResponse().withBody("some_response_body");
        HttpForward httpForward = new HttpForward().withHost("some_host");
        HttpCallback httpCallback = new HttpCallback().withCallbackClass("some_class");

        // when
        ExpectationDTO expectationWithResponse = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenRespond(httpResponse));

        // then
        assertThat(expectationWithResponse.getHttpRequest(), is(new HttpRequestDTO(httpRequest)));
        assertThat(expectationWithResponse.getTimes(), is(new TimesDTO(Times.exactly(3))));
        assertThat(expectationWithResponse.getHttpResponse(), is(new HttpResponseDTO(httpResponse)));
        assertNull(expectationWithResponse.getHttpForward());
        assertNull(expectationWithResponse.getHttpCallback());

        // when
        ExpectationDTO expectationWithForward = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenForward(httpForward));

        // then
        assertThat(expectationWithForward.getHttpRequest(), is(new HttpRequestDTO(httpRequest)));
        assertThat(expectationWithForward.getTimes(), is(new TimesDTO(Times.exactly(3))));
        assertNull(expectationWithForward.getHttpResponse());
        assertThat(expectationWithForward.getHttpForward(), is(new HttpForwardDTO(httpForward)));
        assertNull(expectationWithForward.getHttpCallback());

        // when
        ExpectationDTO expectationWithCallback = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenCallback(httpCallback));

        // then
        assertThat(expectationWithCallback.getHttpRequest(), is(new HttpRequestDTO(httpRequest)));
        assertThat(expectationWithCallback.getTimes(), is(new TimesDTO(Times.exactly(3))));
        assertNull(expectationWithCallback.getHttpResponse());
View Full Code Here

        HttpResponse httpResponse = new HttpResponse().withBody("some_response_body");
        HttpForward httpForward = new HttpForward().withHost("some_host");
        HttpCallback httpCallback = new HttpCallback().withCallbackClass("some_class");

        // when
        Expectation expectationWithResponse = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenRespond(httpResponse)).buildObject();

        // then
        assertThat(expectationWithResponse.getHttpRequest(), is(httpRequest));
        assertThat(expectationWithResponse.getTimes(), is(Times.exactly(3)));
        assertThat(expectationWithResponse.getHttpResponse(false), is(httpResponse));
        assertNull(expectationWithResponse.getHttpForward());
        assertNull(expectationWithResponse.getHttpCallback());

        // when
        Expectation expectationWithForward = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenForward(httpForward)).buildObject();

        // then
        assertThat(expectationWithForward.getHttpRequest(), is(httpRequest));
        assertThat(expectationWithForward.getTimes(), is(Times.exactly(3)));
        assertNull(expectationWithForward.getHttpResponse(false));
        assertThat(expectationWithForward.getHttpForward(), is(httpForward));
        assertNull(expectationWithForward.getHttpCallback());

        // when
        Expectation expectationWithCallback = new ExpectationDTO(new Expectation(httpRequest, Times.exactly(3)).thenCallback(httpCallback)).buildObject();

        // then
        assertThat(expectationWithCallback.getHttpRequest(), is(httpRequest));
        assertThat(expectationWithCallback.getTimes(), is(Times.exactly(3)));
        assertNull(expectationWithCallback.getHttpResponse(false));
        assertNull(expectationWithCallback.getHttpForward());
        assertThat(expectationWithCallback.getHttpCallback(), is(httpCallback));
    }
View Full Code Here

    }

    @Test
    public void shouldBuildObjectWithNulls() {
        // when
        Expectation expectation = new ExpectationDTO(new Expectation(null, null).thenRespond(null).thenForward(null)).buildObject();

        // then
        assertThat(expectation.getHttpRequest(), is(nullValue()));
        assertThat(expectation.getTimes(), is(Times.once()));
        assertThat(expectation.getHttpResponse(false), is(nullValue()));
        assertThat(expectation.getHttpForward(), is(nullValue()));
        assertThat(expectation.getHttpCallback(), is(nullValue()));
    }
View Full Code Here

    }

    @Test
    public void shouldHandleNullFieldInput() {
        // when
        ExpectationDTO expectationDTO = new ExpectationDTO(new Expectation(null, null));

        // then
        assertThat(expectationDTO.getHttpRequest(), is(nullValue()));
        assertThat(expectationDTO.getTimes(), is(nullValue()));
        assertThat(expectationDTO.getHttpResponse(), is(nullValue()));
View Full Code Here

                        "                                new Cookie(\"responseCookieNameTwo\", \"responseCookieValueTwo\")" + System.getProperty("line.separator") +
                        "                        )" + System.getProperty("line.separator") +
                        "                        .withBody(\"responseBody\")" + System.getProperty("line.separator") +
                        "        );",
                expectationSerializer.serializeAsJava(
                        new Expectation(
                                new HttpRequest()
                                        .withMethod("GET")
                                        .withURL("http://www.example.com")
                                        .withPath("somePath")
                                        .withQueryStringParameters(
View Full Code Here

                        "                response()" + System.getProperty("line.separator") +
                        "                        .withStatusCode(200)" + System.getProperty("line.separator") +
                        "                        .withBody(\"responseBody\")" + System.getProperty("line.separator") +
                        "        );",
                expectationSerializer.serializeAsJava(
                        new Expectation(
                                new HttpRequest()
                                        .withBody(
                                                new ParameterBody(
                                                        new Parameter("requestBodyParameterNameOne", "requestBodyParameterValueOneOne", "requestBodyParameterValueOneTwo"),
                                                        new Parameter("requestBodyParameterNameTwo", "requestBodyParameterValueTwo")
View Full Code Here

                        "                response()" + System.getProperty("line.separator") +
                        "                        .withStatusCode(200)" + System.getProperty("line.separator") +
                        "                        .withBody(\"responseBody\")" + System.getProperty("line.separator") +
                        "        );",
                expectationSerializer.serializeAsJava(
                        new Expectation(
                                new HttpRequest()
                                        .withBody(
                                                new BinaryBody(new byte[0])
                                        ),
                                Times.once()
View Full Code Here

                        "                        .withHost(\"some_host\")" + System.getProperty("line.separator") +
                        "                        .withPort(9090)" + System.getProperty("line.separator") +
                        "                        .withScheme(HttpForward.Scheme.HTTPS)" + System.getProperty("line.separator") +
                        "        );",
                expectationSerializer.serializeAsJava(
                        new Expectation(
                                new HttpRequest()
                                        .withMethod("GET")
                                        .withURL("http://www.example.com")
                                        .withPath("somePath")
                                        .withQueryStringParameters(
View Full Code Here

                        "        .thenCallback(" + System.getProperty("line.separator") +
                        "                callback()" + System.getProperty("line.separator") +
                        "                        .withCallbackClass(\"some_class\")" + System.getProperty("line.separator") +
                        "        );",
                expectationSerializer.serializeAsJava(
                        new Expectation(
                                new HttpRequest()
                                        .withMethod("GET")
                                        .withURL("http://www.example.com")
                                        .withPath("somePath")
                                        .withQueryStringParameters(
View Full Code Here

TOP

Related Classes of org.mockserver.mock.Expectation

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.