@Test public void testExecuteException() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { throw new RuntimeException("FOO"); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage()); }
@Test public void testExecuteFailure() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.FAILED); execution.setEndTime(new Date()); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); }
@Test public void testStepExecutionExitStatus() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.COMPLETED); execution.setExitStatus(new ExitStatus("CUSTOM")); execution.setEndTime(new Date()); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals("CUSTOM", stepExecution.getExitStatus().getExitCode()); } }
/** * Test method for * {@link org.springframework.batch.core.step.AbstractStep#execute(org.springframework.batch.core.StepExecution)} * . */ @Test public void testExecuteSunnyDay() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.COMPLETED); execution.setEndTime(new Date()); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertTrue("Missing job parameters in execution context: " + stepExecution.getExecutionContext(), stepExecution .getExecutionContext().containsKey(JobStep.class.getName() + ".JOB_PARAMETERS")); }
@Test public void testStoppedChild() throws Exception { DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor(); jobParametersExtractor.setKeys(new String[] {"foo"}); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); step.setJobParametersExtractor(jobParametersExtractor); step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.STOPPED); execution.setEndTime(new Date()); jobRepository.update(execution); } @Override public boolean isRestartable() { return true; } }); step.afterPropertiesSet(); step.execute(stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); }