Updates from the JSR 352 v1.0 Maintenance Release 20140214 Draft 2

* Per added section 9.3.2 - do not automatically make job properties available
  to artifacts when using @BatchProperty. Job properties are only available to
  artifacts when using the jobProperties substitution mechanism.

* Update tests to reflect changes
This commit is contained in:
Chris Schaefer
2014-02-28 11:11:23 -05:00
committed by Michael Minella
parent 319c751432
commit fe05e0daaf
5 changed files with 44 additions and 32 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.core.jsr.configuration.support;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -99,11 +100,18 @@ public class BatchPropertyContext {
for(Map.Entry<String, Properties> propertiesEntry : properties.entrySet()) {
String stepName = propertiesEntry.getKey();
Properties stepProperties = propertiesEntry.getValue();
if (!propertiesEntry.getValue().isEmpty()) {
if (!stepProperties.isEmpty()) {
if (this.stepProperties.containsKey(stepName)) {
Properties existingStepProperties = this.stepProperties.get(stepName);
existingStepProperties.putAll(propertiesEntry.getValue());
Enumeration<?> stepPropertyNames = stepProperties.propertyNames();
while(stepPropertyNames.hasMoreElements()) {
String propertyEntryName = (String) stepPropertyNames.nextElement();
existingStepProperties.put(propertyEntryName, stepProperties.getProperty(propertyEntryName));
}
this.stepProperties.put(stepName, existingStepProperties);
} else {
@@ -134,9 +142,7 @@ public class BatchPropertyContext {
/**
* <p>
* Obtains the batch {@link Properties} for the provided artifact name. The returned {@link Properties}
* will also contain any job level properties that have been set. Job level properties will not override
* existing lower level artifact properties.
* Obtains the batch {@link Properties} for the provided artifact name.
* </p>
*
* @param artifactName the batch artifact to obtain properties for
@@ -144,7 +150,6 @@ public class BatchPropertyContext {
*/
public Properties getArtifactProperties(String artifactName) {
Properties properties = new Properties();
properties.putAll(getJobProperties());
if (artifactProperties.containsKey(artifactName)) {
properties.putAll(artifactProperties.get(artifactName));
@@ -184,7 +189,6 @@ public class BatchPropertyContext {
*/
public Properties getStepArtifactProperties(String stepName, String artifactName) {
Properties properties = new Properties();
properties.putAll(getJobProperties());
properties.putAll(getStepProperties(stepName));
Map<String, Properties> artifactProperties = stepArtifactProperties.get(stepName);

View File

@@ -36,18 +36,18 @@ import org.w3c.dom.Element;
* @since 3.0
*/
public class PropertyParser {
private static final String PROPERTY_ELEMENT = "property";
private static final String PROPERTIES_ELEMENT = "properties";
private static final String PROPERTY_NAME_ATTRIBUTE = "name";
private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
private static final String JOB_PROPERTIES_BEAN_NAME = "jobProperties";
private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext";
private static final String JOB_PROPERTIES_PROPERTY_NAME = "jobProperties";
private static final String STEP_PROPERTIES_PROPERTY_NAME = "stepProperties";
private static final String ARTIFACT_PROPERTIES_PROPERTY_NAME = "artifactProperties";
private static final String STEP_ARTIFACT_PROPERTIES_PROPERTY_NAME = "stepArtifactProperties";
private static final String PROPERTY_ELEMENT = "property";
private static final String PROPERTIES_ELEMENT = "properties";
private static final String PROPERTY_NAME_ATTRIBUTE = "name";
private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
private static final String JOB_PROPERTIES_BEAN_NAME = "jobProperties";
private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext";
private static final String JOB_PROPERTIES_PROPERTY_NAME = "jobProperties";
private static final String STEP_PROPERTIES_PROPERTY_NAME = "stepProperties";
private static final String ARTIFACT_PROPERTIES_PROPERTY_NAME = "artifactProperties";
private static final String STEP_ARTIFACT_PROPERTIES_PROPERTY_NAME = "stepArtifactProperties";
private String beanName;
private String beanName;
private String stepName;
private ParserContext parserContext;
private BatchArtifact.BatchArtifactType batchArtifactType;

View File

@@ -144,11 +144,9 @@ public class BatchPropertyContextTests {
batchPropertyContext.setStepProperties(stepProperties);
Properties artifactProperties = batchPropertyContext.getArtifactProperties("decider1");
assertEquals(4, artifactProperties.size());
assertEquals(2, artifactProperties.size());
assertEquals("deciderProperty1value", artifactProperties.getProperty("deciderProperty1"));
assertEquals("deciderProperty2value", artifactProperties.getProperty("deciderProperty2"));
assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1"));
assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2"));
}
@Test
@@ -160,13 +158,11 @@ public class BatchPropertyContextTests {
batchPropertyContext.setStepArtifactProperties(stepArtifactProperties);
Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step1", "reader");
assertEquals(6, artifactProperties.size());
assertEquals(4, artifactProperties.size());
assertEquals("readerProperty1value", artifactProperties.getProperty("readerProperty1"));
assertEquals("readerProperty2value", artifactProperties.getProperty("readerProperty2"));
assertEquals("step1PropertyValue1", artifactProperties.getProperty("step1PropertyName1"));
assertEquals("step1PropertyValue2", artifactProperties.getProperty("step1PropertyName2"));
assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1"));
assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2"));
}
@Test
@@ -181,11 +177,9 @@ public class BatchPropertyContextTests {
batchPropertyContext.setJobProperties(jobProperties);
Properties step1 = batchPropertyContext.getArtifactProperties("decider1");
assertEquals(4, step1.size());
assertEquals(2, step1.size());
assertEquals("deciderProperty1value", step1.getProperty("deciderProperty1"));
assertEquals("deciderProperty2value", step1.getProperty("deciderProperty2"));
assertEquals("jobProperty1value", step1.getProperty("jobProperty1"));
assertEquals("jobProperty2value", step1.getProperty("jobProperty2"));
Properties job = batchPropertyContext.getJobProperties();
assertEquals(3, job.size());
@@ -204,14 +198,12 @@ public class BatchPropertyContextTests {
batchPropertyContext.setStepArtifactProperties(partitionProperties);
Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step2:partition0", "writer");
assertEquals(8, artifactProperties.size());
assertEquals(6, artifactProperties.size());
assertEquals("writerProperty1", artifactProperties.getProperty("writerProperty1Step"));
assertEquals("writerProperty2", artifactProperties.getProperty("writerProperty2Step"));
assertEquals("writerProperty1valuePartition0", artifactProperties.getProperty("writerProperty1"));
assertEquals("writerProperty2valuePartition0", artifactProperties.getProperty("writerProperty2"));
assertEquals("step2PropertyValue1", artifactProperties.getProperty("step2PropertyName1"));
assertEquals("step2PropertyValue2", artifactProperties.getProperty("step2PropertyName2"));
assertEquals("jobProperty1value", artifactProperties.getProperty("jobProperty1"));
assertEquals("jobProperty2value", artifactProperties.getProperty("jobProperty2"));
}
}

View File

@@ -81,8 +81,6 @@ public class JobPropertyTests {
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step1PropertyName2").equals("step1PropertyValue2"));
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));
@@ -92,6 +90,14 @@ public class JobPropertyTests {
org.springframework.util.Assert.notNull(injectAnnotatedOnlyField);
org.springframework.util.Assert.isTrue("job1".equals(injectAnnotatedOnlyField.getJobName()));
org.springframework.util.Assert.isNull(readerPropertyName3);
Properties jobProperties = injectAnnotatedOnlyField.getProperties();
org.springframework.util.Assert.isTrue(jobProperties.size() == 5);
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName1").equals("jobPropertyValue1"));
org.springframework.util.Assert.isTrue(jobProperties.get("jobPropertyName2").equals("jobPropertyValue2"));
org.springframework.util.Assert.isTrue(jobProperties.get("step2name").equals("step2"));
org.springframework.util.Assert.isTrue(jobProperties.get("filestem").equals("postings"));
org.springframework.util.Assert.isTrue(jobProperties.get("x").equals("xVal"));
}
@Override
@@ -242,6 +248,9 @@ public class JobPropertyTests {
@Inject @BatchProperty String notDefinedProperty;
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
@Inject javax.batch.runtime.context.StepContext stepContext;
@Inject @BatchProperty(name = "infile.name") String infile;
@Inject @BatchProperty(name = "y") String y;
@Inject @BatchProperty(name = "x") String x;
@Override
public String process() throws Exception {
@@ -256,8 +265,11 @@ public class JobPropertyTests {
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.isTrue("postings.txt".equals(infile));
org.springframework.util.Assert.isTrue("xVal".equals(y));
org.springframework.util.Assert.isNull(notDefinedProperty);
org.springframework.util.Assert.isNull(notDefinedAnnotationNamedProperty);
org.springframework.util.Assert.isNull(x);
return null;
}

View File

@@ -6,6 +6,8 @@
<property name="jobPropertyName1" value="jobPropertyValue1"/>
<property name="jobPropertyName2" value="jobPropertyValue2"/>
<property name="step2name" value="step2"/>
<property name="filestem" value="postings"/>
<property name="x" value="xVal"/>
</properties>
<step id="step1" allow-start-if-complete="#{jobParameters['allow.start.if.complete']}">
@@ -92,6 +94,8 @@
<property name="batchletPropertyName2" value="batchletPropertyValue2"/>
<property name="annotationNamedBatchletPropertyName" value="annotationNamedBatchletPropertyValue"/>
<property name="nonexistentBatchletPropertyName" value="nonexistentBatchletPropertyValue"/>
<property name="infile.name" value="#{jobProperties['filestem']}.txt"/>
<property name="y" value="#{jobProperties['x']}"/>
</properties>
</batchlet>
</step>