From 0b52801e3577bcff0982bd1b147b50f690086081 Mon Sep 17 00:00:00 2001 From: dsyer Date: Fri, 5 Oct 2007 15:32:52 +0000 Subject: [PATCH] RESOLVED - issue BATCH-142: DefaultStepExecutorFactory as the stepExecutorFactory for the DefaultJobExecutor http://opensource.atlassian.com/projects/spring/browse/BATCH-142 --- .../step/SimpleStepExecutorFactory.java | 16 +++++++++++++++- .../step/SimpleStepExecutorFactoryTests.java | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java b/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java index 27df2be31..e33da04f2 100644 --- a/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java +++ b/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java @@ -23,6 +23,7 @@ import org.springframework.batch.execution.step.simple.SimpleStepExecutor; import org.springframework.batch.repeat.RepeatOperations; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; +import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; /** @@ -32,7 +33,7 @@ import org.springframework.util.Assert; * @author Dave Syer * */ -public class SimpleStepExecutorFactory implements StepExecutorFactory { +public class SimpleStepExecutorFactory implements StepExecutorFactory, InitializingBean { private JobRepository jobRepository; @@ -70,8 +71,21 @@ public class SimpleStepExecutorFactory implements StepExecutorFactory { } + /** + * Public setter for {@link JobRepository}. + * + * @param jobRepository is a mandatory dependence (no default). + */ public void setJobRepository(JobRepository jobRepository) { this.jobRepository = jobRepository; } + /** + * Assert that all mandatory properties are set (the {@link JobRepository}). + * + * @throws Exception + */ + public void afterPropertiesSet() throws Exception { + Assert.notNull(jobRepository); + } } diff --git a/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java b/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java index 229116113..09f621138 100644 --- a/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java @@ -62,4 +62,14 @@ public class SimpleStepExecutorFactoryTests extends TestCase { "JobRepository") >= 0); } } + + public void testMandatoryProperties() throws Exception { + factory = new SimpleStepExecutorFactory(); + try { + factory.afterPropertiesSet(); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } }