2

I'm trying to do this:

    stubFor(get("/my/path")
      .withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
      .willReturn(okJson(RESPONSE)));

and I get this error:

GET                                                        | GET
/my/path                                                   | /my/path?paramName=v1Value  <<<<< URL does not match
                                                           |
Query: paramName [matches] ^(v1Value)|(v2Value)|(v3Value)$ | paramName: v1Value

I have tested the regex and it works. I also debugged and I saw that the RegexPattern also matches. But for some reason, I still get this error. I believe I'm using it wrongly.

I tried a simpler version that also didn't work:

stubFor(get("/my/path")
  .withQueryParam("paramName", equalTo("v1Value"))
  .willReturn(okJson(RESPONSE)));

Any ideas? Thanks in advance.

Jordan Silva
  • 833
  • 8
  • 18

1 Answers1

4

WireMock documentation recommends matching on url path only and matching on query parameters separately.

That would look something like...

    stubFor(get(urlPathEqualTo("/my/path"))
      .withQueryParam("paramName", matching(format("^(%s)|(%s)|(%s)$", v1, v2, v3)))
      .willReturn(okJson(RESPONSE)));

If I recall correctly, just using stubFor(get("my/url")) defaults to using urlEqualTo, which checks equality matching on path and query parameters

agoff
  • 5,818
  • 1
  • 7
  • 20