我正在尝试在映射文件夹下创建一个具有多个 stub 的mapping.json,如下所示。但我面临以下错误
Wiremock:v2.5.1(独立)
Mapping.json 文件看起来,
[
{
"scenarioName": "Savings account Stub",
"request": {
"url": "/ws/*****",
"method": "POST",
"bodyPatterns" : [{
"contains" : "AccountRequest"
}
]
},
"response": {
"status": 200,
"bodyFileName": "******"
}
},
{
"scenarioName": "Current account Stub",
"request": {
"method": "POST",
"url": "/ws/*****",
"bodyPatterns": [
{
"contains": "AccountListRequest"
}
]
},
"response": {
"status": 200,
"bodyFileName": "******"
}
}]
错误:
Exception in thread "main" wiremock.com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.github.tomakehurst.wiremock.stubbing.StubMapping out of START_ARRAY token
是否有可能在单个映射文件中为同一 URL 创建多个 stub ?谁能告诉我具体的问题是什么?
最佳答案
Looking at the stubbing documentation ,我认为您希望您的 mappings.json
看起来像...
{
"mappings": [
{
"scenarioName": "foo",
"request": {},
"response": {}
}, {
"request": {}
}
],
"importOptions": {
"duplicatePolicy": "IGNORE",
"deleteAllNotInImport": true
}
}
然后,您需要使用 mappings.json
作为请求正文向 /__admin/mappings/import
发出 POST 请求。原因是我相信单个文件中的多个映射只能通过导入选项支持。
关于java - 如何使用 Wiremock 在一个 json 文件中为同一 url 实现多 stub ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61230767/