I have a body pattern defined like below ```"body...
# help
d
I have a body pattern defined like below
Copy code
"bodyPatterns": [
          {
            "matchesJsonPath" : "$.[?(@.event_type=='TRIP_DETAILS_V2' || @.event_type=='TRIP_DETAILS_V3' || @.event_type=='PNR_V2' || @.event_type=='PNR_V3')]",
            "caseInsensitive": false
          }
        ]
Can someone help me understand why wiremock is still not able to match the request body? I am using wiremock-jre8-standalone:2.35.0
I was sending a malformed json request
l
So it is working now ?
m
No, it seems it is not. Have the same issue using version 2.33.1. The only difference is I am using "&&".
d
@Lee Turner It is working for me after fixing the json
m
@Debraj Manna How did you fix it?
d
My request json was malformed json. For example, in the screenshot shared above
"payload": pnr_details_response
was not correct
l
@Maxim Bastrygin Can you give examples of your requests and mappings to give us an idea of what you are trying to do ?
m
{ fromAccountId: 123, providerId: 123, operationId: 123, paymentInformation: 123, step: 1, attributes: [{attributeName: customerCode, value: abc}, {attributeName: pinCode, value: 01.01.1900}] } "bodyPatterns": [ { "matchesJsonPath": "$.attributes[?(@.attributeName == 'customerCode' && @.value == 'abc')]" } ]
l
Quick question, your json isn’t valid. Is that what you are using or is that just a copy/paste issue into slack ?
The json in the request I mean
m
Just copied it from our front-end console
Copy code
{
  "fromAccountId": 123,
  "providerId": 123,
  "operationId": 123,
  "paymentInformation": 123,
  "step": 1,
  "attributes": [
    {
      "attributeName": "customerCode",
      "value": "abc"
    },
    {
      "attributeName": "pinCode",
      "value": "01.01.1900"
    }
  ]
}
👍 1
This is the valid one
l
Not sure what the problem would be. I have just tried your payload with your
bodyPatterns
and it matches the request OK for me. I am using the latest wiremock version which is different to yours though
m
So yours is 3.2.0?
Will try to test with it then
l
Yes, I think so. Might be the release before
3.2.0
I am using wiremock standalone in docker at the moment. I normally use the nightly image. Will delete my local image to make sure I have the latest
OK, just pulled the latest image and retested and it seems to match the request fine
🙌 1
m
Much obliged Lee!
l
No worries at all. Just for reference I am testing with a very simple get request with your
bodyPatterns
pasted in:
Copy code
{
  "name": "test",
  "request": {
    "url": "/test",
    "method": "GET",
    "bodyPatterns": [
      {
        "matchesJsonPath": "$.attributes[?(@.attributeName == 'customerCode' && @.value == 'abc')]"
      }
    ]
  },
  "response": {
    "status": 200,
    "transformers": [
      "response-template"
    ],
    "jsonBody": {
      "id": "{{randomInt}}",
      "name": "test",
      "creationDate": "{{now}}"
    }
  }
}
Then testing with curl:
Copy code
curl -X GET --location "<http://localhost:7777/test>" \
    -H "Content-Type: application/json" \
    -d "{
          \"fromAccountId\": 123,
          \"providerId\": 123,
          \"operationId\": 123,
          \"paymentInformation\": 123,
          \"step\": 1,
          \"attributes\": [
            {
              \"attributeName\": \"customerCode\",
              \"value\": \"abc\"
            },
            {
              \"attributeName\": \"pinCode\",
              \"value\": \"01.01.1900\"
            }
          ]
        }"