List of usage examples for org.springframework.batch.core.scope.context StepContext StepContext
public StepContext(StepExecution stepExecution)
From source file:de.langmi.spring.batch.examples.complex.file.split.GetLineCountTaskletTest.java
@Test public void testExecute() throws Exception { // setup/*from w ww . j a v a 2 s .c o m*/ tasklet = new GetLineCountTasklet(); tasklet.setResource(new FileSystemResource(INPUT)); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(); // execute RepeatStatus status = tasklet.execute(new StepContribution(stepExecution), new ChunkContext(new StepContext(stepExecution))); // assertions assertEquals(RepeatStatus.FINISHED, status); assertEquals(EXPECTED_COUNT, stepExecution.getExecutionContext().get("line.count")); }
From source file:org.springframework.batch.core.step.tasklet.SystemCommandTaskletIntegrationTests.java
@Test public void testStopped() throws Exception { initializeTasklet();//from w ww .j a va 2 s . com 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 = System.getProperty("os.name").toLowerCase().contains("win") ? "ping 1.1.1.1 -n 1 -w 5000" : "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(contribution.getExitStatus().getExitCode(), ExitStatus.STOPPED.getExitCode()); }