wiremockwiremock-standalone

WireMock multi value query matching


According to this documentation: https://wiremock.org/docs/request-matching/#matching-headerquery-parameter-containing-multiple-values the following mapping definition should work:

{
  "mappings" : [ {
    "id" : "8de914b3-3f46-4860-bcbb-d9671c1d39ac",
    "request" : {
      "url" : "/someEndpoint",
      "method" : "GET",
      "queryParameters" : {
        "id" : {
          "hasExactly" : [ {
            "equalTo" : "16930666"
          }, {
            "equalTo" : "49288354"
          }, {
            "equalTo" : "62100189"
          }, {
            "equalTo" : "53250905"
          } ]
        }
      }
    },
    "response" : {
      "status" : 200,
      "body" : "<?xml version=\"1.0\" ?>\n\n",
      "headers" : {
        "Content-Type" : "text/xml; charset=UTF-8"
      }
    },
    "uuid" : "8de914b3-3f46-4860-bcbb-d9671c1d39ac"
  } ],
  "meta" : {
    "total" : 1
  }
}

Although there is no example how the query parameters should be passed, I'd expect the following to match:

curl "http://localhost:8090/someEndpoint?id=16930666,49288354,62100189,53250905"

Instead I get this:

first failure

curl "http://localhost:8090/someEndpoint?id=16930666&id=49288354&id=62100189&id=53250905"

second failure

What am I doing wrong?

I am using WireMock 3.5.4


Solution

  • The correct url for accessing that stub is your second example:

    http://localhost:8090/someEndpoint?id=16930666&id=49288354&id=62100189&id=53250905
    

    The problem here is that your stub mapping differs slightly from the example in the WireMock docs. Your mapping uses the url element where as the correct element to use is the urlPath element. Everything else in your mapping was spot on.

    This should hopefully work for you:

    {
      "mappings": [
        {
          "id": "8de914b3-3f46-4860-bcbb-d9671c1d39ac",
          "request": {
            "urlPath": "/someEndpoint",
            "method": "GET",
            "queryParameters": {
              "id": {
                "hasExactly": [
                  {
                    "equalTo": "16930666"
                  },
                  {
                    "equalTo": "49288354"
                  },
                  {
                    "equalTo": "62100189"
                  },
                  {
                    "equalTo": "53250905"
                  }
                ]
              }
            }
          },
          "response": {
            "status": 200,
            "body": "<?xml version=\"1.0\" ?>\n\n",
            "headers": {
              "Content-Type": "text/xml; charset=UTF-8"
            }
          },
          "uuid": "8de914b3-3f46-4860-bcbb-d9671c1d39ac"
        }
      ],
      "meta": {
        "total": 1
      }
    }