@Override public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) { return request -> { request.setUserPrincipal(mock(Principal.class)); return request; }; }
@Override public void customize(ConfigurableMockMvcBuilder<?> builder) { if (this.addFilters) { addFilters(builder); } if (this.alwaysPrint) { builder.alwaysDo(MockMvcResultHandlers.print(System.out)); } }
private void addFilters(ConfigurableMockMvcBuilder<?> builder) { ServletContextInitializerBeans Initializers = new ServletContextInitializerBeans( this.context); for (ServletContextInitializer initializer : Initializers) { if (initializer instanceof FilterRegistrationBean) { addFilter(builder, (FilterRegistrationBean) initializer); } if (initializer instanceof DelegatingFilterProxyRegistrationBean) { addFilter(builder, (DelegatingFilterProxyRegistrationBean) initializer); } } }
private void addFilter(ConfigurableMockMvcBuilder<?> builder, Filter filter, Collection<String> urls) { if (urls.isEmpty()) { builder.addFilters(filter); } else { builder.addFilter(filter, urls.toArray(new String[urls.size()])); } }
@Override public void customize(ConfigurableMockMvcBuilder<?> builder) { builder.apply(this.delegate); if (this.resultHandler != null) { builder.alwaysDo(this.resultHandler); } }
@Override public void afterConfigurerAdded(ConfigurableMockMvcBuilder<?> builder) { builder.alwaysExpect(status().isOk()); }
private void addFilter(ConfigurableMockMvcBuilder<?> builder, FilterRegistrationBean registration) { addFilter(builder, registration.getFilter(), registration.getUrlPatterns()); }
private void addFilter(ConfigurableMockMvcBuilder<?> builder, DelegatingFilterProxyRegistrationBean registration) { addFilter(builder, registration.getFilter(), registration.getUrlPatterns()); }
@Override public void afterConfigurerAdded(ConfigurableMockMvcBuilder<?> builder) { }
@Override public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) { AbstractControllerTest.this.lazySpringConstraintValidatorFactory.setDelegate(new SpringConstraintValidatorFactory(context.getAutowireCapableBeanFactory())); AbstractControllerTest.this.lazySpringConstraintValidatorFactory.setBeanFactory(context.getAutowireCapableBeanFactory()); return null; }
/** * Customize the given {@code builder}. * @param builder the builder */ void customize(ConfigurableMockMvcBuilder<?> builder);