Example usage for org.springframework.batch.item ItemStreamReader ItemStreamReader

List of usage examples for org.springframework.batch.item ItemStreamReader ItemStreamReader

Introduction

In this page you can find the example usage for org.springframework.batch.item ItemStreamReader ItemStreamReader.

Prototype

ItemStreamReader

Source Link

Usage

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java

/**
 * Check ItemStream is opened//from   w ww . j  a v  a 2s.  c om
 */
@Test
public void testNestedItemStreamOpened() throws Exception {
    writer.setFailures("4");

    ItemStreamReader<String> reader = new ItemStreamReader<String>() {
        @Override
        public void close() throws ItemStreamException {
        }

        @Override
        public void open(ExecutionContext executionContext) throws ItemStreamException {
        }

        @Override
        public void update(ExecutionContext executionContext) throws ItemStreamException {
        }

        @Override
        public String read() throws Exception, UnexpectedInputException, ParseException {
            return null;
        }
    };

    ItemStreamReader<String> stream = new ItemStreamReader<String>() {
        @Override
        public void close() throws ItemStreamException {
            closed = true;
        }

        @Override
        public void open(ExecutionContext executionContext) throws ItemStreamException {
            opened = true;
        }

        @Override
        public void update(ExecutionContext executionContext) throws ItemStreamException {
        }

        @Override
        public String read() throws Exception, UnexpectedInputException, ParseException {
            return null;
        }
    };

    factory.setItemReader(reader);
    factory.setStreams(new ItemStream[] { stream, reader });

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertTrue(opened);
    assertTrue(closed);
    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java

/**
 * Check ItemStream is opened//  w  w  w  . jav a2  s  .  c o m
 */
@SuppressWarnings("unchecked")
@Test
public void testProxiedItemStreamOpened() throws Exception {
    writer.setFailures("4");

    ItemStreamReader<String> reader = new ItemStreamReader<String>() {
        @Override
        public void close() throws ItemStreamException {
            closed = true;
        }

        @Override
        public void open(ExecutionContext executionContext) throws ItemStreamException {
            opened = true;
        }

        @Override
        public void update(ExecutionContext executionContext) throws ItemStreamException {
        }

        @Override
        public String read() throws Exception, UnexpectedInputException, ParseException {
            return null;
        }
    };

    ProxyFactory proxy = new ProxyFactory();
    proxy.setTarget(reader);
    proxy.setInterfaces(new Class<?>[] { ItemReader.class, ItemStream.class });
    proxy.addAdvice(new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            return invocation.proceed();
        }
    });
    Object advised = proxy.getProxy();

    factory.setItemReader((ItemReader<? extends String>) advised);
    factory.setStreams(new ItemStream[] { (ItemStream) advised });

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertTrue(opened);
    assertTrue(closed);
    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
}