我有一个应用程序,其中一个 api 是使用 Get 方法定义的。它还需要请求正文,然后将其映射到 POJO。我正在尝试使用 webTestClient 测试该控制器。但我没有看到使用 get() 方法发送请求正文的选项。不确定我是否以正确的方式定义我的 webTestClient。
我的控制器看起来像:
@GetMapping
public Flux<ResponseBody> getAllResources(@RequestBody Resource resource) {
//related code here...
}
Run Code Online (Sandbox Code Playgroud)
我的测试方法:
@Test
public void myTest() {
webClient.get()
.uri("uri_path")
.header("Content-Type", "application/json")
.accept("application/json")
.exchange()
.expectedStatus.is2xxxSuccessful();
}
Run Code Online (Sandbox Code Playgroud)
我在想,既然控制器允许通过 get 调用将对象绑定到 POJO,那么应该有某种方法使用 webTestClient 来测试它。
java rest integration-testing spring-webclient webtestclient