我正在尝试为我的登录过程创建模拟。我使用带有几个字段和登录对象(带有登录名、密码等)的 POST 方法
为此,我正在使用 JsonPath。代码如下:
{
"request": {
"method": "POST",
"url": "/login",
"bodyPatterns" : [
{"matchesJsonPath" : "$.method"},
{"matchesJsonPath" : "$.params[?(@.clientVersion == "1")]"},
{"matchesJsonPath" : "$.params.login"},
{"matchesJsonPath" : "$.params.password"}
]
},
"response": {
"status": 200,
"bodyFileName": "login.json"
}
}
我正在检查 clientVersion 因为它类似于示例。
我的问题是,给定 POST JSON:
{
"method": "login",
"params": {
"clientVersion": "1",
"login": "test@test.com",
"password": "681819535da188b6ef2"
}
}
我收到 404。
然而,当我改变
{"matchesJsonPath" : "$.params[?(@.clientVersion == "1")]"},
正常
{"matchesJsonPath" : "$.params.clientVersion"},
一切正常。
那么 - 如果给定的字段等于某个值,如何使用matchesJsonPath检查wiremock内部?
在我的情况下,如何将其应用于根字段之类的方法?
当我们在做的时候 - 我在检查值是否不为空时遇到了类似的问题。我尝试应用正则表达式等 - 没有运气。
最佳答案
它在我的情况下工作:
线模:
"request": {
"urlPathPattern": "/api/authins-portail-rs/authins/inscription/infosperso",
"bodyPatterns" : [
{"matchesJsonPath" : "$[?(@.nir == '123456789')]"},
{"matchesJsonPath" : "$[?(@.nomPatronyme == 'aubert')]"},
{"matchesJsonPath" : "$[?(@.prenoms == 'christian')]"},
{"matchesJsonPath" : "$[?(@.dateNaissance == '01/09/1952')]"}
],
"method": "POST"
}
杰森:
{
"nir": "123456789",
"nomPatronyme": "aubert",
"prenoms": "christian",
"dateNaissance": "01/09/1952"
}
关于json - 使用wiremock匹配JsonPath中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28671753/