java Wiremock独立处理如何使用请求数据操作响应
我试图使用Wiremock独立服务器实现对POST REST调用的模拟。我面临着这样的挑战,假设post主体包含一个“name”字段及其值,那么在该post调用的响应中应该返回相同的值。我的json文件如下所示:
{
"priority": 1,
"request": {
"method": "POST",
"urlPath": "/primeSlots",
"bodyPatterns" : [ {
"matchesJsonPath" : "{ \"things\": [ { \"name\": \"794363\" }]
}"
} ]
},
"response": {
"status": 200,
"body": "{{$.things.name.value}}",
"transformers": ["response-template"]
}
}
所以,我需要得到值,即794363,但使用上述方法无法在响应后体中得到它
我也试过:
{
"request": {
"method": "POST",
"urlPath": "/transform",
"bodyPatterns": [
{
"matchesJsonPath" : "$.things[?(@.name =~ /[0-9]+/i)]"
}
]
},
"response": {
"status": 200,
"body": "{\"responseName\": \"
{{request.body.things.name.value}}\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
所以我的问题是,即使我使用一个正则表达式,它与请求中的任何数字匹配,如何使用Wiremock独立json文件在响应中返回相同的数字? 谢谢
共 (0) 个答案