Mohammad
Mohammad

Reputation: 154

If WireMock query is not matched then defaults to overlapping endpoint instead of 404

Here are two endpoints

Endpoint 1

{
  "request": {
    "method": "GET",
    "urlPath": "/event/event410"
  },
  "response": {
    "status": 410,
    "jsonBody": {"status":"Error","message":"Target resource is no longer available - type 410 -"},
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

Endpoint 2

{
  "request": {
    "method": "GET",
    "urlPath": "/event/event410",
    "queryParameters":{
          "date": {
            "equalTo" : "SomeDate"
        }
      }
  },
  "response": {
    "status": 410,
    "jsonBody": {"status":"Error","message":"Target resource is no longer available - type and date 410 -"},
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

If I hit the second endpoint with a query that does not match SomeDate then I expect it throw a 404 NOT FOUND but instead it hits the 1st endpoint by default. Is there some way of specifying it such that it does not hit the overlapping endpoint. I have tried the priority attribute but it does not seem to do anything.

Upvotes: 0

Views: 975

Answers (1)

Tom
Tom

Reputation: 4149

You need to explicitly declare the query parameter to be absent in the first stub by adding this:

"queryParameters" : { "date" : { "absent" : true } }

Upvotes: 1

Related Questions