Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@WebFluxTest Doesn't Import the ErrorWebFluxAutoConfiguration #16258

Closed
alimate opened this issue Mar 19, 2019 · 5 comments
Closed

@WebFluxTest Doesn't Import the ErrorWebFluxAutoConfiguration #16258

alimate opened this issue Mar 19, 2019 · 5 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@alimate
Copy link
Contributor

alimate commented Mar 19, 2019

Synopsis

As I was experimenting with the @WebFluxTests 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 WebExceptionHandlers was added in #13627 but the default auto-configuration is missing from the WebFluxTest.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2019
@wilkinsona
Copy link
Member

Well spotted. This seems like a bug to me, particularly as @WebMvcTest imports the equivalent auto-configuration for the servlet stack. Do you agree, @bclozel?

@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 19, 2019
@bclozel bclozel modified the milestones: 2.1.4, 2.1.x Mar 19, 2019
@bclozel
Copy link
Member

bclozel commented Mar 19, 2019

Yes, we should align with our existing MVC setup here.

@alimate
Copy link
Contributor Author

alimate commented Mar 19, 2019

@bclozel @wilkinsona May I provide a PR to fix that?

@wilkinsona
Copy link
Member

@alimate Yes, please. That would be much appreciated.

@mbhave
Copy link
Contributor

mbhave commented Mar 22, 2019

Closing in favor of PR #16266.

@mbhave mbhave closed this as completed Mar 22, 2019
@mbhave mbhave added status: superseded An issue that has been superseded by another and removed type: bug A general bug labels Mar 22, 2019
@mbhave mbhave removed this from the 2.1.x milestone Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

5 participants