Search in sources :

Example 1 with ConfigurableSmartRequestBuilder

use of org.springframework.test.web.servlet.request.ConfigurableSmartRequestBuilder in project spring-framework by spring-projects.

the class AbstractMockMvcBuilder method build.

/**
	 * Build a {@link org.springframework.test.web.servlet.MockMvc} instance.
	 */
@Override
@SuppressWarnings("rawtypes")
public final MockMvc build() {
    WebApplicationContext wac = initWebAppContext();
    ServletContext servletContext = wac.getServletContext();
    MockServletConfig mockServletConfig = new MockServletConfig(servletContext);
    for (MockMvcConfigurer configurer : this.configurers) {
        RequestPostProcessor processor = configurer.beforeMockMvcCreated(this, wac);
        if (processor != null) {
            if (this.defaultRequestBuilder == null) {
                this.defaultRequestBuilder = MockMvcRequestBuilders.get("/");
            }
            if (this.defaultRequestBuilder instanceof ConfigurableSmartRequestBuilder) {
                ((ConfigurableSmartRequestBuilder) this.defaultRequestBuilder).with(processor);
            }
        }
    }
    Filter[] filterArray = this.filters.toArray(new Filter[this.filters.size()]);
    return super.createMockMvc(filterArray, mockServletConfig, wac, this.defaultRequestBuilder, this.globalResultMatchers, this.globalResultHandlers, this.dispatcherServletCustomizers);
}
Also used : RequestPostProcessor(org.springframework.test.web.servlet.request.RequestPostProcessor) Filter(javax.servlet.Filter) ConfigurableSmartRequestBuilder(org.springframework.test.web.servlet.request.ConfigurableSmartRequestBuilder) ServletContext(javax.servlet.ServletContext) MockServletConfig(org.springframework.mock.web.MockServletConfig) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

Filter (javax.servlet.Filter)1 ServletContext (javax.servlet.ServletContext)1 MockServletConfig (org.springframework.mock.web.MockServletConfig)1 ConfigurableSmartRequestBuilder (org.springframework.test.web.servlet.request.ConfigurableSmartRequestBuilder)1 RequestPostProcessor (org.springframework.test.web.servlet.request.RequestPostProcessor)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1