Example usage for org.springframework.batch.core.step.tasklet TestingChunkOrientedTasklet TestingChunkOrientedTasklet

List of usage examples for org.springframework.batch.core.step.tasklet TestingChunkOrientedTasklet TestingChunkOrientedTasklet

Introduction

In this page you can find the example usage for org.springframework.batch.core.step.tasklet TestingChunkOrientedTasklet TestingChunkOrientedTasklet.

Prototype

public TestingChunkOrientedTasklet(ItemReader<T> itemReader, ItemWriter<T> itemWriter,
        RepeatOperations repeatOperations) 

Source Link

Document

Creates a PassThroughItemProcessor and uses it to create an instance of Tasklet .

Usage

From source file:org.springframework.batch.core.step.tasklet.AsyncChunkOrientedStepIntegrationTests.java

@Test
@Ignore//from   w w w. j a  v a2  s.c  o m
public void testStatus() throws Exception {

    step.setTasklet(new TestingChunkOrientedTasklet<String>(
            getReader(new String[] { "a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c" }),
            new ItemWriter<String>() {
                @Override
                public void write(List<? extends String> data) throws Exception {
                    written.addAll(data);
                }
            }, chunkOperations));

    final JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters(
            Collections.singletonMap("run.id", new JobParameter(getClass().getName() + ".1"))));
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);

    jobRepository.add(stepExecution);
    step.execute(stepExecution);
    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    // Need a transaction so one connection is enough to get job execution and its parameters
    StepExecution lastStepExecution = new TransactionTemplate(transactionManager)
            .execute(new TransactionCallback<StepExecution>() {
                @Override
                public StepExecution doInTransaction(TransactionStatus status) {
                    return jobRepository.getLastStepExecution(jobExecution.getJobInstance(), step.getName());
                }
            });
    assertEquals(lastStepExecution, stepExecution);
    assertFalse(lastStepExecution == stepExecution);
}