Package org.mockserver.model

Examples of org.mockserver.model.Header


    @Test
    public void shouldBuildObject() {
        // given
        String body = "body";
        Cookie cookie = new Cookie("name", "value");
        Header header = new Header("name", "value");
        Integer statusCode = 200;
        HttpResponse httpRequest = new HttpResponse()
                .withBody(body)
                .withCookies(cookie)
                .withHeaders(header)
View Full Code Here


        assertFalse(new HttpResponseMatcher(new HttpResponse().withBody(binary("some binary value".getBytes()))).matches(new HttpResponse().withBody(matched)));
    }

    @Test
    public void matchesMatchingHeaders() {
        assertTrue(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name", "value"))));
    }
View Full Code Here

        assertTrue(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name", "value"))));
    }

    @Test
    public void matchesMatchingHeadersWithRegex() {
        assertTrue(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", ".*"))).matches(new HttpResponse().withHeaders(new Header("name", "value"))));
    }
View Full Code Here

        assertTrue(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", ".*"))).matches(new HttpResponse().withHeaders(new Header("name", "value"))));
    }

    @Test
    public void doesNotMatchIncorrectHeaderName() {
        assertFalse(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name1", "value"))));
    }
View Full Code Here

        assertFalse(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name1", "value"))));
    }

    @Test
    public void doesNotMatchIncorrectHeaderValue() {
        assertFalse(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name", "value1"))));
    }
View Full Code Here

        assertFalse(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "value"))).matches(new HttpResponse().withHeaders(new Header("name", "value1"))));
    }

    @Test
    public void doesNotMatchIncorrectHeaderValueRegex() {
        assertFalse(new HttpResponseMatcher(new HttpResponse().withHeaders(new Header("name", "[0-9]{0,100}"))).matches(new HttpResponse().withHeaders(new Header("name", "value1"))));
    }
View Full Code Here

                        "  } ]" + System.getProperty("line.separator") +
                        "}",
                new HttpResponseMatcher(
                        response()
                                .withBody("some_body")
                                .withHeaders(new Header("name", "value"))
                                .withCookies(new Cookie("name", "[A-Z]{0,10}"))
                ).toString()
        );
    }
View Full Code Here

                        "  } ]" + System.getProperty("line.separator") +
                        "}",
                new HttpResponseMatcher(
                        response()
                                .withBody(json("{ \"key\": \"some_value\" }"))
                                .withHeaders(new Header("name", "value"))
                                .withCookies(new Cookie("name", "[A-Z]{0,10}"))
                ).toString()
        );
    }
View Full Code Here

    @Test
    public void shouldNotForwardHopByHopHeaders() throws Exception {
        // given
        httpRequest.withHeaders(
                new Header("some_other_header"),
                new Header("proxy-connection"),
                new Header("connection"),
                new Header("keep-alive"),
                new Header("transfer-encoding"),
                new Header("te"),
                new Header("trailer"),
                new Header("proxy-authorization"),
                new Header("proxy-authenticate"),
                new Header("upgrade")
        );

        // when
        proxyServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
View Full Code Here

                                .withCallbackClass("org.mockserver.server.TestClasspathTestExpectationCallback")
                );
        TestClasspathTestExpectationCallback.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(
                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()),
                                        new Header("Accept-Encoding", "gzip,deflate"),
                                        new Header("Content-Type", "text/plain")
                                )
                                .withBody("an_example_body_https"),
                        false
                )
        );
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.