Package org.mockserver.model

Examples of org.mockserver.model.Header


                                .withPath("/get_books")
                )
                .respond(
                        response()
                                .withHeaders(
                                        new Header("Content-Type", "application/json")
                                )
                                .withBody("" +
                                        "[" + System.getProperty("line.separator") +
                                        "    {" + System.getProperty("line.separator") +
                                        "        \"id\": \"1\"," + System.getProperty("line.separator") +
View Full Code Here


                                )
                )
                .respond(
                        response()
                                .withHeaders(
                                        new Header("Content-Type", "application/json")
                                )
                                .withBody("" +
                                        "{" + System.getProperty("line.separator") +
                                        "    \"id\": \"1\"," + System.getProperty("line.separator") +
                                        "    \"title\": \"Xenophon's imperial fiction : on the education of Cyrus\"," + System.getProperty("line.separator") +
View Full Code Here

        HttpResponse httpResponse = new ApacheHttpClientToMockServerResponseMapper().mapApacheHttpClientResponseToMockServerResponse(httpClientResponse, false);

        // then
        assertEquals(httpResponse.getStatusCode(), new Integer(500));
        assertThat(httpResponse.getHeaders(), containsInAnyOrder(
                new Header("header_name", "header_value"),
                new Header("Set-Cookie", "cookie_name=cookie_value")
        ));
        assertEquals(httpResponse.getCookies(), Arrays.asList(
                new Cookie("cookie_name", "cookie_value")
        ));
        assertEquals(httpResponse.getBodyAsString(), "some_other_body");
View Full Code Here

        // when
        HttpResponse httpResponse = new ApacheHttpClientToMockServerResponseMapper().mapApacheHttpClientResponseToMockServerResponse(httpClientResponse, false);

        // then
        assertEquals(httpResponse.getHeaders(), Arrays.asList(
                new Header("header_name", "header_value")
        ));
    }
View Full Code Here

                                .withCallbackClass("org.mockserver.integration.callback.StaticTestExpectationCallback")
                );
        StaticTestExpectationCallback.httpResponse = new HttpResponse()
                .withStatusCode(HttpStatusCode.ACCEPTED_202.code())
                .withHeaders(
                        new Header("x-callback", "test_callback_header")
                )
                .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(
                StaticTestExpectationCallback.httpResponse,
                actual
        );
        assertEquals(StaticTestExpectationCallback.httpRequests.get(0).getBody().getValue(), "an_example_body_http");
        assertEquals(StaticTestExpectationCallback.httpRequests.get(0).getPath(), "/callback");

        // - in https
        assertEquals(
                StaticTestExpectationCallback.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()),
                                        new Header("Accept-Encoding", "gzip,deflate"),
                                        new Header("Content-Type", "text/plain")
                                )
                                .withBody("an_example_body_https"),
                        false
                )
        );
View Full Code Here

        Map<String, Header> mappedHeaders = new HashMap<String, Header>();
        for (org.apache.http.Header header : clientResponse.getAllHeaders()) {
            if (mappedHeaders.containsKey(header.getName())) {
                mappedHeaders.get(header.getName()).addValue(header.getValue());
            } else {
                mappedHeaders.put(header.getName(), new Header(header.getName(), header.getValue()));
            }
        }
        List<Header> headers = new ArrayList<Header>(mappedHeaders.values());
        List<String> headersToRemove = Arrays.asList("Content-Encoding", "Content-Length", "Transfer-Encoding");
        for (Header header : new ArrayList<Header>(headers)) {
View Full Code Here

    @Test
    public void shouldReturnValueSetInConstructor() {
        // given
        BodyDTO body = BodyDTO.createDTO(exact("body"));
        List<CookieDTO> cookies = Arrays.asList(new CookieDTO(new Cookie("name", "value")));
        List<HeaderDTO> headers = Arrays.asList(new HeaderDTO(new Header("name", "value")));
        String method = "METHOD";
        String path = "path";
        List<ParameterDTO> queryStringParameters = Arrays.asList(new ParameterDTO(new Parameter("name", "value")));
        String url = "url";
        HttpRequest httpRequest = new HttpRequest()
                .withBody("body")
                .withCookies(new Cookie("name", "value"))
                .withHeaders(new Header("name", "value"))
                .withMethod(method)
                .withPath(path)
                .withQueryStringParameter(new Parameter("name", "value"))
                .withURL(url);
View Full Code Here

    @Test
    public void shouldBuildObject() {
        // given
        String body = "body";
        Cookie cookie = new Cookie("name", "value");
        Header header = new Header("name", "value");
        String method = "METHOD";
        String path = "path";
        Parameter parameter = new Parameter("name", "value");
        String url = "url";
        HttpRequest httpRequest = new HttpRequest()
View Full Code Here

public class HeaderDTOTest {

    @Test
    public void shouldReturnValueSetInConstructor() {
        // when
        HeaderDTO header = new HeaderDTO(new Header("first", "first_one", "first_two"));

        // then
        assertThat(header.getValues(), containsInAnyOrder("first_one", "first_two"));
        assertThat(header.buildObject().getValues(), containsInAnyOrder("first_one", "first_two"));
    }
View Full Code Here

    @Test
    public void shouldReturnValueSetInConstructor() {
        // given
        BodyDTO body = BodyDTO.createDTO(exact("body"));
        List<CookieDTO> cookies = Arrays.asList(new CookieDTO(new Cookie("name", "value")));
        List<HeaderDTO> headers = Arrays.asList(new HeaderDTO(new Header("name", "value")));
        Integer statusCode = 200;
        HttpResponse httpRequest = new HttpResponse()
                .withBody("body")
                .withCookies(new Cookie("name", "value"))
                .withHeaders(new Header("name", "value"))
                .withStatusCode(statusCode);

        // when
        HttpResponseDTO httpRequestDTO = new HttpResponseDTO(httpRequest);
View Full Code Here

TOP

Related Classes of org.mockserver.model.Header

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.