use of io.restassured.module.mockmvc.internal.MockMvcFactory 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 io.restassured.module.mockmvc.internal.MockMvcFactory in project rest-assured by rest-assured.
the class MockMvcRequestSpecBuilder method getConfiguredMockMvcFactory.
private static MockMvcFactory getConfiguredMockMvcFactory() {
try {
Field mockMvcFactory = RestAssuredMockMvc.class.getDeclaredField("mockMvcFactory");
mockMvcFactory.setAccessible(true);
Object instance = mockMvcFactory.get(RestAssuredMockMvc.class);
mockMvcFactory.setAccessible(false);
return (MockMvcFactory) instance;
} catch (Exception e) {
throw new RuntimeException("Internal error: Cannot find mockMvcFactory field in " + RestAssuredMockMvc.class.getName());
}
}
Aggregations