BATCH-2001: fix up property scoping, add support for resolving jobParameter references outside of step scope
This commit is contained in:
committed by
Michael Minella
parent
2c1b8e154a
commit
10e58baf80
@@ -21,6 +21,7 @@ import java.util.Properties;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -37,20 +38,20 @@ public class BatchPropertyContextTests {
|
||||
public void setUp() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties bean1Properties = new Properties();
|
||||
bean1Properties.setProperty("readerName", "bean1readerName");
|
||||
bean1Properties.setProperty("readerWriter", "bean1writerName");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("bean1", bean1Properties));
|
||||
Properties step1Properties = new Properties();
|
||||
step1Properties.setProperty("step1PropertyName1", "step1PropertyValue1");
|
||||
step1Properties.setProperty("step1PropertyName2", "step1PropertyValue2");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.step1", step1Properties));
|
||||
|
||||
Properties bean2Properties = new Properties();
|
||||
bean2Properties.setProperty("readerName", "bean2readerName");
|
||||
bean2Properties.setProperty("readerWriter", "bean2writerName");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("bean2", bean2Properties));
|
||||
Properties step2Properties = new Properties();
|
||||
step2Properties.setProperty("step2PropertyName1", "step2PropertyValue1");
|
||||
step2Properties.setProperty("step2PropertyName2", "step2PropertyValue2");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.step2", step2Properties));
|
||||
|
||||
Properties jobProperties = new Properties();
|
||||
jobProperties.setProperty("jobProperty1", "jobProperty1value");
|
||||
jobProperties.setProperty("jobProperty2", "jobProperty2value");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job-testJob", jobProperties));
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.job-job1", jobProperties));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,21 +59,21 @@ public class BatchPropertyContextTests {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean1 = batchPropertyContext.getBatchProperties("bean1");
|
||||
assertEquals(4, bean1.size());
|
||||
assertEquals("bean1readerName", bean1.getProperty("readerName"));
|
||||
assertEquals("bean1writerName", bean1.getProperty("readerWriter"));
|
||||
assertEquals("jobProperty1value", bean1.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean1.getProperty("jobProperty2"));
|
||||
Properties step1BatchProperties = batchPropertyContext.getBatchProperties("job1.step1");
|
||||
assertEquals(4, step1BatchProperties.size());
|
||||
assertEquals("step1PropertyValue1", step1BatchProperties.getProperty("step1PropertyName1"));
|
||||
assertEquals("step1PropertyValue2", step1BatchProperties.getProperty("step1PropertyName2"));
|
||||
assertEquals("jobProperty1value", step1BatchProperties.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", step1BatchProperties.getProperty("jobProperty2"));
|
||||
|
||||
Properties bean2 = batchPropertyContext.getBatchProperties("bean2");
|
||||
assertEquals(4, bean2.size());
|
||||
assertEquals("bean2readerName", bean2.getProperty("readerName"));
|
||||
assertEquals("bean2writerName", bean2.getProperty("readerWriter"));
|
||||
assertEquals("jobProperty1value", bean2.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean2.getProperty("jobProperty2"));
|
||||
Properties step2BatchProperties = batchPropertyContext.getBatchProperties("job1.step2");
|
||||
assertEquals(4, step2BatchProperties.size());
|
||||
assertEquals("step2PropertyValue1", step2BatchProperties.getProperty("step2PropertyName1"));
|
||||
assertEquals("step2PropertyValue2", step2BatchProperties.getProperty("step2PropertyName2"));
|
||||
assertEquals("jobProperty1value", step2BatchProperties.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", step2BatchProperties.getProperty("jobProperty2"));
|
||||
|
||||
Properties jobProperties = batchPropertyContext.getBatchProperties("job-testJob");
|
||||
Properties jobProperties = batchPropertyContext.getBatchProperties("job1.job-job1");
|
||||
assertEquals(2, jobProperties.size());
|
||||
assertEquals("jobProperty1value", jobProperties.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", jobProperties.getProperty("jobProperty2"));
|
||||
@@ -82,17 +83,17 @@ public class BatchPropertyContextTests {
|
||||
public void testAddBatchContextEntriesToExistingArtifact() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties bean2Properties = new Properties();
|
||||
bean2Properties.setProperty("processorName", "bean2processorName");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("bean2", bean2Properties));
|
||||
Properties step1properties = new Properties();
|
||||
step1properties.setProperty("newStep1PropertyName", "newStep1PropertyValue");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.step1", step1properties));
|
||||
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean2 = batchPropertyContext.getBatchProperties("bean2");
|
||||
Properties bean2 = batchPropertyContext.getBatchProperties("job1.step1");
|
||||
assertEquals(5, bean2.size());
|
||||
assertEquals("bean2readerName", bean2.getProperty("readerName"));
|
||||
assertEquals("bean2writerName", bean2.getProperty("readerWriter"));
|
||||
assertEquals("bean2processorName", bean2.getProperty("processorName"));
|
||||
assertEquals("step1PropertyValue1", bean2.getProperty("step1PropertyName1"));
|
||||
assertEquals("step1PropertyValue2", bean2.getProperty("step1PropertyName2"));
|
||||
assertEquals("newStep1PropertyValue", bean2.getProperty("newStep1PropertyName"));
|
||||
assertEquals("jobProperty1value", bean2.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean2.getProperty("jobProperty2"));
|
||||
}
|
||||
@@ -102,78 +103,15 @@ public class BatchPropertyContextTests {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean1 = batchPropertyContext.getStepLevelProperties("bean1");
|
||||
Properties bean1 = batchPropertyContext.getStepLevelProperties("job1.step1");
|
||||
assertEquals(2, bean1.size());
|
||||
assertEquals("bean1readerName", bean1.getProperty("readerName"));
|
||||
assertEquals("bean1writerName", bean1.getProperty("readerWriter"));
|
||||
assertEquals("step1PropertyValue1", bean1.getProperty("step1PropertyName1"));
|
||||
assertEquals("step1PropertyValue2", bean1.getProperty("step1PropertyName2"));
|
||||
|
||||
Properties bean2 = batchPropertyContext.getStepLevelProperties("bean2");
|
||||
Properties bean2 = batchPropertyContext.getStepLevelProperties("job1.step2");
|
||||
assertEquals(2, bean2.size());
|
||||
assertEquals("bean2readerName", bean2.getProperty("readerName"));
|
||||
assertEquals("bean2writerName", bean2.getProperty("readerWriter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetScopedStepLevelProperties() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties scopedBeanProperties = new Properties();
|
||||
scopedBeanProperties.setProperty("scopedBeanName", "scopedBeanValue");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("scopedBean", scopedBeanProperties));
|
||||
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean1 = batchPropertyContext.getStepLevelProperties("bean1");
|
||||
assertEquals(2, bean1.size());
|
||||
assertEquals("bean1readerName", bean1.getProperty("readerName"));
|
||||
assertEquals("bean1writerName", bean1.getProperty("readerWriter"));
|
||||
|
||||
Properties bean2 = batchPropertyContext.getStepLevelProperties("bean2");
|
||||
assertEquals(2, bean2.size());
|
||||
assertEquals("bean2readerName", bean2.getProperty("readerName"));
|
||||
assertEquals("bean2writerName", bean2.getProperty("readerWriter"));
|
||||
|
||||
Properties scopedBean = batchPropertyContext.getStepLevelProperties("scopedTarget.scopedBean");
|
||||
assertEquals(1, scopedBean.size());
|
||||
assertEquals("scopedBeanValue", scopedBean.getProperty("scopedBeanName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetScopedBatchProperties() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties scopedBeanProperties = new Properties();
|
||||
scopedBeanProperties.setProperty("scopedBeanName", "scopedBeanValue");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("scopedBean", scopedBeanProperties));
|
||||
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean1 = batchPropertyContext.getBatchProperties("bean1");
|
||||
assertEquals(4, bean1.size());
|
||||
assertEquals("bean1readerName", bean1.getProperty("readerName"));
|
||||
assertEquals("bean1writerName", bean1.getProperty("readerWriter"));
|
||||
assertEquals("jobProperty1value", bean1.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean1.getProperty("jobProperty2"));
|
||||
|
||||
Properties bean2 = batchPropertyContext.getBatchProperties("bean2");
|
||||
assertEquals(4, bean2.size());
|
||||
assertEquals("bean2readerName", bean2.getProperty("readerName"));
|
||||
assertEquals("bean2writerName", bean2.getProperty("readerWriter"));
|
||||
assertEquals("jobProperty1value", bean2.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean2.getProperty("jobProperty2"));
|
||||
|
||||
Properties scopedBean = batchPropertyContext.getBatchProperties("scopedTarget.scopedBean");
|
||||
assertEquals(3, scopedBean.size());
|
||||
assertEquals("scopedBeanValue", scopedBean.getProperty("scopedBeanName"));
|
||||
assertEquals("jobProperty1value", scopedBean.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", scopedBean.getProperty("jobProperty2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOriginalBeanName() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
String originalName = batchPropertyContext.getOriginalBeanName("scopedTarget.myBean");
|
||||
assertTrue(originalName.equals("myBean"));
|
||||
assertEquals("step2PropertyValue1", bean2.getProperty("step2PropertyName1"));
|
||||
assertEquals("step2PropertyValue2", bean2.getProperty("step2PropertyName2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,7 +123,6 @@ public class BatchPropertyContextTests {
|
||||
assertEquals(2, jobProperties.size());
|
||||
assertEquals("jobProperty1value", jobProperties.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", jobProperties.getProperty("jobProperty2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,22 +130,52 @@ public class BatchPropertyContextTests {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties jobProperties = new Properties();
|
||||
jobProperties.setProperty("readerName", "testJobreaderName");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job-testJob", jobProperties));
|
||||
jobProperties.setProperty("step1PropertyName1", "step1PropertyOverride");
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.job-job1", jobProperties));
|
||||
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties bean1 = batchPropertyContext.getBatchProperties("bean1");
|
||||
Properties bean1 = batchPropertyContext.getBatchProperties("job1.step1");
|
||||
assertEquals(4, bean1.size());
|
||||
assertEquals("bean1readerName", bean1.getProperty("readerName"));
|
||||
assertEquals("bean1writerName", bean1.getProperty("readerWriter"));
|
||||
assertEquals("step1PropertyValue1", bean1.getProperty("step1PropertyName1"));
|
||||
assertEquals("step1PropertyValue2", bean1.getProperty("step1PropertyName2"));
|
||||
assertEquals("jobProperty1value", bean1.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", bean1.getProperty("jobProperty2"));
|
||||
|
||||
Properties testJobBean = batchPropertyContext.getBatchProperties("job-testJob");
|
||||
Properties testJobBean = batchPropertyContext.getBatchProperties("job1.job-job1");
|
||||
assertEquals(3, testJobBean.size());
|
||||
assertEquals("testJobreaderName", testJobBean.getProperty("readerName"));
|
||||
assertEquals("step1PropertyOverride", testJobBean.getProperty("step1PropertyName1"));
|
||||
assertEquals("jobProperty1value", testJobBean.getProperty("jobProperty1"));
|
||||
assertEquals("jobProperty2value", testJobBean.getProperty("jobProperty2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobLevelPropertiesWithPath() {
|
||||
List<BatchPropertyContext.BatchPropertyContextEntry> entries = new ArrayList<BatchPropertyContext.BatchPropertyContextEntry>();
|
||||
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
|
||||
Properties jobProperties = new Properties();
|
||||
jobProperties.setProperty("readerName", "testJobreaderName");
|
||||
|
||||
entries.add(batchPropertyContext.new BatchPropertyContextEntry("job1.job-job1.itemReader", jobProperties));
|
||||
|
||||
batchPropertyContext.setBatchContextEntries(entries);
|
||||
|
||||
Properties props = batchPropertyContext.getJobProperties();
|
||||
assertEquals(1, props.size());
|
||||
assertEquals("testJobreaderName", props.getProperty("readerName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobLevelComponentPath() {
|
||||
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
|
||||
assertTrue(batchPropertyContext.isJobLevelComponentPath("myJob.job-myJob"));
|
||||
assertTrue(batchPropertyContext.isJobLevelComponentPath("myJob.job-myJob.myReader"));
|
||||
assertTrue(batchPropertyContext.isJobLevelComponentPath("myJob.job-myJob.myReader.something"));
|
||||
assertFalse(batchPropertyContext.isJobLevelComponentPath("myJob"));
|
||||
assertFalse(batchPropertyContext.isJobLevelComponentPath("job-myJob"));
|
||||
assertFalse(batchPropertyContext.isJobLevelComponentPath(null));
|
||||
assertFalse(batchPropertyContext.isJobLevelComponentPath("myJob."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,24 +53,8 @@ public class JobPropertySubstitutionTests {
|
||||
@Autowired
|
||||
private JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
private TestItemWriter testItemWriter;
|
||||
|
||||
@Autowired
|
||||
private TestItemReader testItemReader;
|
||||
|
||||
@Test
|
||||
public void testSystemPropertySubstitution() throws Exception {
|
||||
assertEquals(System.getProperty("file.separator"), testItemReader.readerPropertyName1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobPropertySubstitution() throws Exception {
|
||||
assertEquals("jobPropertyValue1", testItemWriter.writerPropertyName1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobParameterSubstitution() throws Exception {
|
||||
public void testPropertySubstitutionSimple() throws Exception {
|
||||
JobExecution jobExecution = jobLauncher.run(job,
|
||||
new JobParametersBuilder().addString("testParam", "testParamValue").toJobParameters());
|
||||
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
|
||||
@@ -85,7 +69,7 @@ public class JobPropertySubstitutionTests {
|
||||
|
||||
@Override
|
||||
public void open(Serializable serializable) throws Exception {
|
||||
|
||||
assertEquals(System.getProperty("file.separator"), readerPropertyName1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +99,7 @@ public class JobPropertySubstitutionTests {
|
||||
|
||||
@Override
|
||||
public void open(Serializable serializable) throws Exception {
|
||||
|
||||
assertEquals("jobPropertyValue1", writerPropertyName1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,10 +25,9 @@ import javax.batch.api.chunk.CheckpointAlgorithm;
|
||||
import javax.batch.api.chunk.ItemProcessor;
|
||||
import javax.batch.api.chunk.ItemReader;
|
||||
import javax.batch.api.chunk.ItemWriter;
|
||||
import javax.batch.api.listener.StepListener;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
@@ -43,10 +38,11 @@ import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Test cases for parsing various <properties /> elements defined by JSR-352.
|
||||
* Configuration test for parsing various <properties /> elements defined by JSR-352.
|
||||
* </p>
|
||||
*
|
||||
* @author Chris Schaefer
|
||||
@@ -54,124 +50,24 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JobPropertyTests {
|
||||
@Autowired
|
||||
private TestItemReader testItemReader;
|
||||
|
||||
@Autowired
|
||||
private Job job;
|
||||
|
||||
@Autowired
|
||||
private JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
private TestItemProcessor testItemProcessor;
|
||||
|
||||
@Autowired
|
||||
private TestItemWriter testItemWriter;
|
||||
|
||||
@Autowired
|
||||
private TestCheckpointAlgorithm testCheckpointAlgorithm;
|
||||
|
||||
@Autowired
|
||||
private TestDecider testDecider;
|
||||
|
||||
@Autowired
|
||||
private TestStepListener testStepListener;
|
||||
|
||||
@Autowired
|
||||
private TestBatchlet testBatchlet;
|
||||
|
||||
@Test
|
||||
public void testJobLevelPropertiesInItemReader() throws Exception {
|
||||
assertEquals("jobPropertyValue1", testItemReader.getJobPropertyName1());
|
||||
assertEquals("jobPropertyValue2", testItemReader.getJobPropertyName2());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepContextProperties() throws Exception {
|
||||
public void testJobPropertyConfiguration() throws Exception {
|
||||
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemReaderProperties() throws Exception {
|
||||
assertEquals("readerPropertyValue1", testItemReader.getReaderPropertyName1());
|
||||
assertEquals("readerPropertyValue2", testItemReader.getReaderPropertyName2());
|
||||
assertEquals("annotationNamedReaderPropertyValue", testItemReader.getAnnotationNamedProperty());
|
||||
assertNull(testItemReader.getNotDefinedProperty());
|
||||
assertNull(testItemReader.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemProcessorProperties() throws Exception {
|
||||
Assert.assertEquals("processorPropertyValue1", testItemProcessor.getProcessorPropertyName1());
|
||||
Assert.assertEquals("processorPropertyValue2", testItemProcessor.getProcessorPropertyName2());
|
||||
assertEquals("annotationNamedProcessorPropertyValue", testItemProcessor.getAnnotationNamedProperty());
|
||||
assertNull(testItemProcessor.getNotDefinedProperty());
|
||||
assertNull(testItemProcessor.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemWriterProperties() throws Exception {
|
||||
Assert.assertEquals("writerPropertyValue1", testItemWriter.getWriterPropertyName1());
|
||||
Assert.assertEquals("writerPropertyValue2", testItemWriter.getWriterPropertyName2());
|
||||
assertEquals("annotationNamedWriterPropertyValue", testItemWriter.getAnnotationNamedProperty());
|
||||
assertNull(testItemWriter.getNotDefinedProperty());
|
||||
assertNull(testItemWriter.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckpointAlgorithmProperties() throws Exception {
|
||||
Assert.assertEquals("algorithmPropertyValue1", testCheckpointAlgorithm.getAlgorithmPropertyName1());
|
||||
Assert.assertEquals("algorithmPropertyValue2", testCheckpointAlgorithm.getAlgorithmPropertyName2());
|
||||
assertEquals("annotationNamedAlgorithmPropertyValue", testCheckpointAlgorithm.getAnnotationNamedProperty());
|
||||
assertNull(testCheckpointAlgorithm.getNotDefinedProperty());
|
||||
assertNull(testCheckpointAlgorithm.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeciderProperties() throws Exception {
|
||||
Assert.assertEquals("deciderPropertyValue1", testDecider.getDeciderPropertyName1());
|
||||
Assert.assertEquals("deciderPropertyValue2", testDecider.getDeciderPropertyName2());
|
||||
assertEquals("annotationNamedDeciderPropertyValue", testDecider.getAnnotationNamedProperty());
|
||||
assertNull(testDecider.getNotDefinedProperty());
|
||||
assertNull(testDecider.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepListenerProperties() throws Exception {
|
||||
Assert.assertEquals("stepListenerPropertyValue1", testStepListener.getStepListenerPropertyName1());
|
||||
Assert.assertEquals("stepListenerPropertyValue2", testStepListener.getStepListenerPropertyName2());
|
||||
assertEquals("annotationNamedStepListenerPropertyValue", testStepListener.getAnnotationNamedProperty());
|
||||
assertNull(testStepListener.getNotDefinedProperty());
|
||||
assertNull(testStepListener.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchletProperties() throws Exception {
|
||||
Assert.assertEquals("batchletPropertyValue1", testBatchlet.getBatchletPropertyName1());
|
||||
Assert.assertEquals("batchletPropertyValue2", testBatchlet.getBatchletPropertyName2());
|
||||
assertEquals("annotationNamedBatchletPropertyValue", testBatchlet.getAnnotationNamedProperty());
|
||||
assertNull(testBatchlet.getNotDefinedProperty());
|
||||
assertNull(testBatchlet.getNotDefinedAnnotationNamedProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldWithInjectAnnotationOnlyInjects() throws Exception {
|
||||
assertNotNull(testItemReader.getInjectAnnotatedOnlyField());
|
||||
assertEquals("Chris", testItemReader.getInjectAnnotatedOnlyField().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldWithBatchPropertyAnnotationOnlyNoInjection() throws Exception {
|
||||
assertNull(testItemReader.getBatchAnnotatedOnlyField());
|
||||
}
|
||||
|
||||
public static final class TestItemReader implements ItemReader {
|
||||
private int cnt;
|
||||
|
||||
@Inject @BatchProperty String readerPropertyName1;
|
||||
@Inject @BatchProperty String readerPropertyName2;
|
||||
@Inject @BatchProperty String readerPropertyName3;
|
||||
@Inject @BatchProperty(name = "annotationNamedReaderPropertyName") String annotationNamedProperty;
|
||||
@Inject @BatchProperty String notDefinedProperty;
|
||||
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
|
||||
@@ -188,8 +84,19 @@ public class JobPropertyTests {
|
||||
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step2PropertyName2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName1").equals("step1PropertyValue1"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1").equals("jobPropertyValue1"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2").equals("jobPropertyValue2"));
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null);
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null);
|
||||
org.springframework.util.Assert.isTrue("jobPropertyValue1".equals(jobPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("jobPropertyValue2".equals(jobPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue1".equals(readerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("readerPropertyValue2".equals(readerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedReaderPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
org.springframework.util.Assert.isNull(batchAnnotatedOnlyField);
|
||||
org.springframework.util.Assert.notNull(injectAnnotatedOnlyField);
|
||||
org.springframework.util.Assert.isTrue("Chris".equals(injectAnnotatedOnlyField.getName()));
|
||||
org.springframework.util.Assert.isNull(readerPropertyName3);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,42 +117,6 @@ public class JobPropertyTests {
|
||||
public Serializable checkpointInfo() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
String getReaderPropertyName1() {
|
||||
return readerPropertyName1;
|
||||
}
|
||||
|
||||
String getReaderPropertyName2() {
|
||||
return readerPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
|
||||
String getJobPropertyName1() {
|
||||
return jobPropertyName1;
|
||||
}
|
||||
|
||||
String getJobPropertyName2() {
|
||||
return jobPropertyName2;
|
||||
}
|
||||
|
||||
InjectTestObj getInjectAnnotatedOnlyField() {
|
||||
return injectAnnotatedOnlyField;
|
||||
}
|
||||
|
||||
String getBatchAnnotatedOnlyField() {
|
||||
return batchAnnotatedOnlyField;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestItemProcessor implements ItemProcessor {
|
||||
@@ -257,28 +128,14 @@ public class JobPropertyTests {
|
||||
|
||||
@Override
|
||||
public Object processItem(Object o) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue1".equals(processorPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("processorPropertyValue2".equals(processorPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedProcessorPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
String getProcessorPropertyName1() {
|
||||
return processorPropertyName1;
|
||||
}
|
||||
|
||||
String getProcessorPropertyName2() {
|
||||
return processorPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestItemWriter implements ItemWriter {
|
||||
@@ -290,6 +147,11 @@ public class JobPropertyTests {
|
||||
|
||||
@Override
|
||||
public void open(Serializable serializable) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue1".equals(writerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("writerPropertyValue2".equals(writerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedWriterPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,26 +167,6 @@ public class JobPropertyTests {
|
||||
public Serializable checkpointInfo() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
String getWriterPropertyName1() {
|
||||
return writerPropertyName1;
|
||||
}
|
||||
|
||||
String getWriterPropertyName2() {
|
||||
return writerPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestCheckpointAlgorithm implements CheckpointAlgorithm {
|
||||
@@ -334,26 +176,6 @@ public class JobPropertyTests {
|
||||
@Inject @BatchProperty String notDefinedProperty;
|
||||
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
|
||||
|
||||
String getAlgorithmPropertyName1() {
|
||||
return algorithmPropertyName1;
|
||||
}
|
||||
|
||||
String getAlgorithmPropertyName2() {
|
||||
return algorithmPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkpointTimeout() throws Exception {
|
||||
return 0;
|
||||
@@ -361,6 +183,11 @@ public class JobPropertyTests {
|
||||
|
||||
@Override
|
||||
public void beginCheckpoint() throws Exception {
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue1".equals(algorithmPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("algorithmPropertyValue2".equals(algorithmPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedAlgorithmPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -380,35 +207,19 @@ public class JobPropertyTests {
|
||||
@Inject @BatchProperty String notDefinedProperty;
|
||||
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
|
||||
|
||||
String getDeciderPropertyName1() {
|
||||
return deciderPropertyName1;
|
||||
}
|
||||
|
||||
String getDeciderPropertyName2() {
|
||||
return deciderPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decide(javax.batch.runtime.StepExecution[] executions)
|
||||
throws Exception {
|
||||
public String decide(javax.batch.runtime.StepExecution[] executions) throws Exception {
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue1".equals(deciderPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("deciderPropertyValue2".equals(deciderPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedDeciderPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
|
||||
return "step2";
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestStepListener implements javax.batch.api.chunk.listener.ItemReadListener,
|
||||
javax.batch.api.chunk.listener.ItemProcessListener, javax.batch.api.chunk.listener.ItemWriteListener {
|
||||
public static class TestStepListener implements StepListener {
|
||||
@Inject @BatchProperty String stepListenerPropertyName1;
|
||||
@Inject @BatchProperty String stepListenerPropertyName2;
|
||||
@Inject @BatchProperty(name = "annotationNamedStepListenerPropertyName") String annotationNamedProperty;
|
||||
@@ -416,59 +227,16 @@ public class JobPropertyTests {
|
||||
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
|
||||
|
||||
@Override
|
||||
public void beforeProcess(Object o) throws Exception {
|
||||
public void beforeStep() throws Exception {
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue1".equals(stepListenerPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("stepListenerPropertyValue2".equals(stepListenerPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedStepListenerPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(Object o, Object o2) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProcessError(Object o, Exception e) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRead() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRead(Object o) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadError(Exception e) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeWrite(List<Object> objects) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List<Object> objects) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(List<Object> objects, Exception e) throws Exception {
|
||||
}
|
||||
|
||||
String getStepListenerPropertyName1() {
|
||||
return stepListenerPropertyName1;
|
||||
}
|
||||
|
||||
String getStepListenerPropertyName2() {
|
||||
return stepListenerPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
public void afterStep() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,32 +258,18 @@ public class JobPropertyTests {
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null);
|
||||
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null);
|
||||
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue1".equals(batchletPropertyName1));
|
||||
org.springframework.util.Assert.isTrue("batchletPropertyValue2".equals(batchletPropertyName2));
|
||||
org.springframework.util.Assert.isTrue("annotationNamedBatchletPropertyValue".equals(annotationNamedProperty));
|
||||
org.springframework.util.Assert.isNull(notDefinedProperty);
|
||||
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
}
|
||||
|
||||
String getBatchletPropertyName1() {
|
||||
return batchletPropertyName1;
|
||||
}
|
||||
|
||||
String getBatchletPropertyName2() {
|
||||
return batchletPropertyName2;
|
||||
}
|
||||
|
||||
String getAnnotationNamedProperty() {
|
||||
return annotationNamedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedProperty() {
|
||||
return notDefinedProperty;
|
||||
}
|
||||
|
||||
String getNotDefinedAnnotationNamedProperty() {
|
||||
return notDefinedAnnotationNamedProperty;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InjectTestObj {
|
||||
|
||||
Reference in New Issue
Block a user