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();
}
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);
}
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();
}
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();
}
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;
}
Aggregations