问题
I need to use wiremock to test a POST request that's sending data like this:
{
"name": "known fixed value",
"dateOfBirth": 5123456789000,
"email": "known fixed value",
"currentDate": any numeric value,
"status": any text value with alphabets, numbers and symbols
}
The 1st 3 fields, name, dateOfBirth and email are fixed, known values, that don't change from one request to the next.
The last 2 fields, currentDate and status change randomly from one request to the next, but are mandatory fields that can hold any value.
How do I design a mapping that tests this?
Thanks in advance.
回答1:
You can use a JsonPath regex request body matcher, for example in your case you should use this JsonPath:
$[?(@.name == 'known fixed value' && @.dateOfBirth == 5123456789000 && @.email == 'known fixed value' && @.currentDate =~ /[0-9]*/i && @.status =~ /.*/i)]
Which will match an example request body:
{
"name": "known fixed value",
"dateOfBirth": 5123456789000,
"email": "known fixed value",
"currentDate": 23123,
"status": "rfjhg33443"
}
来源:https://stackoverflow.com/questions/47019382/how-to-match-a-wiremock-post-request-with-some-optional-json-parameters-any-va