From c662914896620b19a2bcf54c689d0268b13348cd Mon Sep 17 00:00:00 2001 From: thebignet Date: Fri, 28 Nov 2014 22:28:44 +0100 Subject: [PATCH] Added unit test to verify JobScope works when using both @EnableBatchProcessing and XML namespace --- .../JobScopeConfigurationTests.java | 45 +++++++++++++++++-- ...onTestsXmlImportUsingNamespace-context.xml | 20 +++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsXmlImportUsingNamespace-context.xml diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java index 8164d792f..1fed5213b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTests.java @@ -16,28 +16,34 @@ package org.springframework.batch.core.configuration.annotation; +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.Callable; + import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; + import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; +import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.scope.context.JobSynchronizationManager; +import org.springframework.batch.core.step.tasklet.Tasklet; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.context.support.ClassPathXmlApplicationContext; -import java.util.concurrent.Callable; - -import static org.junit.Assert.assertEquals; - /** * @author Dave Syer * @author Michael Minella @@ -87,6 +93,16 @@ public class JobScopeConfigurationTests { assertEquals("JOB", value.call()); } + @Test + public void testStepScopeXmlImportUsingNamespace() throws Exception { + init(JobScopeConfigurationXmlImportUsingNamespace.class); + + SimpleHolder value = (SimpleHolder) context.getBean("xmlValue"); + assertEquals("JOB", value.call()); + value = (SimpleHolder) context.getBean("javaValue"); + assertEquals("JOB", value.call()); + } + @Test public void testJobScopeWithProxyTargetClassInjected() throws Exception { init(JobScopeConfigurationInjectingProxy.class); @@ -201,6 +217,27 @@ public class JobScopeConfigurationTests { } + public static class TaskletSupport implements Tasklet { + + @Override + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { + return RepeatStatus.FINISHED; + } + } + + @Configuration + @ImportResource("org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsXmlImportUsingNamespace-context.xml") + @EnableBatchProcessing + public static class JobScopeConfigurationXmlImportUsingNamespace { + + @Bean + @JobScope + protected SimpleHolder javaValue(@Value("#{jobName}") final String value) { + return new SimpleHolder(value); + } + + } + @Configuration @EnableBatchProcessing public static class JobScopeConfigurationInjectingProxy { diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsXmlImportUsingNamespace-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsXmlImportUsingNamespace-context.xml new file mode 100644 index 000000000..efb834f9c --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/annotation/JobScopeConfigurationTestsXmlImportUsingNamespace-context.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file