Package org.mockserver.model

Examples of org.mockserver.model.StringBody


        // when
        proxyClient
                .verify(
                        new HttpRequest()
                                .withPath("/some_path")
                                .withBody(new StringBody("some_request_body", Body.Type.STRING)),
                        Times.atLeast(1)
                );

        // no assertion exception thrown
    }
View Full Code Here


        // when
        proxyClient
                .verify(
                        new HttpRequest()
                                .withPath("/some_path")
                                .withBody(new StringBody("some_request_body", Body.Type.STRING)),
                        Times.exactly(2)
                );
    }
View Full Code Here

                        .withBody("some_body"),
                makeRequest(
                        new HttpRequest()
                                .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_path")
                                .withMethod("POST")
                                .withBody(new StringBody("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<bookstore>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"COOKING\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Everyday Italian</title>" + System.getProperty("line.separator") +
                                        "  <author>Giada De Laurentiis</author>" + System.getProperty("line.separator") +
                                        "  <year>2005</year>" + System.getProperty("line.separator") +
                                        "  <price>30.00</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"CHILDREN\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Harry Potter</title>" + System.getProperty("line.separator") +
                                        "  <author>J K. Rowling</author>" + System.getProperty("line.separator") +
                                        "  <year>2005</year>" + System.getProperty("line.separator") +
                                        "  <price>29.99</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"WEB\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Learning XML</title>" + System.getProperty("line.separator") +
                                        "  <author>Erik T. Ray</author>" + System.getProperty("line.separator") +
                                        "  <year>2003</year>" + System.getProperty("line.separator") +
                                        "  <price>39.95</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "</bookstore>", Body.Type.STRING)),
                        false
                )
        );
        // - in https
        assertEquals(
                new HttpResponse()
                        .withStatusCode(HttpStatusCode.OK_200.code())
                        .withBody("some_body"),
                makeRequest(
                        new HttpRequest()
                                .withURL("https://localhost:" + getMockServerSecurePort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_path")
                                .withMethod("POST")
                                .withBody(new StringBody("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<bookstore>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"COOKING\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Everyday Italian</title>" + System.getProperty("line.separator") +
View Full Code Here

                makeRequest(
                        new HttpRequest()
                                .withMethod("POST")
                                .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_pathRequest")
                                .withPath("/some_pathRequest")
                                .withBody(new StringBody("bodyParameterOneName=Parameter+One+Value+One" +
                                        "&bodyParameterOneName=Parameter+One+Value+Two" +
                                        "&bodyParameterTwoName=Parameter+Two", Body.Type.STRING))
                                .withHeaders(new Header("headerNameRequest", "headerValueRequest"))
                                .withCookies(new Cookie("cookieNameRequest", "cookieValueRequest")),
                        false
View Full Code Here

        mockServerClient
                .when(
                        new HttpRequest()
                                .withMethod("PUT")
                                .withPath("/some_pathRequest")
                                .withBody(new StringBody("bodyParameterOneName=Parameter+One+Value+One" +
                                        "&bodyParameterOneName=Parameter+One+Value+Two" +
                                        "&bodyParameterTwoName=Parameter+Two", Body.Type.STRING))
                                .withHeaders(new Header("headerNameRequest", "headerValueRequest"))
                                .withCookies(new Cookie("cookieNameRequest", "cookieValueRequest"))
                )
                .respond(
                        new HttpResponse()
                                .withStatusCode(HttpStatusCode.ACCEPTED_202.code())
                                .withBody("some_bodyResponse")
                                .withHeaders(new Header("headerNameResponse", "headerValueResponse"))
                                .withCookies(new Cookie("cookieNameResponse", "cookieValueResponse"))
                );

        // then
        // - in http - body string
        assertEquals(
                new HttpResponse()
                        .withStatusCode(HttpStatusCode.ACCEPTED_202.code())
                        .withBody("some_bodyResponse")
                        .withCookies(new Cookie("cookieNameResponse", "cookieValueResponse"))
                        .withHeaders(
                                new Header("headerNameResponse", "headerValueResponse"),
                                new Header("Set-Cookie", "cookieNameResponse=cookieValueResponse")
                        ),
                makeRequest(
                        new HttpRequest()
                                .withMethod("PUT")
                                .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_pathRequest")
                                .withPath("/some_pathRequest")
                                .withBody(new StringBody("bodyParameterOneName=Parameter+One+Value+One" +
                                        "&bodyParameterOneName=Parameter+One+Value+Two" +
                                        "&bodyParameterTwoName=Parameter+Two", Body.Type.STRING))
                                .withHeaders(
                                        new Header("headerNameRequest", "headerValueRequest"),
                                        new Header("Cookie", "cookieNameRequest=cookieValueRequest")
View Full Code Here

    }

    @Test
    public void clientCanCallServerNegativeMatchXPathBodyOnly() {
        // when
        mockServerClient.when(new HttpRequest().withBody(new StringBody("/bookstore/book[price>35]/price", Body.Type.XPATH)), exactly(2)).respond(new HttpResponse().withBody("some_body"));

        // then
        // - in http
        assertEquals(
                new HttpResponse()
                        .withStatusCode(HttpStatusCode.NOT_FOUND_404.code()),
                makeRequest(
                        new HttpRequest()
                                .withURL("https://localhost:" + getMockServerSecurePort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_path")
                                .withMethod("POST")
                                .withBody(new StringBody("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<bookstore>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"COOKING\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Everyday Italian</title>" + System.getProperty("line.separator") +
                                        "  <author>Giada De Laurentiis</author>" + System.getProperty("line.separator") +
                                        "  <year>2005</year>" + System.getProperty("line.separator") +
                                        "  <price>30.00</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"CHILDREN\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Harry Potter</title>" + System.getProperty("line.separator") +
                                        "  <author>J K. Rowling</author>" + System.getProperty("line.separator") +
                                        "  <year>2005</year>" + System.getProperty("line.separator") +
                                        "  <price>29.99</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"WEB\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Learning XML</title>" + System.getProperty("line.separator") +
                                        "  <author>Erik T. Ray</author>" + System.getProperty("line.separator") +
                                        "  <year>2003</year>" + System.getProperty("line.separator") +
                                        "  <price>31.95</price>" + System.getProperty("line.separator") +
                                        "</book>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "</bookstore>", Body.Type.STRING)),
                        false
                )
        );
        // - in https
        assertEquals(
                new HttpResponse()
                        .withStatusCode(HttpStatusCode.NOT_FOUND_404.code()),
                makeRequest(
                        new HttpRequest()
                                .withURL("https://localhost:" + getMockServerSecurePort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_path")
                                .withMethod("POST")
                                .withBody(new StringBody("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<bookstore>" + System.getProperty("line.separator") +
                                        "" + System.getProperty("line.separator") +
                                        "<book category=\"COOKING\">" + System.getProperty("line.separator") +
                                        "  <title lang=\"en\">Everyday Italian</title>" + System.getProperty("line.separator") +
View Full Code Here

                makeRequest(
                        new HttpRequest()
                                .withMethod("POST")
                                .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_pathRequest")
                                .withPath("/some_pathRequest")
                                .withBody(new StringBody("OTHERBodyParameterOneName=Parameter+One+Value+One" +
                                        "&bodyParameterOneName=Parameter+One+Value+Two" +
                                        "&bodyParameterTwoName=Parameter+Two", Body.Type.STRING))
                                .withHeaders(new Header("headerNameRequest", "headerValueRequest"))
                                .withCookies(new Cookie("cookieNameRequest", "cookieValueRequest")),
                        false
View Full Code Here

                makeRequest(
                        new HttpRequest()
                                .withMethod("POST")
                                .withURL("http://localhost:" + getMockServerPort() + "/" + servletContext + (servletContext.length() > 0 && !servletContext.endsWith("/") ? "/" : "") + "some_pathRequest")
                                .withPath("/some_pathRequest")
                                .withBody(new StringBody("bodyParameterOneName=Other Parameter+One+Value+One" +
                                        "&bodyParameterOneName=Parameter+One+Value+Two" +
                                        "&bodyParameterTwoName=Parameter+Two", Body.Type.STRING))
                                .withHeaders(new Header("headerNameRequest", "headerValueRequest"))
                                .withCookies(new Cookie("cookieNameRequest", "cookieValueRequest")),
                        false
View Full Code Here

public class StringBodyDTOTest {

    @Test
    public void shouldReturnValueSetInConstructor() {
        // when
        StringBodyDTO stringBody = new StringBodyDTO(new StringBody("some_body", Body.Type.STRING));

        // then
        assertThat(stringBody.getValue(), is("some_body"));
        assertThat(stringBody.getType(), is(Body.Type.STRING));
    }
View Full Code Here

    }

    @Test
    public void shouldBuildCorrectObject() {
        // when
        StringBody stringBody = new StringBodyDTO(new StringBody("some_body", Body.Type.XPATH)).buildObject();

        // then
        assertThat(stringBody.getValue(), is("some_body"));
        assertThat(stringBody.getType(), is(Body.Type.XPATH));
    }
View Full Code Here

TOP

Related Classes of org.mockserver.model.StringBody

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.