BATCH-2227: Allow multiple configs (xmls, java-files, packages) to be

loaded in ApplicationContextFactory
This commit is contained in:
Thomas Bosch
2014-04-24 15:13:15 +02:00
committed by Chris Schaefer
parent 6e4b0cb045
commit 90aca9c98b
5 changed files with 163 additions and 47 deletions

View File

@@ -21,7 +21,11 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
@@ -133,6 +137,40 @@ public class GenericApplicationContextFactoryTests {
assertEquals(other.hashCode(), factory.hashCode());
}
@Test
public void testEqualsMultileConfigs() throws Exception {
Resource resource1 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"abstract-context.xml"));
Resource resource2 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"child-context-with-abstract-job.xml"));
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource1, resource2);
GenericApplicationContextFactory other = new GenericApplicationContextFactory(resource1, resource2);
assertEquals(other, factory);
assertEquals(other.hashCode(), factory.hashCode());
}
@Test
public void testParentConfigurationInheritedMultipleConfigs() {
Resource resource1 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"abstract-context.xml"));
Resource resource2 = new ClassPathResource(ClassUtils.addResourcePathToPackagePath(getClass(),
"child-context-with-abstract-job.xml"));
GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource1, resource2);
ConfigurableApplicationContext context = factory.createApplicationContext();
assertEquals("concrete-job", context.getBeanNamesForType(Job.class)[0]);
assertEquals("bar", context.getBean("concrete-job", Job.class).getName());
assertEquals(4, context.getBean("foo", Foo.class).values[1], 0.01);
assertNotNull(context.getBean("concrete-job", JobSupport.class).getStep("step31"));
assertNotNull(context.getBean("concrete-job", JobSupport.class).getStep("step32"));
boolean autowiredFound = false;
for (BeanPostProcessor postProcessor : ((AbstractBeanFactory)context.getBeanFactory()).getBeanPostProcessors()) {
if (postProcessor instanceof AutowiredAnnotationBeanPostProcessor) {
autowiredFound = true;
}
}
assertTrue(autowiredFound);
}
public static class Foo {
private double[] values;