Updated to remove run id from job parameters when using JSR

This commit is contained in:
Michael Minella
2013-08-23 11:04:31 -05:00
parent b2b54921ae
commit 2a3bb817c0
4 changed files with 14 additions and 3 deletions

View File

@@ -114,6 +114,8 @@ public class JobExecution implements javax.batch.runtime.JobExecution {
*/
@Override
public Properties getJobParameters() {
return parametersConverter.getProperties(this.execution.getJobParameters());
Properties properties = parametersConverter.getProperties(this.execution.getJobParameters());
properties.remove(JsrJobParametersConverter.JOB_RUN_ID);
return properties;
}
}

View File

@@ -45,6 +45,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.jsr.JobContext;
import org.springframework.batch.core.jsr.JsrJobParametersConverter;
import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobRepository;
@@ -320,7 +321,10 @@ public class JsrJobOperator implements JobOperator {
throw new NoSuchJobExecutionException("Unable to find the JobExecution for id " + executionId);
}
return jobParametersConverter.getProperties(execution.getJobParameters());
Properties properties = jobParametersConverter.getProperties(execution.getJobParameters());
properties.remove(JsrJobParametersConverter.JOB_RUN_ID);
return properties;
}
/* (non-Javadoc)

View File

@@ -1,6 +1,7 @@
package org.springframework.batch.core.jsr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.Date;
import java.util.Properties;
@@ -57,5 +58,6 @@ public class JobExecutionTests {
Properties props = adapter.getJobParameters();
assertEquals("value1", props.get("key1"));
assertNull(props.get(JsrJobParametersConverter.JOB_RUN_ID));
}
}

View File

@@ -2,6 +2,7 @@ package org.springframework.batch.core.jsr.launch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.verify;
@@ -33,6 +34,7 @@ import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.converter.JobParametersConverterSupport;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.SimpleJobExplorer;
import org.springframework.batch.core.jsr.JsrJobParametersConverter;
import org.springframework.batch.core.launch.support.SimpleJobOperator;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobRepository;
@@ -252,13 +254,14 @@ public class JsrJobOperatorTests {
@Test
public void testGetParametersRoseyScenario() {
JobExecution jobExecution = new JobExecution(5l, new JobParametersBuilder().addString("key1", "value1").toJobParameters());
JobExecution jobExecution = new JobExecution(5l, new JobParametersBuilder().addString("key1", "value1").addLong(JsrJobParametersConverter.JOB_RUN_ID, 5l).toJobParameters());
when(jobExplorer.getJobExecution(5l)).thenReturn(jobExecution);
Properties params = jsrJobOperator.getParameters(5l);
assertEquals("value1", params.get("key1"));
assertNull(params.get(JsrJobParametersConverter.JOB_RUN_ID));
}
@Test(expected=NoSuchJobExecutionException.class)