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

Document how to use WebTestClientBuilderCustomizer to configure REST Docs' parameterized output #27747

Closed
wilkinsona opened this issue Aug 18, 2021 · 2 comments
Labels
status: superseded An issue that has been superseded by another type: documentation A documentation update

Comments

@wilkinsona
Copy link
Member

We already have an example showing how to do it with MockMvc. It'd be good to have an equivalent example for WebTestClient. See spring-projects/spring-restdocs#741 for some background.

@wilkinsona wilkinsona added the type: documentation A documentation update label Aug 18, 2021
@wilkinsona wilkinsona added this to the 2.4.x milestone Aug 18, 2021
@brneto
Copy link

brneto commented Aug 18, 2021

I just noticed an issue with this approach with my Spring Contract Testing. I'm investigating why first. I share it with you anyway.

I have a base contract base class that implements an abstract class where the RestAssureWebTestClient happens.
e.g.

ContractBase:

abstract class ChassisBase extends ContractTest {

    @MockBean
    private Service service;

    @BeforeEach
    void setUp() {
        // init
        webTestClientSetup();

        // given
        var entity =
                new Entity()
                        .setId(1L)
                        .setName("test name")
                        .setDescription("description test");

        given(service.findAllItems())
                .willReturn(Flux.just(entity));
    }
}

AbstractContractTest (working):

@WebFluxTest
@AutoConfigureRestDocs
abstract class ContractTest {

    @Autowired
    private ApplicationContext context;

    @Autowired
    private WebTestClientRestDocumentationConfigurer configurer;

    void webTestClientSetup() {
        RestAssuredWebTestClient.webTestClient(
                WebTestClient
                        .bindToApplicationContext(context)
                        .configureClient()
                        .filter(configurer)
                        .entityExchangeResultConsumer(document("{class-name}/{method-name}"))
                        .build());
    }

AbstractContractTest (not working):

@WebFluxTest
@AutoConfigureRestDocs
abstract class ContractTest {

    @TestConfiguration
    static class RestDocsParameterizedOutput {

        @Bean
        WebTestClientBuilderCustomizer restDocsParameterizedOutput() {
            return builder -> builder.entityExchangeResultConsumer(document("{class-name}/{method-name}"));
        }
    }

    @Autowired
    private WebTestClient webClient;

    void webTestClientSetup() {
        RestAssuredWebTestClient.webTestClient(webTestClient);
    }

@wilkinsona
Copy link
Member Author

Closing in favor of #27755.

@wilkinsona wilkinsona removed this from the 2.4.x milestone Aug 18, 2021
@wilkinsona wilkinsona added the status: superseded An issue that has been superseded by another label Aug 18, 2021
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 type: documentation A documentation update
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants