'Wiremock Placeholder isn't recognized
I tried with the following json but the wiremock doesn't recognize my change. I read the documentation of wiremock and I saw that they said: JSON equality matching is based on JsonUnit and therefore supports placeholders. I also tried with both JDK 8 and JDK 13 but both are not working
Below is the detail
"method" : "POST",
"bodyPatterns" : [{
"equalToJson" : {
"recipient": {
"address": {
"city": "Bellevue",
"postalCode": "52031",
"countryCode": "US"
}
},
"sender": {
"address": {
"city": "",
"postalCode": "",
"countryCode": "HK"
}
},
"shipDate": "${json-unit.any-string}",
"accountNumber": {
"key": ""
}
},
Result when running selenium test with mock (I executed mock via java -jar tmp/wiremock.jar --global-response-templating --root-dir ./mock --port 1337
):
|
{ | { <<<<< Body does not match
"recipient" : { | "recipient" : {
"address" : { | "address" : {
"city" : "Bellevue", | "city" : "Bellevue",
"postalCode" : "52031", | "postalCode" : "52031",
"countryCode" : "US" | "countryCode" : "US"
} | }
}, | },
"sender" : { | "sender" : {
"address" : { | "address" : {
"city" : "", | "city" : "",
"postalCode" : "", | "postalCode" : "",
"countryCode" : "HK" | "countryCode" : "HK"
} | }
}, | },
"shipDate" : "${json-unit.any-string}", | "shipDate" : "May-26-2020",
"accountNumber" : { | "accountNumber" : {
"key" : "" | "key" : ""
} | }
} | }
|
Can anybody make some suggestions here. Thank you for reading my question
Solution 1:[1]
you have to enable the placeholder as below and you should make sure you are using the jre-standalone jar. you seem to be using the normal standalone jar
"enablePlaceholders" : true
Solution 2:[2]
The usage of "${json-unit.any-string}" is right. But placeholder works when the right dependency is used.
Using dependency com.github.tomakehurst:wiremock-jre8
worked for me.
Refer https://wiremock.org/docs/request-matching/ for more info. This would mention the following note
Placeholders are only available in the jre8 WireMock JARs, as the JsonUnit library requires at least Java 8.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mano |
Solution 2 |