Search in sources :

Example 1 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project tutorials by eugenp.

the class RequestMapingShortcutsIntegrationTest method setup.

@Before
public void setup() {
    DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.ctx);
    this.mockMvc = builder.build();
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) Before(org.junit.Before)

Example 2 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project rest-assured by rest-assured.

the class RestAssuredMockMvc method webAppContextSetup.

/**
 * Build a {@link MockMvc} using the given, fully initialized, i.e.
 * refreshed, {@link WebApplicationContext} and assign it to REST Assured.
 * The {@link org.springframework.web.servlet.DispatcherServlet}
 * will use the context to discover Spring MVC infrastructure and
 * application controllers in it. The context must have been configured with
 * a {@link javax.servlet.ServletContext}.
 *
 * @param context            The web application context to use
 * @param mockMvcConfigurers {@link MockMvcConfigurer}'s to be applied when creating a {@link MockMvc} instance of this WebApplicationContext (optional)
 */
public static void webAppContextSetup(WebApplicationContext context, MockMvcConfigurer... mockMvcConfigurers) {
    // To avoid compile-time errors
    DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(context);
    if (mockMvcConfigurers != null && mockMvcConfigurers.length > 0) {
        for (MockMvcConfigurer mockMvcConfigurer : mockMvcConfigurers) {
            builder.apply(mockMvcConfigurer);
        }
    }
    mockMvcFactory = new MockMvcFactory(builder);
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) MockMvcFactory(io.restassured.module.mockmvc.internal.MockMvcFactory) StandaloneMockMvcFactory(io.restassured.module.mockmvc.internal.StandaloneMockMvcFactory) MockMvcConfigurer(org.springframework.test.web.servlet.setup.MockMvcConfigurer)

Example 3 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project instrumentation-java by census-instrumentation.

the class AbstractMvcIntegrationTest method setup.

@Before
public void setup() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/view/");
    viewResolver.setSuffix(".jsp");
    DefaultMockMvcBuilder mockMvcBuilder = MockMvcBuilders.webAppContextSetup(this.webApplicationContext);
    configureMockMvcBuilder(mockMvcBuilder);
    this.mockMvc = mockMvcBuilder.build();
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Before(org.junit.Before)

Example 4 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project spring-boot by spring-projects.

the class ControllerEndpointWebMvcIntegrationTests method doCreateMockMvc.

private MockMvc doCreateMockMvc(MockMvcConfigurer... configurers) {
    this.context.setServletContext(new MockServletContext());
    this.context.refresh();
    DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.context);
    for (MockMvcConfigurer configurer : configurers) {
        builder.apply(configurer);
    }
    return builder.build();
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) MockMvcConfigurer(org.springframework.test.web.servlet.setup.MockMvcConfigurer) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 5 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project spring-boot by spring-projects.

the class MockMvcAutoConfiguration method mockMvcBuilder.

@Bean
@ConditionalOnMissingBean(MockMvcBuilder.class)
public DefaultMockMvcBuilder mockMvcBuilder(List<MockMvcBuilderCustomizer> customizers) {
    DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(this.context);
    builder.addDispatcherServletCustomizer(new MockMvcDispatcherServletCustomizer(this.webMvcProperties));
    for (MockMvcBuilderCustomizer customizer : customizers) {
        customizer.customize(builder);
    }
    return builder;
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultMockMvcBuilder (org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder)9 MockServletContext (org.springframework.mock.web.MockServletContext)4 MockMvcConfigurer (org.springframework.test.web.servlet.setup.MockMvcConfigurer)4 Before (org.junit.Before)3 MockMvcFactory (io.restassured.module.mockmvc.internal.MockMvcFactory)1 StandaloneMockMvcFactory (io.restassured.module.mockmvc.internal.StandaloneMockMvcFactory)1 Filter (jakarta.servlet.Filter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 AnnotationConfigServletWebApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)1