@Test public void testExecutionInStepScope() throws Exception { delegate = new ItemProcessor<String, String>() { public String process(String item) throws Exception { StepContext context = StepSynchronizationManager.getContext(); assertTrue(context != null && context.getStepExecution() != null); return item + item; }; }; processor.setDelegate(delegate); Future<String> result = StepScopeTestUtils.doInStepScope(MetaDataInstanceFactory.createStepExecution(), new Callable<Future<String>>() { public Future<String> call() throws Exception { return processor.process("foo"); } }); assertEquals("foofoo", result.get()); }
private void verifyOutput(int expected) throws Exception { JobParameters jobParameters = new JobParametersBuilder().addString("inputFile", "file:./build/test-outputs/delimitedOutput.csv").toJobParameters(); StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters); int count = StepScopeTestUtils.doInStepScope(stepExecution, new Callable<Integer>() { @Override public Integer call() throws Exception { int count = 0; readerStream.open(new ExecutionContext()); try { while (reader.read() != null) { count++; } } finally { readerStream.close(); } return count; } }); assertEquals(expected, count); }