It's currently not supported to use java config out of the box.
You need to pass the mocks created from Spring to the TestExecutor which is only possible by a custom implementation of IProcessingContextBuilder:
@WebAppConfiguration
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTest {
@Configuration
public static class ContextConfiguration {
// some beans
}
@Autowired
private WebApplicationContext applicationContext;
@Autowired
private MockServletContext servletContext;
@Autowired
private MockHttpServletRequest request;
@Autowired
private MockHttpServletResponse response;
@Autowired
private ServletWebRequest webRequest;
private TestExecutor executor;
@Before
public void setUp() {
IProcessingContextBuilder processingContextBuilder = new CustomContextBuilder(applicationContext, servletContext, session, request, response, webRequest);
List<IDialect> dialects = new ArrayList<IDialect>();
dialects.add(new SpringStandardDialect());
executor = new TestExecutor();
executor.setProcessingContextBuilder(processingContextBuilder);
executor.setDialects(dialects);
}
// some tests
}
And this is where the trouble begins: You cannot simply extend from SpringWebProcessingContextBuilder as most of the methods createApplicationContext, createMockServletContext, createMockHttpServletRequest, createMockHttpServletResponse are final and the ServletWebRequest will be initialized directly in doAdditionalVariableProcessing instead of an own method.
So I ended up in copying all the stuff of the classes which works but is really ugly:
It's currently not supported to use java config out of the box. You need to pass the mocks created from Spring to the TestExecutor which is only possible by a custom implementation of
IProcessingContextBuilder
:And this is where the trouble begins: You cannot simply extend from
SpringWebProcessingContextBuilder
as most of the methodscreateApplicationContext
,createMockServletContext
,createMockHttpServletRequest
,createMockHttpServletResponse
are final and theServletWebRequest
will be initialized directly indoAdditionalVariableProcessing
instead of an own method.So I ended up in copying all the stuff of the classes which works but is really ugly: