如何解决com.github.tomakehurst.wiremock.WireMockServer 将 GET 解释为 POST?
这是 Feign 客户端,我正在尝试在我的应用中进行测试。
@FeignClient(value = "sessionData",url = "${client.session-data-url}")
public interface SessionDataClient {
@RequestMapping(method = RequestMethod.GET,path = "/session/{sessionId}")
@Headers({"Content-Type: application/json,Authorization: Bearer {token}"})
SessionDataResponseDto getMdmId(String token,@RequestParam(required = false) String serviceId,@PathVariable String sessionId);
}
这里是测试
public void getSessionDataForMdmId() throws IOException {
final String path = "/session/testSessionId?serviceId=testServiceId";
final String pathToResponse = "/mock-response/session-data-response.json";
IntegrationClientMocks.setupResponse(mockSessionDataService,path,pathToResponse,RequestMethod.GET.toString());
final SessionDataResponseDto dto = sessionDataClient.getMdmId("testToken","testServiceId","testSessionId");
assertEquals(dto.getMdmId(),"testMdmId");
}
这里是 WireMockServer 的设置
public static void setupResponse(WireMockServer mockService,String path,String pathToResponse,String method)
throws IOException {
mockService.stubFor(WireMock.request(method,WireMock.urlEqualTo(path))
.willReturn(WireMock.aResponse()
.withStatus(HttpStatus.OK.value())
.withHeader("Content-Type",MediaType.APPLICATION_JSON_VALUE)
.withBody(
copyToString(
IntegrationClientMocks.class.getResourceAsStream(pathToResponse),defaultCharset()))));
}
这里是日志
Request was not matched
=======================
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
GET | POST <<<<< HTTP method does not match
/session/testSessionId?serviceId=testServiceId | /session/testSessionId?serviceId=testServiceId
|
|
-----------------------------------------------------------------------------------------------------------------------
feign.FeignException$NotFound: [404 Not Found] during [GET] to [http://localhost:9562/session/testSessionId?serviceId=testServiceId] [SessionDataClient#getMdmId(String,String,String)]: [
Request was not matched
=======================
在日志中,WireMockServer 告诉我在发送 POST 时模拟了 GET 调用。但是在 Feign 下面告诉 [404 Not Found] during [GET]
请帮忙。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。