I'm trying to mock an API call that accepts a JSON body in a POST and it has two possible responses:
SearchCenter
property, answer with response ASearchCenter
, answer with response BIn the Request Matching chapter of Wiremock documentation it only shows how to positively match JSON, it does not show how to match missing properties.
Sample request with SearchCenter
:
{
"GeoCoordinatesResponseFormat": "DecimalDegree",
"ProviderID": "bla bla",
"SearchCenter": {
"GeoCoordinates": {
"DecimalDegree": {
"Latitude": "{{search_lat}}",
"Longitude": "{{search_lon}}"
}
},
"Radius": {{search_radius}}
}
}
Sample request without SearchCenter
:
{
"GeoCoordinatesResponseFormat": "DecimalDegree",
"ProviderID": "bla bla"
}
In order to match a missing JSON property, you can use the matchingJsonPath
operator in combination with the absent()
, like this:
.withRequestBody(matchingJsonPath("$.SearchCenter", absent()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With