Is it possible to have a test using Wiremock for a known POST request, in order to check the query params the request has?
wireMockServer.start();
stubFor(post(urlMatching("http://localhost:8080/smth.*"))
.withHeader("Content-Type", equalTo("application/x-www-form-urlencoded"))
.withQueryParam("authorizationcode", equalTo("123456"))
.withQueryParam("baseamount", equalTo("0.10"))
.withQueryParam("basecurrency", equalTo("978"))
.withQueryParam("cardcountry", equalTo("ITA"))
.withQueryParam("cardexpirydate", equalTo("0120"))
.withQueryParam("customfield",equalTo("some+custom+field"))
.withQueryParam("result", equalTo("APPROVED"))
.willReturn(aResponse().withBody(RESPONSE))
);
wireMockServer.stop();
I don't know if I am on the right path, I can't find good examples in the documentation.
All of those parameters and headers that you added will have to be present in the request in order to be matched by WireMock. That should test the presence of query parameters in request properly. If you have issues matching the request with the stub, you can stop the code execution with breakpoint after your stub is registered and evaluate (ALT + F8 in IntelliJ) this expression:
WireMock.listAllStubMappings()
I found some repositories with examples containing full configuration in the GitHub of WireMock author: https://github.com/tomakehurst/wiremock-demo and https://github.com/tomakehurst/wiremock-presentation-examples
I'm not sure if that answers your question entirely. If you have any specific issues, then please provide the code that causes it: https://stackoverflow.com/help/minimal-reproducible-example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With