Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I verify two post requests to the same url but with different bodies in Wiremock? [duplicate]

Tags:

java

wiremock

How do I verify two post requests to the same url but with different bodies in Wiremock? The same url should be called once with body 1 and once with body 2.

As it is now Wiremock only cares about verifying the last line.

verify(postRequestedFor(urlEqualTo("/my-url"))
    .withRequestBody(equalToJson(resourceAsString("my-first-body.json"), true, false)));

verify(postRequestedFor(urlEqualTo("/my-url"))
    .withRequestBody(equalToJson(resourceAsString("my-other-body.json"), true, false)));
like image 254
Swoot Avatar asked Oct 17 '25 21:10

Swoot


1 Answers

I ended up doing this:

var postRequests = findAll(postRequestedFor(urlMatching("/my-url")));

assertThat(postRequests.get(0).getBodyAsString()).isEqualTo(resourceAsString("my-first-body.json"));
assertThat(postRequests.get(1).getBodyAsString()).isEqualTo(resourceAsString("my-other-body.json"));
like image 178
Swoot Avatar answered Oct 19 '25 09:10

Swoot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!