
org.mockserver.integration.server.SameJVMAbstractClientServerIntegrationTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-integration-testing Show documentation
Show all versions of mockserver-integration-testing Show documentation
A module used to simplify integration testing of all MockServer versions by sharing commons integration testing components
package org.mockserver.integration.server;
import com.google.common.net.HttpHeaders;
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.HttpCallback.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"),
header(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
)
.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"),
header(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
)
.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"));
}
}