【发布时间】:2021-10-04 15:57:58
【问题描述】:
我有一些关于再次检查 Wiremock 的问题
我想检查 JSON 所有字段
{"petType" : 1, "wildLevel": 40,"petStatus": 1}
如果我发送无效字段,例如
{"petType" : 1, "wildLevel": 40,"patStatus": 1}
{"catType" : 1, "wildLevel": 40,"patStatus": 1}
{"petType" : 1, "wildLevelxx": 40,"patStatus": 1}
,它应该显示无效请求。
这个我可以写的映射JSON
{
"mappings":[
{
"priority":1,
"request":{
"method":"PATCH",
"urlPath":"/pet/status",
"bodyPatterns":[
{
"or":[
]
}
]
},
"response":{
"status":400,
"transformers":[
"response-template"
],
"bodyFileName":"invalid-request.json",
"headers":{
"Content-Type":"application/json"
}
}
},
{
"priority":2,
"request":{
"method":"PATCH",
"urlPath":"/pet/status",
"bodyPatterns":[
{
"and":[
{
"matchesJsonPath":"$[?(@.petType == '404040')]"
},
{
"matchesJsonPath":"$.wildLevel "
},
{
"matchesJsonPath":"$.petStatus "
}
]
}
]
},
"response":{
"status":200,
"transformers":[
"response-template"
],
"bodyFileName":"find-success.json",
"headers":{
"Content-Type":"application/json"
}
}
},
{
"priority":3,
"request":{
"method":"PATCH",
"urlPath":"/pet/status",
"bodyPatterns":[
{
"and":[
{
"matchesJsonPath":"$.petType "
},
{
"matchesJsonPath":"$.wildLevel "
},
{
"matchesJsonPath":"$.petStatus "
}
]
}
]
},
"response":{
"status":403,
"transformers":[
"response-template"
],
"bodyFileName":"data-not-found.json",
"headers":{
"Content-Type":"application/json"
}
}
}
]
}
现在,我不知道如何找到解决方案,请帮助
【问题讨论】: