Hi
There is a difference between cuba 6 and cuba 7 regarding overriding of bean for testing.
In cuba 6 TestContainer inited this way
public TestContainer() {
[...]
springConfig = "test-spring.xml";
[...]
}
So you could simple create a test-spring.xml in root package of core tests and you could easily override beans for testing.
Now in cuba 7:
public TestContainer() {
[...]
springConfig = "com/haulmont/cuba/testsupport/test-spring.xml";
[...]
}
I’m struggling to add my own test-spring.xml. I tried adding a test-app properties file along following ways
cuba.springContextConfig = +com/company/svp/test-spring.xml
=> does not work as it replace the entry cuba.springContextConfig = com/company/svp/spring.xml
in app.properties
cuba.springContextConfig = com/company/svp/spring.xml com/company/svp/test-spring.xml
=> does not work as cuba spring is not taken into account
cuba.springContextConfig = +com/company/svp/spring.xml +com/company/svp/test-spring.xml
=> I had great expectations for this one but it fails
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [+com/company/svp/test-spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [+com/company/svp/test-spring.xml] cannot be opened because it does not exist
I would have liked to override the initAppContext()
method of TestContainer
to add location manually, but some stuff is private, namely
protected void initAppContext() {
EclipseLinkCustomizer.initTransientCompatibleAnnotations();
String configProperty = AppContext.getProperty(AbstractAppContextLoader.SPRING_CONTEXT_CONFIG);
StringTokenizer tokenizer = new StringTokenizer(configProperty);
List<String> locations = tokenizer.getTokenList();
locations.add(getSpringConfig());
// here I would have like to add test-spring.xml location manually
locations.add("test-spring.xml")
// but springAppContext is private
springAppContext = new CubaCoreApplicationContext(locations.toArray(new String[0]));
AppContext.Internals.setApplicationContext(springAppContext);
Events events = springAppContext.getBean(Events.class);
events.publish(new AppContextInitializedEvent(springAppContext));
}
Except if I’m mistaken this part is not documented, that could have helped.
Regards
Michael