List of usage examples for org.springframework.batch.test StepScopeTestUtils doInStepScope
public static <T> T doInStepScope(StepExecution stepExecution, Callable<T> callable) throws Exception
From source file:de.langmi.spring.batch.examples.readers.file.flatfileitemreader.FlatFileItemReaderDoInStepscopeTest.java
/** * Test should read succesfully.//from www.j a v a 2 s .c om * * @throws Exception */ @Test public void testSuccessfulReading() throws Exception { // setup Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>(); jobParametersMap.put("time", new JobParameter(System.currentTimeMillis())); jobParametersMap.put("input.file", new JobParameter("file:src/test/resources/input/file/simple/input.txt")); StepExecution execution = MetaDataInstanceFactory.createStepExecution(new JobParameters(jobParametersMap)); int count = StepScopeTestUtils.doInStepScope(execution, new Callable<Integer>() { @Override public Integer call() throws Exception { int count = 0; itemReaderStream.open(new ExecutionContext()); String line; try { while ((line = itemReaderStream.read()) != null) { assertEquals(String.valueOf(count), line); count++; } } finally { itemReaderStream.close(); } return count; } }); assertEquals(EXPECTED_COUNT, count); }