package org.mockserver.integration.server; import org.junit.Test; import org.mockserver.integration.callback.StaticTestExpectationCallback; import org.mockserver.model.HttpStatusCode; import static org.junit.Assert.assertEquals; import static org.mockserver.model.Header.header; import static org.mockserver.model.HttpClassCallback.callback; import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; /** * @author jamesdbloom */ public abstract class SameJVMAbstractClientServerIntegrationTest extends AbstractClientServerIntegrationTest { @Test public void shouldCallbackToSpecifiedClassWithResponseOnStaticField() { // given StaticTestExpectationCallback.httpRequests.clear(); StaticTestExpectationCallback.httpResponse = response() .withStatusCode(HttpStatusCode.ACCEPTED_202.code()) .withHeaders( header("x-callback", "test_callback_header") ) .withBody("a_callback_response"); // when mockServerClient .when( request() .withPath(calculatePath("callback")) ) .callback( callback() .withCallbackClass("org.mockserver.integration.callback.StaticTestExpectationCallback") ); // then // - in http assertEquals( response() .withStatusCode(HttpStatusCode.ACCEPTED_202.code()) .withHeaders( header("x-callback", "test_callback_header") ) .withBody("a_callback_response"), makeRequest( request() .withPath(calculatePath("callback")) .withMethod("POST") .withHeaders( header("X-Test", "test_headers_and_body") ) .withBody("an_example_body_http"), headersToIgnore) ); assertEquals(StaticTestExpectationCallback.httpRequests.get(0).getBody().getValue(), "an_example_body_http"); assertEquals(StaticTestExpectationCallback.httpRequests.get(0).getPath().getValue(), calculatePath("callback")); // - in https assertEquals( response() .withStatusCode(HttpStatusCode.ACCEPTED_202.code()) .withHeaders( header("x-callback", "test_callback_header") ) .withBody("a_callback_response"), makeRequest( request() .withSecure(true) .withPath(calculatePath("callback")) .withMethod("POST") .withHeaders( header("X-Test", "test_headers_and_body") ) .withBody("an_example_body_https"), headersToIgnore ) ); assertEquals(StaticTestExpectationCallback.httpRequests.get(1).getBody().getValue(), "an_example_body_https"); assertEquals(StaticTestExpectationCallback.httpRequests.get(1).getPath().getValue(), calculatePath("callback")); } }