How to match a wiremock POST request with some optional JSON parameters & any values?

为君一笑 提交于 2019-12-12 18:09:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!