@Override protected void jumpToItem(int itemIndex) throws Exception { for (int i = 0; i < itemIndex; i++) { readLine(); } }
private T readFromDelegate() throws Exception { T item = delegate.read(); if(item instanceof ResourceAware){ ((ResourceAware) item).setResource(getCurrentResource()); } return item; }
public void testMessageInputLineCount() throws Exception { FlatFileParseException exception = new FlatFileParseException("foo", "bar", 100); assertEquals("foo", exception.getMessage()); assertEquals("bar", exception.getInput()); assertEquals(100, exception.getLineNumber()); }
@Test public void testNonExistentResource() throws Exception { Resource resource = new NonExistentResource(); reader.setResource(resource); // afterPropertiesSet should only throw an exception if the Resource is // null reader.afterPropertiesSet(); reader.setStrict(false); reader.open(executionContext); assertNull(reader.read()); reader.close(); }
@Test public void testRuntimeFileCreation() throws Exception { Resource resource = new NonExistentResource(); reader.setResource(resource); // afterPropertiesSet should only throw an exception if the Resource is // null reader.afterPropertiesSet(); // replace the resource to simulate runtime resource creation reader.setResource(getInputResource(TEST_STRING)); reader.open(executionContext); assertEquals(TEST_STRING, reader.read()); }
/** * Setup the tested reader to read from the test resources. */ @Before public void setUp() throws Exception { itemReader.setLineMapper(new FooLineMapper()); tested.setDelegate(itemReader); tested.setComparator(new Comparator<Resource>() { @Override public int compare(Resource o1, Resource o2) { return 0; // do not change ordering } }); tested.setResources(new Resource[] { r1, r2, r3, r4, r5 }); }
/** * 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); }
@Before public void setUp() throws Exception { super.createFile(); delegate = new FlatFileItemWriter<>(); delegate.setLineAggregator(new PassThroughLineAggregator<>()); }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { this.delegate.open(executionContext); }
@Override public Exception getException(String msg, Throwable t) throws Exception { return new FlatFileParseException(msg, t, "bar", 100); }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { this.delegate.open(executionContext); }
@Test public void testWriteStringNotTransactional() throws Exception { writer.setTransactional(false); writeStringTransactionCheck(TEST_STRING); }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { this.delegate.update(executionContext); } }
@Override public void update(ExecutionContext executionContext) throws ItemStreamException { this.delegate.update(executionContext); } }
@Override public void close() throws ItemStreamException { this.delegate.close(); }
@Override public void close() throws ItemStreamException { this.delegate.close(); }
@Override public Foo mapLine(String line, int lineNumber) throws Exception { return new Foo(line); } }
@Override public Item mapLine(String line, int lineNumber) throws Exception { return new Item(line); }
private String readLine() throws IOException { return readLine("UTF-8"); }
@Override public Exception getException(String msg) throws Exception { return new FlatFileParseException(msg, "bar"); }