我有一个应用程序,其中一个 api 是使用 Get 方法定义的。它还需要请求正文,然后将其映射到 POJO。我正在尝试使用 webTestClient 测试该 Controller 。但我没有看到使用 get() 方法发送请求正文的选项。不确定我是否以正确的方式定义我的 webTestClient。
我的 Controller 看起来像:
@GetMapping
public Flux<ResponseBody> getAllResources(@RequestBody Resource resource) {
//related code here...
}
我的测试方法:
@Test
public void myTest() {
webClient.get()
.uri("uri_path")
.header("Content-Type", "application/json")
.accept("application/json")
.exchange()
.expectedStatus.is2xxxSuccessful();
}
我在想,既然 Controller 允许通过 get 调用将对象绑定(bind)到 POJO,那么应该有某种方法使用 webTestClient 来测试它。
最佳答案
尝试使用:
webTestClient.method(HttpMethod.GET)
而不是:
webTestClient.get()
关于java - 带有 get() 和 requestBody 的 WebTestClient 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63928759/