@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); initializeTasklet(); tasklet.afterPropertiesSet(); tasklet.beforeStep(stepExecution); }
@Test public void testStopped() throws Exception { initializeTasklet(); tasklet.setJobExplorer(jobExplorer); tasklet.afterPropertiesSet(); tasklet.beforeStep(stepExecution); JobExecution stoppedJobExecution = new JobExecution(stepExecution.getJobExecution()); stoppedJobExecution.setStatus(BatchStatus.STOPPING); when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(), stepExecution.getJobExecution(), stoppedJobExecution); String command = isRunningOnWindows() ? "ping 127.0.0.1 -n 5" : "sleep 15"; tasklet.setCommand(command); tasklet.setTerminationCheckInterval(10); tasklet.afterPropertiesSet(); StepContribution contribution = stepExecution.createStepContribution(); StepContext stepContext = new StepContext(stepExecution); ChunkContext chunkContext = new ChunkContext(stepContext); tasklet.execute(contribution, chunkContext); assertEquals(ExitStatus.STOPPED.getExitCode(), contribution.getExitStatus().getExitCode()); }