4

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.

Alex
  • 65
  • 8

1 Answers1

2

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

mklepa
  • 211
  • 3
  • 7
  • Thank you! What I did was to create a request where I added my query params & header also, and then verify that they are the same as the stub's. – Alex Nov 28 '19 at 07:04