From 622e27de9c13e365da031c561086b40adcd5b1a2 Mon Sep 17 00:00:00 2001 From: dsyer Date: Tue, 11 Dec 2007 11:46:56 +0000 Subject: [PATCH] OPEN - issue BATCH-243: Register Job twice if beanName property is used to define a job name http://opensource.atlassian.com/projects/spring/browse/BATCH-243 Added test case for double registration. --- spring-batch-execution/.springBeans | 4 +- ...urationRegistryBeanPostProcessorTests.java | 17 +++++- .../execution/configuration/test-context.xml | 53 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml diff --git a/spring-batch-execution/.springBeans b/spring-batch-execution/.springBeans index d31740914..a78899bd3 100644 --- a/spring-batch-execution/.springBeans +++ b/spring-batch-execution/.springBeans @@ -1,7 +1,7 @@ 1 - + @@ -12,6 +12,8 @@ src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml src/test/resources/org/springframework/batch/execution/bootstrap/support/test-batch-environment.xml src/test/resources/org/springframework/batch/execution/bootstrap/support/test-batch-environment-no-launcher.xml + src/test/resources/org/springframework/batch/execution/configuration/test-context.xml + src/test/resources/org/springframework/batch/execution/scope/scope-tests.xml diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java index 3842562c5..e7b26a593 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/configuration/JobConfigurationRegistryBeanPostProcessorTests.java @@ -15,14 +15,15 @@ */ package org.springframework.batch.execution.configuration; +import java.util.Collection; + import junit.framework.TestCase; import org.springframework.batch.core.configuration.DuplicateJobConfigurationException; import org.springframework.batch.core.configuration.JobConfiguration; import org.springframework.batch.core.configuration.NoSuchJobConfigurationException; -import org.springframework.batch.execution.configuration.JobConfigurationRegistryBeanPostProcessor; -import org.springframework.batch.execution.configuration.MapJobConfigurationRegistry; import org.springframework.beans.FatalBeanException; +import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Dave Syer @@ -91,4 +92,16 @@ public class JobConfigurationRegistryBeanPostProcessorTests extends TestCase { // expected } } + + public void testExecutionWithApplicationContext() throws Exception { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml", getClass()); + MapJobConfigurationRegistry registry = (MapJobConfigurationRegistry) context.getBean("registry"); + Collection configurations = registry.getJobConfigurations(); + assertEquals(6, configurations.size()); + assertNotNull(registry.getJobConfiguration("test-job")); + assertEquals(context.getBean("test-job-with-name"), registry.getJobConfiguration("foo")); + assertEquals(context.getBean("test-job-with-bean-name"), registry.getJobConfiguration("bar")); + assertEquals(context.getBean("test-job-with-parent-and-name"), registry.getJobConfiguration("spam")); + assertEquals(context.getBean("test-job-with-parent-and-bean-name"), registry.getJobConfiguration("bucket")); + } } diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml new file mode 100644 index 000000000..33d001bac --- /dev/null +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/configuration/test-context.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +