https://linen.dev logo
#help
Title
# help
k

Krupa Mashruwala

09/05/2023, 1:25 PM
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

Oleg Nenashev

09/05/2023, 4:19 PM
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

Aaron

09/05/2023, 7:40 PM
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

Krupa Mashruwala

09/06/2023, 5:18 AM
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

Oleg Nenashev

09/06/2023, 8:25 AM
I suggest updating, in any case. At least to 2.35.0
k

Krupa Mashruwala

09/06/2023, 11:11 AM
hello @Aaron @Oleg Nenashev I tried but didn't work
a

Aaron

09/06/2023, 1:46 PM
What’s the full mapping you’re using? What’s the request you’re sending look like?