Search in sources :

Example 6 with DefaultMockMvcBuilder

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

the class MvcEndpointIntegrationTests 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 7 with DefaultMockMvcBuilder

use of org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder in project spring-cloud-sleuth by spring-cloud.

the class AbstractMvcIntegrationTest method setup.

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

Example 8 with DefaultMockMvcBuilder

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

the class SpringBootMockMvcBuilderCustomizerTests method customizeShouldAddFilters.

@Test
@SuppressWarnings("unchecked")
void customizeShouldAddFilters() {
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
    MockServletContext servletContext = new MockServletContext();
    context.setServletContext(servletContext);
    context.register(ServletConfiguration.class, FilterConfiguration.class);
    context.refresh();
    DefaultMockMvcBuilder builder = MockMvcBuilders.webAppContextSetup(context);
    this.customizer = new SpringBootMockMvcBuilderCustomizer(context);
    this.customizer.customize(builder);
    FilterRegistrationBean<?> registrationBean = (FilterRegistrationBean<?>) context.getBean("filterRegistrationBean");
    Filter testFilter = (Filter) context.getBean("testFilter");
    Filter otherTestFilter = registrationBean.getFilter();
    List<Filter> filters = (List<Filter>) ReflectionTestUtils.getField(builder, "filters");
    assertThat(filters).containsExactlyInAnyOrder(testFilter, otherTestFilter);
}
Also used : DefaultMockMvcBuilder(org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder) AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) Filter(jakarta.servlet.Filter) ArrayList(java.util.ArrayList) List(java.util.List) MockServletContext(org.springframework.mock.web.MockServletContext) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultMockMvcBuilder

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

the class WebMvcEndpointIntegrationTests 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)

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