BATCH-1703: fix JobExecution.addStepExecutions()
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -7,6 +9,7 @@ import java.util.Date;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
@@ -48,4 +51,53 @@ public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
|
||||
assertNull(stored.getEndTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddStepExecutions() {
|
||||
StepExecutionDao tested = new MapStepExecutionDao();
|
||||
|
||||
JobExecution jobExecution = new JobExecution(88L);
|
||||
|
||||
// Create step execution with status STARTED
|
||||
StepExecution stepExecution = new StepExecution("Step one", jobExecution);
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
// Save and check id
|
||||
tested.saveStepExecution(stepExecution);
|
||||
assertNotNull(stepExecution.getId());
|
||||
|
||||
// Job execution instance doesn't contain step execution instances
|
||||
assertEquals(0, jobExecution.getStepExecutions().size());
|
||||
|
||||
// Load all execution steps and check
|
||||
tested.addStepExecutions(jobExecution);
|
||||
assertEquals(1, jobExecution.getStepExecutions().size());
|
||||
|
||||
// Check the first (and only) step execution instance of the job instance
|
||||
StepExecution jobStepExecution = jobExecution.getStepExecutions().iterator().next();
|
||||
assertEquals(BatchStatus.STARTED, jobStepExecution.getStatus());
|
||||
assertEquals(stepExecution.getId(), jobStepExecution.getId());
|
||||
|
||||
// Load the step execution instance from the repository and check is it the same
|
||||
StepExecution repoStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId());
|
||||
assertEquals(stepExecution.getId(), repoStepExecution.getId());
|
||||
assertEquals(BatchStatus.STARTED, repoStepExecution.getStatus());
|
||||
|
||||
// Update the step execution instance
|
||||
repoStepExecution.setStatus(BatchStatus.COMPLETED);
|
||||
|
||||
// Update the step execution in the repository and check
|
||||
tested.updateStepExecution(repoStepExecution);
|
||||
StepExecution updatedStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId());
|
||||
assertEquals(stepExecution.getId(), updatedStepExecution.getId());
|
||||
assertEquals(BatchStatus.COMPLETED, updatedStepExecution.getStatus());
|
||||
|
||||
// Now, add step executions from the repository and check
|
||||
tested.addStepExecutions(jobExecution);
|
||||
|
||||
jobStepExecution = jobExecution.getStepExecutions().iterator().next();
|
||||
assertEquals(1, jobExecution.getStepExecutions().size());
|
||||
assertEquals(stepExecution.getId(), jobStepExecution.getId());
|
||||
assertEquals(BatchStatus.COMPLETED, jobStepExecution.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user