在尝试测试客户端类时,POST 调用存根可以正常工作,而 GET 则不能。我在这里做错了什么/没有正确理解?
客户端代码(POST):
HttpResponse httpResponse = new DefaultHttpRequestBuilder(HttpMethod.POST, SERVICE_URL_GET_MAGIC)
.withBody(parseMagic(magicName))
.execute();
使用存根(POST):
stubFor(post(urlEqualTo("/api/get-magic"))
.withRequestBody(equalToJson(magicNameParsed))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(magicDtoParsed)));
工作正常(httpResponse 将有 200 OK)。
当GET使用时,它不会存根 api 调用(httpResponse 将 404 Not found)。
HttpResponse httpResponse = new DefaultHttpRequestBuilder(HttpMethod.GET, SERVICE_URL_GET_MAGIC)
.withBody(parseMagic(magicName))
.execute();
stubFor(get(urlEqualTo("/api/get-magic"))
.withRequestBody(equalToJson(magicNameParsed))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(magicDtoParsed)));