-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another
Description
Synopsis
As I was experimenting with the @WebFluxTest
s to test Reactive controllers, I noticed that the provided test auto-configurations do not import the default ErrorWebExceptionHandler
, so the following test would fail:
@AutoConfigureErrors
@RunWith(SpringRunner.class)
@WebFluxTest(PersonController.class)
public class ReactiveWebApplicationTests {
@Autowired private WebTestClient webClient;
@Test
public void personName_CanNotBeBlank() {
webClient.post().uri("/persons")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.syncBody("{}")
.exchange()
.expectStatus().isBadRequest()
.expectBody()
.jsonPath("$.errors[0].code").isEqualTo("name.blank");
}
}
This can be easily fixed just by importing the ErrorWebFluxAutoConfiguration
:
@AutoConfigureErrors
@RunWith(SpringRunner.class)
@WebFluxTest(PersonController.class)
@ImportAutoConfiguration(ErrorWebFluxAutoConfiguration.class)
public class ReactiveWebApplicationTests {
@Autowired private WebTestClient webClient;
@Test
public void personName_CanNotBeBlank() {
webClient.post().uri("/persons")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.syncBody("{}")
.exchange()
.expectStatus().isBadRequest()
.expectBody()
.jsonPath("$.errors[0].code").isEqualTo("name.blank");
}
}
Suggestion
Although the problem is so easy to fix, that'd be great if we import the default auto-configuration automatically. For example by adding an AutoConfigureErrorWebFlux
annotation.
Related Issues
Apparently supporting WebExceptionHandler
s was added in #13627 but the default auto-configuration is missing from the WebFluxTest
.
Metadata
Metadata
Assignees
Labels
status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by another