springboot WireMock mock without parameters

Viewed 322

I have this mock that is working fine

stubFor(WireMock.get("/varela/offerszones?channel=123").willReturn(aResponse()
                .withStatus(200)
                .withHeader("content-type", "application/json")
                .withBodyFile("zones_config.json")));

but I would like to know if it possible to mock it without parametes, because I've tried but it is not working

stubFor(WireMock.get("/varela/offerszones").willReturn(aResponse()
                .withStatus(200)
                .withHeader("content-type", "application/json")
                .withBodyFile("zones_config.json")));
1 Answers

URL matching can be difficult to remember in WireMock. Check out the Request Matching documentation for more information.

You should be able to equality match on only the URL path by using urlPathEqualTo in Java ("urlPath" in JSON).

stubFor(WireMock.get(urlPathEqualTo("/varela/offerszones"))
    .willReturn(aResponse()
    .withStatus(200)
    .withHeader("content-type", "application/json")
    .withBodyFile("zones_config.json")));

The other options are: (listed as Java / JSON)

  • urlEqualTo / "url": equality matching on path and query
  • urlMatching / "urlPattern": regex matching on path and query
  • urlPathMatching / "urlPathPattern": regex matching on path only
Related