我需要什么时候做第一个请求然后得到存根响应代码= 401.
当第二次执行相同的请求时,得到存根响应码= 200.
我使用scenario.
这是我的WireMock映射在一个文件:
{
"scenarioName": "Request transfer, 401",
"requiredScenarioState": "Started",
"newScenarioState": "Triggered Once",
"request": {
"method": "POST",
"urlPattern": "/api/T2A"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 401
}
}
{
"scenarioName": "Request transfer, 200",
"requiredScenarioState": "Triggered Once",
"newScenarioState": "Started",
"request": {
"method": "POST",
"urlPattern": "/api/T2A"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "VB/back/request_transfer.json"
}
}
当我第一次请求我得到存根响应= 401.
好了。但当做第二次相同的请求WireMock返回错误码= 404.
Request was not matched
=======================
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
POST | POST
/api/T2A | /api/T2A
|
|
-----------------------------------------------------------------------------------------------------------------------
2021-03-02 22:44:34.802 Request received:
127.0.0.1 - POST /api/T2A
{"MTS":"2be192ca-dabe-47b9-b","IDNP":"1"}
Matched response definition:
(no response definition configured)
Response:
HTTP/1.1 404
(no headers)
2021-03-02 22:44:34.805 Received request to /not-matched with body
为什么第二个SAME请求不返回存根响应状态= 200?
您的场景必须具有相同的名称。这就是WireMock如何识别映射属于该场景。
您得到404,因为场景Request transfer, 401
和场景状态Triggered Once
没有映射。
将两个映射的场景名称更改为Request transfer
将解决您的问题。