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

Danny Paniagua

03/20/2023, 1:31 PM
Hey! I'm having some trouble setting up my wiremock mapping logic using response templating helpers. I'm trying to understand how to access the request body inside of a
#eq
block - whatever I have setup now is always returning with the false condition. The simplified object coming in is
Copy code
{
  lender-type: 'installment',
  cuId: '1234'
}
The goal is to use response templating to choose which json file to return. I have these sections in my mapping file:
Copy code
"bodyPatterns": [{ 
  "mathesJsonPath": "[?($.lenderId == 'installment')]"
}]
and then further down:
Copy code
"response": {
  "bodyFileName": "{{#eq (jsonPath request.body '$.cuId') '1234'}}respseon_file_A.json{{else}}response_file_B.json{{/eq}}"
}
The
matchesJsonPath
bit seems to work fine as I know I am getting into this mapping file. The problem I'm running into as stated further up above is that when I try to test this logic, the
#eq
block is always returning
response_file_B.json
, no matter what
cuId
field is getting passed. I'm assuming I have some bad character spacing in the handlebars syntax and not to sure how to debug it. Is there anything obvious that I'm doing wrong?
1
a

Aaron

03/20/2023, 1:53 PM
What version of WireMock are you using? With your example, I was able to successfully retrieve file A or file B depending on
cuId
value.
👀 1
And you’re positive that the
matchesJsonPath
part is working, and you aren’t matching a separate mapping?
d

Danny Paniagua

03/20/2023, 1:54 PM
wiremock-jre3-standalone
2.35.0
Yes, I actually removed all other mapping files to ensure that that wasn't the case - there is only one mapping file in my directory at this point
a

Aaron

03/20/2023, 1:57 PM
Hmm… And you’ve restarted WireMock since making those changes?
d

Danny Paniagua

03/20/2023, 1:58 PM
Yep 😕
a

Aaron

03/20/2023, 1:59 PM
Any chance you can give the full mapping and a complete example request body? Might be something going on there
d

Danny Paniagua

03/20/2023, 2:01 PM
Copy code
{
  "name": "installment_mapping",
  "request": {
    "method": "POST",
    "url": "/lender",
    "headers": {
      "Content-Type": {
        "equalTo": "application/json"
      }
    },
    "bodyPatterns": [
      {
        "matchesJsonPath": "[?($.lender-type== 'installment')]"
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "bodyFileName": "{{#eq (jsonPath request.body '$.cuId') '1234'}}response_file_A.json{{else}}response_file_B.json{{/eq}}"
  }
}
Was actually about to ask if the full mapping file might help 😂 The request body is
Copy code
<http://localhost:8080/partner-service/lender>
{
    "firstName": "Danman",
    "lastName": "Mandan",
    "lender-type": "installment",
    "cuId": 1234
}
...actually think I just discovered that changing
cuId
from int to string in the request payload triggers the correct response 🤦
Yeah, I've got it figured out now - was improperly parsing for a string instead of an int in the handlebar
a

Aaron

03/20/2023, 2:11 PM
haha nice! glad you were able to get it sorted 😄
d

Danny Paniagua

03/20/2023, 2:14 PM
Same 🙂 - thank you for being my rubber duck 😂
6 Views