我是Wiremock的新手,并试图阻止以下springboot静态端点的调用。
@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未找到
//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)));
请帮助提供代码段或参考。
答案 0 :(得分:0)
由于参数template
和templateDataAsJson
都用@RequestParam
进行了注释,因此,它们应相应地在Wiremock存根中传递,如下所示。
templatingService.stubFor(
post(urlEqualTo("/template/pdf?template=value1&templateDataAsJson=value2"))
.willReturn(aResponse().withBody(JSON_INPUT_TO_PDF_GEN).withStatus(200)));
其中value1
和value2
是两个参数各自的值。