Package org.mockserver.model

Examples of org.mockserver.model.HttpRequest


    @Test
    public void shouldClearAllExpectations() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.clear(new HttpRequest().withPath("somepath"));

        // then
        assertArrayEquals(new Expectation[]{}, mockServerMatcher.expectations.toArray());
    }
View Full Code Here


    @Test
    public void shouldResetAllExpectationsWhenHttpRequestNull() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.clear(null);

        // then
View Full Code Here

    @Test
    public void shouldResetAllExpectations() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);
        mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.reset();

        // then
View Full Code Here

    @Test
    public void shouldClearMatchingExpectationsByPathOnly() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withPath("abc"), Times.unlimited()).thenRespond(httpResponse);
        Expectation expectation = mockServerMatcher.when(new HttpRequest().withPath("def"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.clear(new HttpRequest().withPath("abc"));

        // then
        assertArrayEquals(new Expectation[]{expectation}, mockServerMatcher.expectations.toArray());
    }
View Full Code Here

    @Test
    public void shouldClearMatchingExpectationsByMethodOnly() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withMethod("GET").withPath("abc"), Times.unlimited()).thenRespond(httpResponse);
        mockServerMatcher.when(new HttpRequest().withMethod("GET").withPath("def"), Times.unlimited()).thenRespond(httpResponse);
        Expectation expectation = mockServerMatcher.when(new HttpRequest().withMethod("POST").withPath("def"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.clear(new HttpRequest().withMethod("GET"));

        // then
        assertArrayEquals(new Expectation[]{expectation}, mockServerMatcher.expectations.toArray());
    }
View Full Code Here

    @Test
    public void shouldClearMatchingExpectationsByHeaderOnly() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        mockServerMatcher.when(new HttpRequest().withMethod("GET").withPath("abc").withHeader(new Header("headerOneName", "headerOneValue")), Times.unlimited()).thenRespond(httpResponse);
        mockServerMatcher.when(new HttpRequest().withMethod("PUT").withPath("def").withHeaders(new Header("headerOneName", "headerOneValue")), Times.unlimited()).thenRespond(httpResponse);
        Expectation expectation = mockServerMatcher.when(new HttpRequest().withMethod("POST").withPath("def"), Times.unlimited()).thenRespond(httpResponse);

        // when
        mockServerMatcher.clear(new HttpRequest().withHeader(new Header("headerOneName", "headerOneValue")));

        // then
        assertArrayEquals(new Expectation[]{expectation}, mockServerMatcher.expectations.toArray());
    }
View Full Code Here

    @Test
    public void shouldClearNoExpectations() {
        // given
        HttpResponse httpResponse = new HttpResponse().withBody("somebody");
        Expectation[] expectations = new Expectation[]{
                mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse),
                mockServerMatcher.when(new HttpRequest().withPath("somepath"), Times.unlimited()).thenRespond(httpResponse)
        };

        // when
        mockServerMatcher.clear(new HttpRequest().withPath("foobar"));

        // then
        assertArrayEquals(expectations, mockServerMatcher.expectations.toArray());
    }
View Full Code Here

    @Test
    public void shouldCallMatchingFiltersBeforeForwardingRequest() throws Exception {
        // given
        Filters filters = new Filters();
        // add first filter
        HttpRequest httpRequest = new HttpRequest();
        ProxyRequestFilter filter = mock(ProxyRequestFilter.class);
        filters.withFilter(httpRequest, filter);
        // add first filter with other request
        HttpRequest someOtherRequest = new HttpRequest().withPath("some_other_path");
        filters.withFilter(someOtherRequest, filter);
        // add second filter
        ProxyRequestFilter someOtherFilter = mock(ProxyRequestFilter.class);
        filters.withFilter(someOtherRequest, someOtherFilter);
View Full Code Here

    public void shouldCallMatchingFiltersAfterForwardingRequest() throws Exception {
        // given
        Filters filters = new Filters();
        HttpResponse httpResponse = new HttpResponse();
        // add first filter
        HttpRequest httpRequest = new HttpRequest();
        ProxyResponseFilter filter = mock(ProxyResponseFilter.class);
        when(filter.onResponse(any(HttpRequest.class), any(HttpResponse.class))).thenReturn(new HttpResponse());
        filters.withFilter(httpRequest, filter);
        // add first filter with other request
        HttpRequest someOtherRequest = new HttpRequest().withPath("some_other_path");
        filters.withFilter(someOtherRequest, filter);
        // add second filter
        ProxyResponseFilter someOtherFilter = mock(ProxyResponseFilter.class);
        filters.withFilter(someOtherRequest, someOtherFilter);
View Full Code Here

    public void shouldThrowIllegalStateExceptionIfHttpResponseIsNull() throws Exception {
        // given
        Filters filters = new Filters();
        HttpResponse httpResponse = new HttpResponse();
        // add first filter
        HttpRequest httpRequest = new HttpRequest();
        ProxyResponseFilter filter = mock(ProxyResponseFilter.class);
        when(filter.onResponse(any(HttpRequest.class), any(HttpResponse.class))).thenReturn(null);
        filters.withFilter(httpRequest, filter);

        // when
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.