Java Code Examples for org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder

Following code examples demonstrate how to use org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilderfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilderand various code implementation of this class.

    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext)
                .addFilters(paramFilter)
                .build();
        this.webClient = MockMvcWebClientBuilder
                .mockMvcSetup(this.mockMvc)
                .build();
        this.webDriver = MockMvcHtmlUnitDriverBuilder
                .mockMvcSetup(this.mockMvc)
                .build();
    } 


    @PostConstruct
    void init()
    {
        client = MockMvcWebClientBuilder
            .webAppContextSetup(context, springSecurity())
            .build();

        client.setAlertHandler((page, message) -> alertHandler(message));
        client.setConfirmHandler((page, message) -> confirmHandler(message));
        client.setPromptHandler((page, message) -> promptHandler(message));
    } 

Advertisement
Javadoc
MockMvcWebClientBuilder simplifies the creation of an HtmlUnit WebClient that delegates to a MockMvc

instance.

The MockMvc instance used by the builder may be {@linkplain #mockMvcSetup supplied directly or created transparently from a #webAppContextSetup WebApplicationContext. @author Rob Winch @author Sam Brannen @since 4.2 @see #mockMvcSetup(MockMvc) @see #webAppContextSetup(WebApplicationContext) @see #webAppContextSetup(WebApplicationContext, MockMvcConfigurer) @see #withDelegate(WebClient) @see #build()

Read More
Advertisement