diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java index 0a0f54e3b..5e7378549 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java @@ -143,8 +143,8 @@ public class JobExecution extends Entity { * * @param stepExecution */ - public StepExecution createStepExecution(String stepName) { - StepExecution stepExecution = new StepExecution(stepName, this, null); + public StepExecution createStepExecution(Step step) { + StepExecution stepExecution = new StepExecution(step, this, null); this.stepExecutions.add(stepExecution); return stepExecution; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java index 2b8ede1ba..5807d7fdd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java @@ -20,6 +20,7 @@ import java.util.Date; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.ExitStatus; +import org.springframework.util.Assert; /** * Batch domain object representation the execution of a step. Unlike @@ -37,7 +38,7 @@ public class StepExecution extends Entity { private JobExecution jobExecution; - private String stepName; + private Step step; private BatchStatus status = BatchStatus.STARTING; @@ -75,9 +76,10 @@ public class StepExecution extends Entity { * @param jobExecution the current job execution * @param id the id of this execution */ - public StepExecution(String stepName, JobExecution jobExecution, Long id) { + public StepExecution(Step step, JobExecution jobExecution, Long id) { super(id); - this.stepName = stepName; + Assert.notNull(step); + this.step = step; this.jobExecution = jobExecution; } @@ -87,8 +89,8 @@ public class StepExecution extends Entity { * @param step the step to which this execution belongs * @param jobExecution the current job execution */ - public StepExecution(String stepName, JobExecution jobExecution) { - this(stepName, jobExecution, null); + public StepExecution(Step step, JobExecution jobExecution) { + this(step, jobExecution, null); } /** @@ -235,7 +237,7 @@ public class StepExecution extends Entity { * @return the name of the step */ public String getStepName() { - return stepName; + return step.getName(); } /** @@ -258,14 +260,14 @@ public class StepExecution extends Entity { public boolean equals(Object obj) { //TODO make sure the equality makes sense Object jobExecutionId = getJobExecutionId(); - if (stepName == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { + if (step == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { return super.equals(obj); } StepExecution other = (StepExecution) obj; - if (stepName == null) { + if (step == null) { return jobExecutionId.equals(other.getJobExecutionId()); } - return stepName.equals(other.getStepName()) + return step.getName().equals(other.getStepName()) && (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId())); } @@ -276,12 +278,12 @@ public class StepExecution extends Entity { */ public int hashCode() { Object jobExecutionId = getJobExecutionId(); - return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91 + return super.hashCode() + 31 * (step.getName() != null ? step.getName().hashCode() : 0) + 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0); } public String toString() { - return super.toString() + ", name=" + stepName + ", taskCount=" + taskCount + ", commitCount=" + commitCount + return super.toString() + ", name=" + step.getName() + ", taskCount=" + taskCount + ", commitCount=" + commitCount + ", rollbackCount=" + rollbackCount; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java index 41a4f3178..520cd650c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java @@ -130,12 +130,12 @@ public class JobExecutionTests extends TestCase { public void testAddAndRemoveStepExecution() throws Exception { assertEquals(0, execution.getStepExecutions().size()); - execution.createStepExecution(null); + execution.createStepExecution(new StepSupport("stepName")); assertEquals(1, execution.getStepExecutions().size()); } public void testStop() throws Exception { - StepExecution stepExecution = execution.createStepExecution(null); + StepExecution stepExecution = execution.createStepExecution(new StepSupport("stepName")); assertFalse(stepExecution.isTerminateOnly()); execution.stop(); assertTrue(stepExecution.isTerminateOnly()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java index 325733a18..486b7e031 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java @@ -31,9 +31,10 @@ import org.springframework.batch.support.PropertiesConverter; */ public class StepExecutionTests extends TestCase { - private StepExecution execution = newStepExecution("stepName", + private StepExecution execution = newStepExecution(new StepSupport("stepName"), new Long(23)); + private StepExecution blankExecution = new StepExecution(new StepSupport("blank"), new JobExecution()); /** * Test method for * {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}. @@ -47,7 +48,7 @@ public class StepExecutionTests extends TestCase { * {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}. */ public void testStepExecutionWithNullId() { - assertNull(new StepExecution(null, null).getId()); + assertNull(new StepExecution(new StepSupport("stepName"), new JobExecution()).getId()); } /** @@ -176,7 +177,7 @@ public class StepExecutionTests extends TestCase { } public void testToStringWithNullName() throws Exception { - String value = new StepExecution().toString(); + String value = new StepExecution(new StepSupport(null), new JobExecution()).toString(); assertTrue("Should contain name=null: "+value, value.indexOf("name=null")>=0); } @@ -198,29 +199,30 @@ public class StepExecutionTests extends TestCase { } public void testEqualsWithSameIdentifier() throws Exception { - Entity step1 = newStepExecution("stepName", new Long(11)); - Entity step2 = newStepExecution("stepName", new Long(11)); - assertEquals(step1, step2); + Step step = new StepSupport("stepName"); + Entity stepExecution1 = newStepExecution(step, new Long(11)); + Entity stepExecution2 = newStepExecution(step, new Long(11)); + assertEquals(stepExecution1, stepExecution2); } public void testEqualsWithNull() throws Exception { - Entity step = newStepExecution("stepName", new Long(11)); - assertFalse(step.equals(null)); + Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11)); + assertFalse(stepExecution.equals(null)); } public void testEqualsWithNullIdentifiers() throws Exception { - Entity step = newStepExecution("stepName", new Long(11)); - assertFalse(step.equals(new StepExecution())); + Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11)); + assertFalse(stepExecution.equals(blankExecution)); } public void testEqualsWithNullJob() throws Exception { - Entity step = newStepExecution(null, new Long(11)); - assertFalse(step.equals(new StepExecution())); + Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11)); + assertFalse(stepExecution.equals(blankExecution)); } public void testEqualsWithNullStep() throws Exception { - Entity step = newStepExecution("stepName", null); - assertFalse(step.equals(new StepExecution())); + Entity stepExecution = newStepExecution(new StepSupport("stepName"), null); + assertFalse(stepExecution.equals(blankExecution)); } public void testEqualsWithSelf() throws Exception { @@ -228,16 +230,17 @@ public class StepExecutionTests extends TestCase { } public void testEqualsWithDifferent() throws Exception { - Entity step = newStepExecution("foo", new Long(13)); - assertFalse(execution.equals(step)); + Entity stepExecution = newStepExecution(new StepSupport("foo"), new Long(13)); + assertFalse(execution.equals(stepExecution)); } public void testEqualsWithNullStepId() throws Exception { - execution = newStepExecution(null, new Long(31)); - assertEquals(null, execution.getStepName()); - StepExecution step = newStepExecution(null, new Long(31)); - assertEquals(step.getJobExecutionId(), execution.getJobExecutionId()); - assertTrue(execution.equals(step)); + Step step = new StepSupport("name"); + execution = newStepExecution(step, new Long(31)); + assertEquals("name", execution.getStepName()); + StepExecution stepExecution = newStepExecution(step, new Long(31)); + assertEquals(stepExecution.getJobExecutionId(), execution.getJobExecutionId()); + assertTrue(execution.equals(stepExecution)); } public void testHashCode() throws Exception { @@ -247,7 +250,7 @@ public class StepExecutionTests extends TestCase { public void testHashCodeWithNullIds() throws Exception { assertTrue("Hash code not same as parent", - new Entity(execution.getId()).hashCode() != new StepExecution() + new Entity(execution.getId()).hashCode() != blankExecution .hashCode()); } @@ -259,9 +262,9 @@ public class StepExecutionTests extends TestCase { assertTrue(set.contains(execution)); } - private StepExecution newStepExecution(String stepName, Long long2) { + private StepExecution newStepExecution(Step step, Long long2) { JobInstance job = new JobInstance(new Long(3), new JobParameters(), new JobSupport("testJob")); - StepExecution execution = new StepExecution(stepName, new JobExecution(job, long2), new Long(4)); + StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4)); return execution; } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/simple/SimpleJob.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/simple/SimpleJob.java index afce6c606..5b5be4a7c 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/simple/SimpleJob.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/simple/SimpleJob.java @@ -81,7 +81,7 @@ public class SimpleJob extends JobSupport { if (shouldStart(jobInstance, step)) { startedCount++; updateStatus(execution, BatchStatus.STARTED); - StepExecution stepExecution = execution.createStepExecution(step.getName()); + StepExecution stepExecution = execution.createStepExecution(step); step.execute(stepExecution); status = stepExecution.getExitStatus(); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java index e22e8b3df..4727fc5df 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java @@ -16,6 +16,7 @@ import org.springframework.batch.core.domain.BatchStatus; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.ExitStatus; @@ -367,14 +368,17 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement private class StepExecutionRowMapper implements RowMapper { private final JobExecution jobExecution; + + private final Step step; - public StepExecutionRowMapper(JobExecution jobExecution) { + public StepExecutionRowMapper(JobExecution jobExecution, Step step) { this.jobExecution = jobExecution; + this.step = step; } public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - StepExecution stepExecution = new StepExecution(rs.getString(2), jobExecution, new Long(rs.getLong(1))); + StepExecution stepExecution = new StepExecution(step, jobExecution, new Long(rs.getLong(1))); stepExecution.setStartTime(rs.getTimestamp(3)); stepExecution.setEndTime(rs.getTimestamp(4)); stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5))); @@ -437,7 +441,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement public StepExecution getStepExecution(JobExecution jobExecution, Step step) { List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION), - new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution)); + new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution, step)); Assert.state(executions.size() <= 1, "There can be at most one step execution with given name for single job execution"); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/bootstrap/support/SimpleExportedJobLauncherTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/bootstrap/support/SimpleExportedJobLauncherTests.java index fcad05b4a..bd6283c15 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/bootstrap/support/SimpleExportedJobLauncherTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/bootstrap/support/SimpleExportedJobLauncherTests.java @@ -27,6 +27,7 @@ import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobParametersBuilder; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.runtime.JobParametersFactory; import org.springframework.batch.execution.configuration.MapJobRegistry; @@ -51,7 +52,7 @@ public class SimpleExportedJobLauncherTests extends TestCase { launcher.setLauncher(new JobLauncher() { public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException { JobExecution result = new JobExecution(null); - StepExecution stepExecution = result.createStepExecution("stepName"); + StepExecution stepExecution = result.createStepExecution(new StepSupport("stepName")); stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar"))); list.add(jobParameters); return result; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java index 580c91f86..fde209747 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/simple/SimpleJobTests.java @@ -75,9 +75,9 @@ public class SimpleJobTests extends TestCase { private SimpleJob job; - private String step1; + private Step step1; - private String step2; + private Step step2; protected void setUp() throws Exception { super.setUp(); @@ -116,8 +116,8 @@ public class SimpleJobTests extends TestCase { jobInstance = jobExecution.getJobInstance(); List steps = jobInstance.getJob().getSteps(); - step1 = ((Step) steps.get(0)).getName(); - step2 = ((Step) steps.get(1)).getName(); + step1 = (Step) steps.get(0); + step2 = (Step) steps.get(1); stepExecution1 = new StepExecution(step1, jobExecution, null); stepExecution2 = new StepExecution(step2, jobExecution, null); @@ -163,8 +163,8 @@ public class SimpleJobTests extends TestCase { testRunNormally(); assertEquals(jobInstance, jobExecution.getJobInstance()); assertEquals(2, jobExecution.getStepExecutions().size()); - assertEquals(step1, stepExecution1.getStepName()); - assertEquals(step2, stepExecution2.getStepName()); + assertEquals(step1.getName(), stepExecution1.getStepName()); + assertEquals(step2.getName(), stepExecution2.getStepName()); } public void testInterrupted() throws Exception { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index c22ca3eb4..5d255d80b 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -17,13 +17,10 @@ package org.springframework.batch.execution.repository; import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; import java.util.List; import junit.framework.TestCase; -import org.easymock.ArgumentsMatcher; import org.easymock.MockControl; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; @@ -346,7 +343,7 @@ public class SimpleJobRepositoryTests extends TestCase { } public void testUpdateStepExecution() { - StepExecution stepExecution = new StepExecution("stepName", null, new Long(1)); + StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, new Long(1)); stepExecution.setId(new Long(11)); ExecutionContext executionContext = new ExecutionContext(); stepExecution.setExecutionContext(executionContext); @@ -358,7 +355,7 @@ public class SimpleJobRepositoryTests extends TestCase { } public void testSaveExistingStepExecution() { - StepExecution stepExecution = new StepExecution("stepName", new JobExecution(null), null); + StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(null), null); ExecutionContext executionContext = new ExecutionContext(); stepExecution.setExecutionContext(executionContext); stepExecutionDao.saveStepExecution(stepExecution); @@ -370,7 +367,7 @@ public class SimpleJobRepositoryTests extends TestCase { public void testSaveOrUpdateStepExecutionException() { - StepExecution stepExecution = new StepExecution(null, null, null); + StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), null, null); // failure scenario -- no step id set. try { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java index 016abc650..41cc5ef87 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java @@ -24,6 +24,7 @@ import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; +import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier; @@ -52,9 +53,9 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour protected JobInstance jobInstance; - protected String step1; + protected Step step1; - protected String step2; + protected Step step2; protected StepExecution stepExecution; @@ -91,8 +92,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour protected void onSetUpInTransaction() throws Exception { Job job = new JobSupport("TestJob"); jobInstance = jobInstanceDao.createJobInstance(job, jobParameters); - step1 = "TestStep1"; - step2 = "TestStep2"; + step1 = new StepSupport("TestStep1"); + step2 = new StepSupport("TestStep2"); jobExecution = new JobExecution(jobInstance); jobExecutionDao.saveJobExecution(jobExecution); @@ -132,7 +133,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION, "java.lang.Exception")); stepExecutionDao.saveStepExecution(execution); - StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step2)); + StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2); assertNotNull(retrievedExecution); assertEquals(execution, retrievedExecution); assertEquals(execution.getExecutionContext().getString("key1"), retrievedExecution.getExecutionContext().getString("key1")); @@ -149,14 +150,14 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour stepExecution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION, "java.lang.Exception")); stepExecutionDao.updateStepExecution(stepExecution); - StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step1)); + StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step1); assertNotNull(retrievedExecution); assertEquals(stepExecution, retrievedExecution); assertEquals(stepExecution.getExitStatus(), retrievedExecution.getExitStatus()); } public void testUpdateStepExecutionWithNullId() { - StepExecution stepExecution = new StepExecution(null, null, null); + StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), null, null); try { stepExecutionDao.updateStepExecution(stepExecution); fail("Expected IllegalArgumentException"); @@ -201,7 +202,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour } public void testGetStepExecution() { - assertEquals(stepExecution, stepExecutionDao.getStepExecution(jobExecution, new StepSupport(step1))); + assertEquals(stepExecution, stepExecutionDao.getStepExecution(jobExecution, step1)); } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java index 4951bbe87..9201cde20 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java @@ -9,7 +9,9 @@ import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; +import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; @@ -31,7 +33,7 @@ public class JdbcStepDaoPrefixTests extends TestCase { MockJdbcTemplate jdbcTemplate = new MockJdbcTemplate(); JobInstance job = new JobInstance(new Long(1), new JobParameters(), new JobSupport("testJob")); - String step = "foo"; + Step step = new StepSupport("foo"); StepExecution stepExecution = new StepExecution(step, new JobExecution(job), null); MockControl stepExecutionIncrementerControl = MockControl.createControl(DataFieldMaxValueIncrementer.class); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java index 82cc854ad..04e11a99f 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoTests.java @@ -32,7 +32,7 @@ public class JdbcStepDaoTests extends AbstractStepDaoTests { List executions = jdbcTemplate.queryForList( "SELECT * FROM BATCH_STEP_EXECUTION where STEP_NAME=?", - new Object[] { step1 }); + new Object[] { step1.getName() }); assertEquals(1, executions.size()); assertEquals(LONG_STRING.substring(0, 250), ((Map) executions.get(0)) .get("EXIT_MESSAGE")); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java index 7e448efe9..9781355f7 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java @@ -16,51 +16,56 @@ package org.springframework.batch.execution.repository.dao; -import java.util.Properties; - import junit.framework.TestCase; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; +import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.item.ExecutionContext; +import org.springframework.batch.core.domain.StepSupport; public class MapStepDaoTests extends TestCase { MapStepDao dao = new MapStepDao(); + private JobInstance job; - private String step; - + + private Step step; + // Make sure we get a new job for each test... - static long jobId=100; - + static long jobId = 100; + protected void setUp() throws Exception { MapStepDao.clear(); job = new JobInstance(new Long(jobId++), new JobParameters(), new JobSupport("testJob")); - step = "foo"; + step = new StepSupport("foo"); } public void testSaveExecutionUpdatesId() throws Exception { - StepExecution execution = new StepExecution(step, null, null); + StepExecution execution = new StepExecution(step, new JobExecution(new JobInstance(new Long(1), + new JobParameters(), new JobSupport("jobName")))); assertNull(execution.getId()); dao.saveStepExecution(execution); assertNotNull(execution.getId()); } public void testSaveExecutionContext() throws Exception { -// JobExecution jobExecution = new JobExecution(null); -// StepExecution stepExecution = new StepExecution(step, jobExecution, null); -// assertEquals(null, dao.findExecutionContext(stepExecution)); -// Properties data = new Properties(); -// data.setProperty("restart.key1", "restartData"); -// ExecutionContext executionContext = new ExecutionContext(data); -// stepExecution.setExecutionContext(executionContext); -// dao.saveStepExecution(stepExecution); -// StepExecution tempExecution = dao.getStepExecution(jobExecution, step); -// assertEquals(tempExecution, stepExecution); -// assertEquals(stepExecution.getExecutionContext(), tempExecution.getExecutionContext()); + // JobExecution jobExecution = new JobExecution(null); + // StepExecution stepExecution = new StepExecution(step, jobExecution, + // null); + // assertEquals(null, dao.findExecutionContext(stepExecution)); + // Properties data = new Properties(); + // data.setProperty("restart.key1", "restartData"); + // ExecutionContext executionContext = new ExecutionContext(data); + // stepExecution.setExecutionContext(executionContext); + // dao.saveStepExecution(stepExecution); + // StepExecution tempExecution = dao.getStepExecution(jobExecution, + // step); + // assertEquals(tempExecution, stepExecution); + // assertEquals(stepExecution.getExecutionContext(), + // tempExecution.getExecutionContext()); } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java index f4aaa3753..8c2d540f5 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/resource/BatchResourceFactoryBeanTests.java @@ -26,6 +26,8 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobParametersBuilder; import org.springframework.batch.core.domain.JobSupport; +import org.springframework.batch.core.domain.Step; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.scope.SimpleStepContext; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.DefaultResourceLoader; @@ -51,7 +53,7 @@ public class BatchResourceFactoryBeanTests extends TestCase { private JobInstance jobInstance; - private String stepInstance; + private Step step; /** * mock step context @@ -61,8 +63,8 @@ public class BatchResourceFactoryBeanTests extends TestCase { jobInstance = new JobInstance(new Long(0), new JobParameters(), new JobSupport("testJob")); JobExecution jobExecution = jobInstance.createJobExecution(); - stepInstance = "bar"; - resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(stepInstance))); + step = new StepSupport("bar"); + resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(step))); resourceFactory.afterPropertiesSet(); @@ -100,8 +102,8 @@ public class BatchResourceFactoryBeanTests extends TestCase { jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam") .toJobParameters(), new JobSupport("testJob")); JobExecution jobExecution = jobInstance.createJobExecution(); - stepInstance = "bar"; - resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(stepInstance))); + step = new StepSupport("bar"); + resourceFactory.setStepContext(new SimpleStepContext(jobExecution.createStepExecution(step))); resourceFactory.setFilePattern("foo/data/%JOB_NAME%/%job.key%-foo"); doTestPathName("spam-foo", "foo" + pathsep + "data" + pathsep); } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java index 83a228092..b633b317b 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java @@ -21,6 +21,7 @@ import java.util.List; import junit.framework.TestCase; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; /** * @author Dave Syer @@ -52,7 +53,7 @@ public class SimpleStepContextTests extends TestCase { */ public void testGetStepExecution() { assertNull(context.getStepExecution()); - context = new SimpleStepContext(new StepExecution(null, null, null)); + context = new SimpleStepContext(new StepExecution(new StepSupport("stepName"), null, null)); assertNotNull(context.getStepExecution()); } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java index 6d4852064..17947af69 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ChunkedStepTests.java @@ -28,6 +28,7 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.execution.scope.StepScope; import org.springframework.batch.execution.scope.StepSynchronizationManager; @@ -102,7 +103,7 @@ public class ChunkedStepTests extends TestCase { chunkedStep.setJobRepository(new JobRepositorySupport()); jobExecutionContext = new JobExecution(jobInstance); - stepExecution = new StepExecution("testStep", jobExecutionContext); + stepExecution = new StepExecution(new StepSupport("testStep"), jobExecutionContext); } public void testStepExecutor() throws Exception { @@ -115,7 +116,7 @@ public class ChunkedStepTests extends TestCase { public void testStepContextInitialized() throws Exception { final JobExecution jobExecution = new JobExecution(jobInstance); - final StepExecution stepExecution = new StepExecution("testStep", jobExecution); + final StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), jobExecution); chunkedStep.setChunker(new ItemChunker(new AbstractItemReader() { int counter = 0; @@ -144,7 +145,7 @@ public class ChunkedStepTests extends TestCase { final JobExecution jobExecution = new JobExecution(jobInstance); jobExecution.setId(new Long(1)); - final StepExecution stepExecution = new StepExecution("testStep", jobExecution); + final StepExecution stepExecution = new StepExecution(new StepSupport("testStep"), jobExecution); template.setListener(new RepeatListenerSupport() { public void open(RepeatContext context) { @@ -171,7 +172,7 @@ public class ChunkedStepTests extends TestCase { // StepExecution stepExecution = new StepExecution(step, jobExecutionContext); repository.getLastStepExecution(jobInstance, chunkedStep); - repoControl.setReturnValue(new StepExecution(null,null)); + repoControl.setReturnValue(stepExecution); repository.getStepExecutionCount(jobInstance, chunkedStep); repoControl.setReturnValue(0); repository.saveOrUpdate(stepExecution); @@ -508,7 +509,7 @@ public class ChunkedStepTests extends TestCase { // } // } // -// private class MockRestartableItemReader extends ItemStreamAdapter implements ItemReader { +// private class MockRestartableItemReader extends ItemStreamSupport implements ItemReader { // // private boolean getExecutionAttributesCalled = false; // diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java index 8c78cb10b..e0235f8e4 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/ItemOrientedStepTests.java @@ -30,14 +30,15 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; +import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepContribution; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.repository.SimpleJobRepository; import org.springframework.batch.execution.repository.dao.MapJobDao; import org.springframework.batch.execution.repository.dao.MapStepDao; import org.springframework.batch.execution.scope.StepScope; import org.springframework.batch.execution.scope.StepSynchronizationManager; -import org.springframework.batch.execution.step.ItemOrientedStep; import org.springframework.batch.execution.step.support.JobRepositorySupport; import org.springframework.batch.execution.step.support.StepInterruptionPolicy; import org.springframework.batch.io.exception.BatchCriticalException; @@ -118,7 +119,7 @@ public class ItemOrientedStepTests extends TestCase { public void testStepExecutor() throws Exception { - String step = "stepName"; + Step step = new StepSupport("stepName"); JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); @@ -135,7 +136,7 @@ public class ItemOrientedStepTests extends TestCase { template.setCompletionPolicy(new SimpleCompletionPolicy(1)); itemOrientedStep.setChunkOperations(template); - String step = "stepName"; + Step step = new StepSupport("stepName"); JobExecution jobExecution = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecution); @@ -155,13 +156,13 @@ public class ItemOrientedStepTests extends TestCase { template.setCompletionPolicy(new SimpleCompletionPolicy(1)); itemOrientedStep.setChunkOperations(template); - final String step = "stepName"; + final Step step = new StepSupport("stepName"); final JobExecution jobExecution = new JobExecution(jobInstance); final StepExecution stepExecution = new StepExecution(step, jobExecution); itemOrientedStep.setItemReader(new AbstractItemReader() { public Object read() throws Exception { - assertEquals(step, stepExecution.getStepName()); + assertEquals(step.getName(), stepExecution.getStepName()); assertNotNull(StepSynchronizationManager.getContext().getStepExecution()); return "foo"; } @@ -180,7 +181,7 @@ public class ItemOrientedStepTests extends TestCase { template.setCompletionPolicy(new SimpleCompletionPolicy(1)); itemOrientedStep.setStepOperations(template); - final String step = "stepName"; + final Step step = new StepSupport("stepName"); final JobExecution jobExecution = new JobExecution(jobInstance); jobExecution.setId(new Long(1)); final StepExecution stepExecution = new StepExecution(step, jobExecution); @@ -204,7 +205,7 @@ public class ItemOrientedStepTests extends TestCase { SimpleJobRepository repository = new SimpleJobRepository(new MapJobDao(), new MapJobDao(), new MapStepDao()); itemOrientedStep.setJobRepository(repository); - String step = "stepName"; + Step step = new StepSupport("stepName"); JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); @@ -229,7 +230,7 @@ public class ItemOrientedStepTests extends TestCase { }; - String step = "stepName"; + Step step = new StepSupport("stepName"); itemOrientedStep.setItemReader(itemReader); JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); @@ -260,7 +261,7 @@ public class ItemOrientedStepTests extends TestCase { }; - String step = "stepName"; + Step step = new StepSupport("stepName"); itemOrientedStep.setItemReader(itemReader); JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); @@ -279,7 +280,7 @@ public class ItemOrientedStepTests extends TestCase { * saveExecutionAttributes = true, doesn't have restoreFrom called on it. */ public void testNonRestartedJob() throws Exception { - String step = "stepName"; + Step step = new StepSupport("stepName"); MockRestartableItemReader tasklet = new MockRestartableItemReader(); itemOrientedStep.setItemReader(tasklet); itemOrientedStep.setSaveExecutionContext(true); @@ -321,8 +322,7 @@ public class ItemOrientedStepTests extends TestCase { * it. */ public void testNoSaveExecutionAttributesRestartableJob() { - String step = "stepName"; -// step.setStepExecutionCount(1); + Step step = new StepSupport("stepName"); MockRestartableItemReader tasklet = new MockRestartableItemReader(); itemOrientedStep.setItemReader(tasklet); itemOrientedStep.setSaveExecutionContext(false); @@ -346,8 +346,7 @@ public class ItemOrientedStepTests extends TestCase { * Restartable. */ public void testRestartJobOnNonRestartableTasklet() throws Exception { - String step = "stepName"; -// step.setStepExecutionCount(1); + Step step = new StepSupport("stepName"); itemOrientedStep.setItemReader(new AbstractItemReader() { public Object read() throws Exception { return "foo"; @@ -400,8 +399,7 @@ public class ItemOrientedStepTests extends TestCase { } public void testStreamManager() throws Exception { - String step = "stepName"; -// step.setStepExecutionCount(1); + Step step = new StepSupport("stepName"); itemOrientedStep.setItemReader(new AbstractItemReader() { public Object read() throws Exception { return "foo"; @@ -501,7 +499,7 @@ public class ItemOrientedStepTests extends TestCase { itemOrientedStep.setItemReader(itemReader); - String step = "stepName"; + Step step = new StepSupport("stepName"); JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); @@ -538,7 +536,7 @@ public class ItemOrientedStepTests extends TestCase { } }); - String step = "stepName"; + Step step = new StepSupport("stepName"); JobExecution jobExecutionContext = jobInstance.createJobExecution(); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java index 74a93ce7b..9a1504ced 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/TaskletStepTests.java @@ -11,8 +11,8 @@ import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.core.tasklet.Tasklet; -import org.springframework.batch.execution.step.TaskletStep; import org.springframework.batch.execution.step.support.JobRepositorySupport; import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.batch.repeat.ExitStatus; @@ -26,7 +26,7 @@ public class TaskletStepTests extends TestCase { private List list = new ArrayList(); protected void setUp() throws Exception { - stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance( + stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance( new Long(0L), new JobParameters(), new JobSupport("testJob")), new Long(12))); } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemChunkerTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemChunkerTests.java index 634d8e056..a8f7e9a37 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemChunkerTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemChunkerTests.java @@ -19,8 +19,13 @@ import junit.framework.TestCase; import org.springframework.batch.core.domain.ChunkingResult; import org.springframework.batch.core.domain.ItemSkipPolicy; +import org.springframework.batch.core.domain.JobExecution; +import org.springframework.batch.core.domain.JobInstance; +import org.springframework.batch.core.domain.JobParameters; +import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepContribution; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.step.support.ItemChunker; public class ItemChunkerTests extends TestCase { @@ -29,18 +34,19 @@ public class ItemChunkerTests extends TestCase { protected void setUp() throws Exception { super.setUp(); - - StepExecution execution = new StepExecution(null,null); + JobExecution jobExecution = new JobExecution(new JobInstance(new Long(1), new JobParameters(), new JobSupport("jobName"))); + StepExecution execution = new StepExecution(new StepSupport("stepName"), jobExecution); stepContribution = execution.createStepContribution(); } - + public void testSizeNegative() { try { MockItemReader itemReader = new MockItemReader(10); ItemChunker chunkReader = new ItemChunker(itemReader); chunkReader.chunk(-1, stepContribution); fail(); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { } } @@ -50,7 +56,8 @@ public class ItemChunkerTests extends TestCase { ItemChunker chunkReader = new ItemChunker(itemReader); chunkReader.chunk(0, stepContribution); fail(); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { } } @@ -76,7 +83,8 @@ public class ItemChunkerTests extends TestCase { try { chunkReader.chunk(10, stepContribution); fail(); - } catch (RuntimeException e) { + } + catch (RuntimeException e) { } } @@ -86,7 +94,7 @@ public class ItemChunkerTests extends TestCase { ItemChunker chunkReader = new ItemChunker(itemReader); chunkReader.setItemSkipPolicy(new StubReadFailurePolicy(false)); ChunkingResult chunkingResult = chunkReader.chunk(1, stepContribution); - assertEquals(1,chunkingResult.getChunk().getItems().size()); + assertEquals(1, chunkingResult.getChunk().getItems().size()); } private class StubReadFailurePolicy implements ItemSkipPolicy { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemDechunkerTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemDechunkerTests.java index 5dc162ff3..c0aeb50ee 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemDechunkerTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/ItemDechunkerTests.java @@ -23,6 +23,7 @@ import org.springframework.batch.core.domain.Chunk; import org.springframework.batch.core.domain.DechunkingResult; import org.springframework.batch.core.domain.StepContribution; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.step.support.AlwaysSkipItemSkipPolicy; import org.springframework.batch.execution.step.support.ItemDechunker; import org.springframework.batch.io.exception.WriteFailureException; @@ -50,7 +51,7 @@ public class ItemDechunkerTests extends TestCase { super.setUp(); itemWriter = (ItemWriter)writerControl.getMock(); - StepExecution execution = new StepExecution(null,null); + StepExecution execution = new StepExecution(new StepSupport("stepName"),null); stepContribution = execution.createStepContribution(); dechunker = new ItemDechunker(itemWriter); List items = new ArrayList(); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/RepeatOperationsStepTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/RepeatOperationsStepTests.java index 10cdc719e..b157f7bb5 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/RepeatOperationsStepTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/RepeatOperationsStepTests.java @@ -25,6 +25,7 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.step.ItemOrientedStep; import org.springframework.batch.item.reader.AbstractItemReader; import org.springframework.batch.item.reader.ItemReaderAdapter; @@ -93,7 +94,7 @@ public class RepeatOperationsStepTests extends TestCase { configuration.setChunkOperations(repeatTemplate); configuration.setJobRepository(new JobRepositorySupport()); configuration.setTransactionManager(new ResourcelessTransactionManager()); - StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")), + StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")), new Long(12))); configuration.afterPropertiesSet(); try { @@ -134,7 +135,7 @@ public class RepeatOperationsStepTests extends TestCase { configuration.setStepOperations(stepTemplate); configuration.setJobRepository(new JobRepositorySupport()); configuration.setTransactionManager(new ResourcelessTransactionManager()); - StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")), + StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")), new Long(12))); configuration.afterPropertiesSet(); configuration.execute(stepExecution); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/SkipLimitReadFailurePolicyTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/SkipLimitReadFailurePolicyTests.java index 70b4ee442..f0116e29d 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/SkipLimitReadFailurePolicyTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/SkipLimitReadFailurePolicyTests.java @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.batch.core.domain.StepContribution; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.step.support.LimitCheckingItemSkipPolicy; import org.springframework.batch.execution.step.support.SkipLimitExceededException; import org.springframework.batch.io.exception.FlatFileParsingException; @@ -44,7 +45,7 @@ public class SkipLimitReadFailurePolicyTests extends TestCase { skippableExceptions.add(FlatFileParsingException.class); failurePolicy = new LimitCheckingItemSkipPolicy(1, skippableExceptions); - stepExecution = new StepExecution(null, null); + stepExecution = new StepExecution(new StepSupport("stepName"), null); stepExecution.setSkipCount(2); stepContribution = stepExecution.createStepContribution(); } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java index 8b898cf50..6599ba982 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/support/StepExecutorInterruptionTests.java @@ -16,8 +16,6 @@ package org.springframework.batch.execution.step.support; -import java.util.List; - import junit.framework.TestCase; import org.springframework.batch.core.domain.BatchStatus; @@ -26,7 +24,6 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; -import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.execution.repository.SimpleJobRepository; @@ -52,8 +49,6 @@ public class StepExecutorInterruptionTests extends TestCase { private StepExecutionDao stepExecutionDao = new MapStepDao(); - private JobInstance jobInstance; - private RepeatOperationsStep step; public void setUp() throws Exception { @@ -65,7 +60,7 @@ public class StepExecutorInterruptionTests extends TestCase { step.setName("stepName"); jobConfiguration.addStep(step); jobConfiguration.setBeanName("testJob"); - jobInstance = jobRepository.createJobExecution(jobConfiguration, new JobParameters()).getJobInstance(); + jobRepository.createJobExecution(jobConfiguration, new JobParameters()); step.setJobRepository(jobRepository); step.setTransactionManager(new ResourcelessTransactionManager()); step.setItemReader(new ItemReaderAdapter()); @@ -77,10 +72,8 @@ public class StepExecutorInterruptionTests extends TestCase { public void testInterruptChunk() throws Exception { - List steps = jobInstance.getJob().getSteps(); - final String stepName = ((Step)steps.get(0)).getName(); JobExecution jobExecutionContext = new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob"))); - final StepExecution stepExecution = new StepExecution(stepName, jobExecutionContext); + final StepExecution stepExecution = new StepExecution(step, jobExecutionContext); step.setItemReader(new AbstractItemReader() { public Object read() throws Exception { // do something non-trivial (and not Thread.sleep()) diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/reader/StagingItemReaderTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/reader/StagingItemReaderTests.java index 87309c71d..4ddeda3d4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/reader/StagingItemReaderTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/reader/StagingItemReaderTests.java @@ -5,6 +5,7 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.scope.SimpleStepContext; import org.springframework.batch.execution.scope.StepContext; import org.springframework.batch.execution.scope.StepSynchronizationManager; @@ -36,7 +37,7 @@ public class StagingItemReaderTests extends AbstractTransactionalDataSourceSprin } protected void prepareTestInstance() throws Exception { - StepContext stepScopeContext = new SimpleStepContext(new StepExecution("stepName", + StepContext stepScopeContext = new SimpleStepContext(new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(jobId, new JobParameters(), new JobSupport("testJob"))))); StepSynchronizationManager.register(stepScopeContext); RepeatSynchronizationManager.register(new RepeatContextSupport(null)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/writer/StagingItemProcessorTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/writer/StagingItemProcessorTests.java index 7b82f86fe..b196d9048 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/writer/StagingItemProcessorTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/item/writer/StagingItemProcessorTests.java @@ -5,6 +5,7 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.execution.scope.SimpleStepContext; import org.springframework.batch.execution.scope.StepSynchronizationManager; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -24,7 +25,7 @@ public class StagingItemProcessorTests extends AbstractTransactionalDataSourceSp } protected void prepareTestInstance() throws Exception { - SimpleStepContext stepScopeContext = new SimpleStepContext(new StepExecution("stepName", + SimpleStepContext stepScopeContext = new SimpleStepContext(new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(12), new JobParameters(), new JobSupport("job"))))); StepSynchronizationManager.register(stepScopeContext); super.prepareTestInstance();