【发布时间】:2019-07-02 04:41:35
【问题描述】:
我是wiremock的新手,并试图对以下springboot restful端点的调用进行存根。
@PostMapping(path = "/template/pdf", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<String> bindData(
@ApiParam(value = "BindDataRequest payload", required = true)
@RequestParam String template, @RequestParam String templateDataAsJson) throws IOException {
//Some code
return ResponseEntity.ok("xyz");
}
**The following basic logic works:**
templatingService.stubFor(
post(urlEqualTo("/template/pdf"))
.willReturn(aResponse().withBody(JSON_INPUT_TO_PDF_GEN).withStatus(200)));
但是,我需要一种在调用 .willReturn(.....) 之前设置 2 个字符串请求参数的方法
我试过了:
templateBinderService.stubFor(
post(urlEqualTo("/template/pdf"))
.withRequestBody(WireMock.equalTo("jixhcjxhcjxhcxhchx"))
.withRequestBody(WireMock.equalTo("nhhhxhxhhhhhxhhhh"))
.willReturn(aResponse().withBody(JSON_INPUT_TO_HTML2PDF_GEN).withStatus(200)));
但是得到了:
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found
//I have also tried:
templateBinderService.stubFor(
post(urlEqualTo("/template/test"))
.withRequestBody(containing("param1-value"))
.withRequestBody(containing("param2-value"))
.willReturn(aResponse().withBody("i-am-a-response").withStatus(200)));
//I have also tried:
templateBinderService.stubFor(
post(urlEqualTo("/template/test"))
.withRequestBody(equalToJson("{}"))
.willReturn(aResponse().withBody("i-am-a-response").withStatus(200)));
请帮忙提供代码 sn-p 或参考。
【问题讨论】:
标签: java spring-boot spring-mvc mockito wiremock