[英]How to stub multiple parameter Springboot Restful POST Endpoint using WireMock
I am new to wiremock and trying to stub the invocation of the following springboot restful endpoint. 我是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)));
But, i need a way of setting the 2 string request parameters before invoking .willReturn(.....) 但是,我需要一种在调用.willReturn(.....)之前设置2个字符串请求参数的方式。
I have tried : 我努力了 :
templateBinderService.stubFor(
post(urlEqualTo("/template/pdf"))
.withRequestBody(WireMock.equalTo("jixhcjxhcjxhcxhchx"))
.withRequestBody(WireMock.equalTo("nhhhxhxhhhhhxhhhh"))
.willReturn(aResponse().withBody(JSON_INPUT_TO_HTML2PDF_GEN).withStatus(200)));
But got: 但是得到了:
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found 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)));
Please help with code snippet or reference. 请帮助代码段或参考。
Since both the parameters template
and templateDataAsJson
are annotated with @RequestParam
, they should be passed accordingly in the wiremock stub as below. 由于参数
template
和templateDataAsJson
都使用@RequestParam
进行了注释,因此应按如下所示在Wiremock存根中相应地传递它们。
templatingService.stubFor(
post(urlEqualTo("/template/pdf?template=value1&templateDataAsJson=value2"))
.willReturn(aResponse().withBody(JSON_INPUT_TO_PDF_GEN).withStatus(200)));
where value1
and value2
are the respective values for both parameters. 其中
value1
和value2
是两个参数的相应值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.