RESOLVED - BATCH-1091: Add strict flag to file readers (flat and XML).
added strict flag - when true reader throws exception on open if input resource doesn't exist
This commit is contained in:
@@ -8,6 +8,7 @@ import java.io.InputStream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.file.mapping.PassThroughLineMapper;
|
||||
import org.springframework.batch.item.file.separator.RecordSeparatorPolicy;
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
@@ -135,6 +136,22 @@ public class FlatFileItemReaderTests {
|
||||
assertEquals(TEST_STRING, reader.read());
|
||||
}
|
||||
|
||||
/**
|
||||
* In strict mode, resource must exist at the time reader is opened.
|
||||
*/
|
||||
@Test(expected = ItemStreamException.class)
|
||||
public void testStrictness() throws Exception {
|
||||
|
||||
Resource resource = new NonExistentResource();
|
||||
|
||||
reader.setResource(resource);
|
||||
reader.setStrict(true);
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
|
||||
reader.open(executionContext);
|
||||
}
|
||||
|
||||
private Resource getInputResource(String input) {
|
||||
return new ByteArrayResource(input.getBytes());
|
||||
}
|
||||
|
||||
@@ -231,10 +231,9 @@ public class StaxEventItemReaderTests {
|
||||
source.setResource(new NonExistentResource());
|
||||
source.afterPropertiesSet();
|
||||
|
||||
|
||||
source.open(executionContext);
|
||||
assertNull(source.read());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,6 +247,17 @@ public class StaxEventItemReaderTests {
|
||||
source.read();
|
||||
}
|
||||
|
||||
@Test(expected = ItemStreamException.class)
|
||||
public void testStrictness() throws Exception {
|
||||
|
||||
source.setResource(new NonExistentResource());
|
||||
source.setStrict(true);
|
||||
source.afterPropertiesSet();
|
||||
|
||||
source.open(executionContext);
|
||||
|
||||
}
|
||||
|
||||
private StaxEventItemReader<List<XMLEvent>> createNewInputSouce() {
|
||||
Resource resource = new ByteArrayResource(xml.getBytes());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user