Search code examples
javaregexintegration-testingwiremock

wiremock path param matching


I need to create very basic mapping stup for wiremock server for the integration tests. I am calling the POST with the payload on url that has path param in it: /ngdms/odrers/{order-id}

this is the mapping stup I want to match to that call:

{
  "request": {
    "method": "POST",
    "urlPathPattern": "/ngdms/orders/*"
  },
  "response": {
   ...
   }
}

and the wiremock says:

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                       | POST
[path regex] /ngdms/orders/*                               | /ngdms/orders/b41a627e-6981-403a-94cd-c225b8036ef1  <<<<< URL does not match
                                                           |
                                                           |
-----------------------------------------------------------------------------------------------------------------------

so what is the regex urlPathPattern that will match basically everything (will be uuid eventually), please?


Solution

  • For Java's regex pattern, * is a quantifier, meaning it tells the pattern how many of the preceding token(s) to match.

    A simple catchall would be .* (. is the symbol for any character).

    {
      "request": {
        "method": "POST",
        "urlPathPattern": "/ngdms/orders/.*"
      },
      "response": {
       ...
       }
    }