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:
robokaso
2009-02-23 23:49:19 +00:00
parent 03f22512d6
commit fa2076594d
4 changed files with 63 additions and 7 deletions

View File

@@ -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());
}

View File

@@ -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());