From bd01760466fcf4fcefee42e99d3a20508338411d Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Thu, 1 May 2014 19:32:36 -0400 Subject: [PATCH] add test case for BATCH-2025 --- .../DefaultJobParametersExtractorTests.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/DefaultJobParametersExtractorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/DefaultJobParametersExtractorTests.java index 6eadff04c..82012fc50 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/DefaultJobParametersExtractorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/DefaultJobParametersExtractorTests.java @@ -22,6 +22,7 @@ import java.util.Date; import org.junit.Test; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.StepExecution; /** @@ -88,4 +89,39 @@ public class DefaultJobParametersExtractorTests { assertEquals("{foo="+date.getTime()+"}", jobParameters.toString()); } + @Test + public void testUseParentParameters() throws Exception { + JobExecution jobExecution = new JobExecution(0L, new JobParametersBuilder() + .addString("parentParam", "val") + .toJobParameters()); + + StepExecution stepExecution = new StepExecution("step", jobExecution); + + stepExecution.getExecutionContext().putDouble("foo", 11.1); + extractor.setKeys(new String[] {"foo(double)"}); + JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); + + String jobParams = jobParameters.toString(); + + assertTrue("Job parameters must contain parentParam=val", jobParams.contains("parentParam=val")); + assertTrue("Job parameters must contain foo=11.1", jobParams.contains("foo=11.1")); + } + + @Test + public void testDontUseParentParameters() throws Exception { + DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor(); + extractor.setUseAllParentParameters(false); + + JobExecution jobExecution = new JobExecution(0L, new JobParametersBuilder() + .addString("parentParam", "val") + .toJobParameters()); + + StepExecution stepExecution = new StepExecution("step", jobExecution); + + stepExecution.getExecutionContext().putDouble("foo", 11.1); + extractor.setKeys(new String[] {"foo(double)"}); + JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); + + assertEquals("{foo=11.1}", jobParameters.toString()); + } }