gpt4 book ai didi

无法识别 Wiremock 占位符

转载 作者:行者123 更新时间:2023-12-05 06:16:38 33 4
gpt4 key购买 nike

我尝试使用以下 json,但 wiremock 无法识别我的更改。我看了wiremock的文档,看到他们说:JSON相等匹配是基于JsonUnit的,因此支持占位符。我也尝试使用 JDK 8 和 JDK 13,但两者都不起作用

详情如下

    "method" : "POST",
"bodyPatterns" : [{
"equalToJson" : {
"recipient": {
"address": {
"city": "Bellevue",
"postalCode": "52031",
"countryCode": "US"
}
},
"sender": {
"address": {
"city": "",
"postalCode": "",
"countryCode": "HK"
}
},
"shipDate": "${json-unit.any-string}",
"accountNumber": {
"key": ""
}
},

使用 mock 运行 selenium 测试时的结果(我通过 java -jar tmp/wiremock.jar --global-response-templating --root-dir ./mock --port 1337 执行 mock) :

                                                           |
{ | { <<<<< Body does not match
"recipient" : { | "recipient" : {
"address" : { | "address" : {
"city" : "Bellevue", | "city" : "Bellevue",
"postalCode" : "52031", | "postalCode" : "52031",
"countryCode" : "US" | "countryCode" : "US"
} | }
}, | },
"sender" : { | "sender" : {
"address" : { | "address" : {
"city" : "", | "city" : "",
"postalCode" : "", | "postalCode" : "",
"countryCode" : "HK" | "countryCode" : "HK"
} | }
}, | },
"shipDate" : "${json-unit.any-string}", | "shipDate" : "May-26-2020",
"accountNumber" : { | "accountNumber" : {
"key" : "" | "key" : ""
} | }
} | }
|

任何人都可以在这里提出一些建议。感谢您阅读我的问题

最佳答案

“${json-unit.any-string}”的用法是正确的。但占位符在使用正确的依赖项时起作用。

使用依赖项 com.github.tomakehurst:wiremock-jre8 对我有用。

引用https://wiremock.org/docs/request-matching/获取更多信息。这会提到以下注释

Placeholders are only available in the jre8 WireMock JARs, as the JsonUnit library requires at least Java 8.

关于无法识别 Wiremock 占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62014297/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com