Java 类org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder 实例源码

项目:spring-boot-controller-test-example    文件:TestHelper.java   
public MockMvc mvc(Object controller) {
    StandaloneMockMvcBuilder builder = new StandaloneMockMvcBuilder(controller) {
        @Override
        protected WebApplicationContext initWebAppContext() {
            WebApplicationContext context = super.initWebAppContext();
            StaticListableBeanFactory beanFactory = (StaticListableBeanFactory)context.getAutowireCapableBeanFactory();

            Arrays.stream(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, Object.class))
                .filter(name -> applicationContext.findAnnotationOnBean(name, ControllerAdvice.class) != null)
                .forEach(name -> beanFactory.addBean(name, applicationContext.getBean(name)));

            context.getBean(RequestMappingHandlerAdapter.class).afterPropertiesSet();
            return context;
        }
    };
    return builder.setHandlerExceptionResolvers(handlerExceptionResolver).build();
}
项目:fullstop    文件:RestControllerTestSupport.java   
protected void configure(final StandaloneMockMvcBuilder mockMvcBuilder) {
    mockMvcBuilder.setCustomArgumentResolvers(mockMvcCustomArgumentResolvers());
    mockMvcBuilder.setMessageConverters(mockMvcMessageConverters());

    final DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    mockMvcBuilder.setConversionService(conversionService);
}
项目:fullstop    文件:FullstopApiTest.java   
@Override
protected void configure(final StandaloneMockMvcBuilder mockMvcBuilder) {
    super.configure(mockMvcBuilder);
    mockMvcBuilder.alwaysDo(print());
}
项目:fullstop    文件:RestControllerTestSupport.java   
@Before
public void setUpMockMvc() throws Exception {
    final StandaloneMockMvcBuilder mockMvcBuilder = MockMvcBuilders.standaloneSetup(mockMvcControllers());
    configure(mockMvcBuilder);
    mockMvc = mockMvcBuilder.build();
}