Java Code Examples for org.mockserver.model.HttpRequest#withBody()
The following examples show how to use
org.mockserver.model.HttpRequest#withBody() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractS3ClientTest.java From vertx-s3-client with Apache License 2.0 | 6 votes |
void mock(Map<String, List<String>> expectedQueryParams, String method, String path, Integer statusCode, Body requestBody, Body responseBody, List<Header> responseHeaders, Header... expectedHeaders) throws IOException { final HttpRequest httpRequest = request() .withMethod(method) .withPath(path) .withHeaders(expectedHeaders) .withQueryStringParameters(expectedQueryParams); if (requestBody != null) { httpRequest.withBody(requestBody); } getMockServerClient().when( httpRequest ).respond( response() .withStatusCode(statusCode) .withHeaders(responseHeaders) .withHeader(Header.header("Content-Type", "application/xml;charset=UTF-8")) .withBody(responseBody) ); }
Example 2
Source File: AcmeMockServerBuilder.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public AcmeMockServerBuilder addPostRequestAndResponse(String expectedPostRequestBody, String postPath, String responseBody, String replayNonce, String link, String location, int responseCode, boolean useProblemContentType) { HttpResponse response = response() .withHeader("Cache-Control", "public, max-age=0, no-cache") .withHeader("Replay-Nonce", replayNonce) .withStatusCode(responseCode); if (! responseBody.isEmpty()) { response = response .withHeader("Content-Type", useProblemContentType ? "application/problem+json" : "application/json") .withBody(responseBody); } if (! link.isEmpty()) { response = response.withHeader("Link", link); } if (! location.isEmpty()) { response = response.withHeader("Location", location); } HttpRequest request = request() .withMethod("POST") .withPath(postPath) ; if (! expectedPostRequestBody.isEmpty()) { request = request.withBody(expectedPostRequestBody); } server.when( request, Times.once()) .respond(response); return this; }
Example 3
Source File: AcmeMockServerBuilder.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public AcmeMockServerBuilder addPostRequestAndResponse(String expectedPostRequestBody, String postPath, String responseBody, String replayNonce, String link, String location, int responseCode, boolean useProblemContentType) { HttpResponse response = response() .withHeader("Retry-After", "0") .withHeader("Cache-Control", "public, max-age=0, no-cache") .withHeader("Replay-Nonce", replayNonce) .withStatusCode(responseCode); if (! responseBody.isEmpty()) { response = response .withHeader("Content-Type", useProblemContentType ? "application/problem+json" : "application/json") .withBody(responseBody); } if (! link.isEmpty()) { response = response.withHeader("Link", link); } if (! location.isEmpty()) { response = response.withHeader("Location", location); } HttpRequest request = request() .withMethod("POST") .withPath(postPath) ; if (! expectedPostRequestBody.isEmpty()) { request = request.withBody(expectedPostRequestBody); } server.when( request, Times.once()) .respond(response); return this; }