https://linen.dev logo
#general
Title
# general
p

Palak

03/22/2023, 1:50 PM
I have recently started working on wiremock. I am working on POST methods. I wanted to know how we can get default response if the selection criteria is not matching any of the existing mappings? This is my mapping file for matching 12345 id, what change to make if we want to make it generic ..like any id and it should respond with the file which we map for. { "id" : "123", "name" : "xyz", "request" : { "url" : "xyz", "method" : "POST", "bodyPatterns" : [ { "matchesXPath": { "expression": "abc/id/text()", "equalTo": "12345" } } ] }, "response" : { "status" : 200, "bodyFileName": "xyz/Success_default-rsp.txt", "headers" : { "Content-Type" : "text/xml;charset=UTF-8", "X-Backside-Transport" : "OK" } }, "uuid" : "123097", "persistent" : true, "insertionIndex" : 2 }
a

Aaron

03/22/2023, 1:59 PM
You can use
priority
to force WireMock to check more specific mappings before more generic mappings. One moment, getting an example.
Copy code
{
  "mappings": [
    {
      "priority": 1,
      "request": {
        "url": "xyz",
        "method": "POST",
        "bodyPatterns": [
          {
            "matchesXPath": {
              "expression": "abc/id/text()",
              "equalTo": "12345"
            }
          }
        ]
      },
      "response": {
        "bodyFileName": "xyz/Success_default-rsp.txt"
      }
    },
    {
      "priority": 5,
      "request": {
        "url": "xyz",
        "method": "POST"
      },
      "response": {
        "bodyFileName": "xyz/some_other_response.txt"
      }
    }
  ]
}
The higher the priority (lower number), the earlier that WireMock checks for a match. So any requests to
xyz
with that
abc/id === 12345
will match on the Priority 1, and any other requests to
xyz
will match on the Priority 5.
I think by default all mappings are Priority 10?