Hello fellow members of community. I am trying to ...
# help
k
Hello fellow members of community. I am trying to use graphQL wiremock stub mapping for not matching (basically negative match) to specific value as follow.
Copy code
{
  "matchesJsonPath" : "$[?(@.variables.size() == 1)]"
},
{
  "matchesJsonPath": "$.variables.orgId",
  "doesNotEqual": "36df60f7-033a-444f-846e-a7cde0fb3947"
}
and for Positive match I was able to successfully match it with jsonEquals. as follows:
Copy code
{
  "matchesJsonPath" : "$[?(@.variables.size() == 1)]"
},
{
  "matchesJsonPath": {
    "expression": "$.variables",
    "equalToJson": "{ \"orgId\": \"36df60f7-033a-444f-846e-a7cde0fb3947\" }"
  }
}
but after placing mapping of negative match it directly get response of negative match even if my value for orgID matches to uuid 36df60f7-033a-444f-846e-a7cde0fb3947 Is there anything wrong I am doing? please guide
o
Hello. I guess you receive JSON and the comparison is for the whole string including brackets. So without them you would match different things
Note that in WireMock 3 there is a
not()
matcher that can chain
equalToJson
()
a
Copy code
...
{
        "matchesJsonPath": "$[?(@.variables.size() == 1)]"
      },
      {
        "matchesJsonPath": {
          "expression": "$.variables.orgId",
          "doesNotMatch": "36df60f7-033a-444f-846e-a7cde0fb3947"
        }
      }
...
should also work! Tested it out on 2.35.0 (oops not on 3.0.2 yet 🙃 ) Here’s the whole mapping I used:
Copy code
{
  "mappings": [
    {
      "request": {
        "url": "/test",
        "bodyPatterns": [
          {
            "matchesJsonPath": "$[?(@.variables.size() == 1)]"
          },
          {
            "matchesJsonPath": {
              "expression": "$.variables.orgId",
              "doesNotMatch": "36df60f7-033a-444f-846e-a7cde0fb3947"
            }
          }
        ]
      },
      "response": {
        "status": 200,
        "body": "Does not match!"
      }
    },
    {
      "request": {
        "url": "/test",
        "bodyPatterns": [
          {
            "matchesJsonPath": "$[?(@.variables.size() == 1)]"
          },
          {
            "matchesJsonPath": {
              "expression": "$.variables",
              "equalToJson": "{ \"orgId\": \"36df60f7-033a-444f-846e-a7cde0fb3947\" }"
            }
          }
        ]
      },
      "response": {
        "status": 200,
        "body": "Does match!"
      }
    }
  ]
}
And the request body I sent:
Copy code
{
  "variables": {
    "orgId": "36df60f7-033a-444f-846e-a7cde0fb3947"
  }
}
👍 1
k
Thanks @Aaron @Oleg Nenashev for reply. We use wiremock 2.26.0 version as of now. I can try both suggestions from y'all will let you know.
o
I suggest updating, in any case. At least to 2.35.0
k
hello @Aaron @Oleg Nenashev I tried but didn't work
a
What’s the full mapping you’re using? What’s the request you’re sending look like?