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

Debraj Manna

09/29/2023, 6:14 PM
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

Lee Turner

09/29/2023, 7:48 PM
So it is working now ?
m

Maxim Bastrygin

10/04/2023, 8:59 AM
No, it seems it is not. Have the same issue using version 2.33.1. The only difference is I am using "&&".
d

Debraj Manna

10/04/2023, 8:59 AM
@Lee Turner It is working for me after fixing the json
m

Maxim Bastrygin

10/04/2023, 9:00 AM
@Debraj Manna How did you fix it?
d

Debraj Manna

10/04/2023, 9:01 AM
My request json was malformed json. For example, in the screenshot shared above
"payload": pnr_details_response
was not correct
l

Lee Turner

10/04/2023, 9:04 AM
@Maxim Bastrygin Can you give examples of your requests and mappings to give us an idea of what you are trying to do ?
m

Maxim Bastrygin

10/04/2023, 9:17 AM
{ 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

Lee Turner

10/04/2023, 9:21 AM
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

Maxim Bastrygin

10/04/2023, 9:27 AM
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

Lee Turner

10/04/2023, 9:55 AM
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

Maxim Bastrygin

10/04/2023, 9:55 AM
So yours is 3.2.0?
Will try to test with it then
l

Lee Turner

10/04/2023, 9:58 AM
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

Maxim Bastrygin

10/04/2023, 10:01 AM
Much obliged Lee!
l

Lee Turner

10/04/2023, 10:03 AM
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\"
            }
          ]
        }"