Search in sources :

Example 1 with RequestPostProcessor

use of org.springframework.test.web.servlet.request.RequestPostProcessor in project spring-boot by spring-projects.

the class NoSpringSecurityHealthMvcEndpointIntegrationTests method getRequestPostProcessor.

private RequestPostProcessor getRequestPostProcessor() {
    return new RequestPostProcessor() {

        @Override
        public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
            Principal principal = mock(Principal.class);
            request.setUserPrincipal(principal);
            return request;
        }
    };
}
Also used : RequestPostProcessor(org.springframework.test.web.servlet.request.RequestPostProcessor) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Principal(java.security.Principal)

Example 2 with RequestPostProcessor

use of org.springframework.test.web.servlet.request.RequestPostProcessor 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

RequestPostProcessor (org.springframework.test.web.servlet.request.RequestPostProcessor)2 Principal (java.security.Principal)1 Filter (javax.servlet.Filter)1 ServletContext (javax.servlet.ServletContext)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockServletConfig (org.springframework.mock.web.MockServletConfig)1 ConfigurableSmartRequestBuilder (org.springframework.test.web.servlet.request.ConfigurableSmartRequestBuilder)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1