}
int numStepExecutions = jobExecution.getStepExecutions().size();
StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
String stepName = stepExecution.getStepName();
BatchStatus stepExecutionStatus = stepExecution.getStatus();
BatchStatus jobExecutionStatus = jobExecution.getStatus();
assertTrue("Should only be one StepExecution but got: " + numStepExecutions, numStepExecutions == 1);
assertTrue("Step name for execution should be step1 but got: " + stepName, "step1".equals(stepName));
assertTrue("Step execution status should be STOPPED but got: " + stepExecutionStatus, stepExecutionStatus.equals(BatchStatus.STOPPED));
assertTrue("Job execution status should be STOPPED but got:" + jobExecutionStatus, jobExecutionStatus.equals(BatchStatus.STOPPED));
JobExecution restartJobExecution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("test", 1L)
.toJobParameters());
while(restartJobExecution.isRunning()) {
// wait for async launched job to complete execution
}
int restartNumStepExecutions = restartJobExecution.getStepExecutions().size();
assertTrue("Should be two StepExecution's on restart but got: " + restartNumStepExecutions, restartNumStepExecutions == 2);
for(StepExecution restartStepExecution : restartJobExecution.getStepExecutions()) {
BatchStatus restartStepExecutionStatus = restartStepExecution.getStatus();
assertTrue("Step execution status should be COMPLETED but got: " + restartStepExecutionStatus,
restartStepExecutionStatus.equals(BatchStatus.COMPLETED));
}
BatchStatus restartJobExecutionStatus = restartJobExecution.getStatus();
assertTrue("Job execution status should be COMPLETED but got:" + restartJobExecutionStatus,
restartJobExecutionStatus.equals(BatchStatus.COMPLETED));
}