Closed vadim-shb closed 5 years ago
You can already achieve this using stream as follows:
final MockServerClient mockServerClient = new MockServerClient("localhost", 1080);
final List<HttpRequest> matchingRequests =
Arrays.stream(mockServerClient
.retrieveRecordedRequests(request()))
.filter(httpRequest -> {
final Body body = httpRequest.getBody();
if (body instanceof StringBody) {
return "J. K. Rowling".equals(JsonPath.read(((StringBody) body).getValue(), "$.store.book[0].author"));
} else {
return false;
}
})
.collect(Collectors.toList());
Making this part of the client library is current beyond the scope of MockServer mainly because it would only be possible for the Java client library or would required complex logic implemented in each client library. The current design ethos is to put as much logic as possible server side so that is it easy to support numerous client libraries in multiple languages without excessive cost. Do this server side would be extremely challenging without a very complex solution like WebSockets or serialising and deserialising code from the client which is executed server side.
Let user define how to verify the body It could look like this: