Add tests for exhausted read in database readers
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.AbstractItemStreamItemReaderTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class AbstractDatabaseItemStreamItemReaderTests extends AbstractItemStreamItemReaderTests {
|
||||
|
||||
@@ -23,6 +28,18 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadToExhaustion() throws Exception {
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
pointToEmptyInput(reader);
|
||||
int count = 0;
|
||||
Foo item = new Foo();
|
||||
while (count++<100 && item!=null) {
|
||||
item = reader.read();
|
||||
}
|
||||
assertEquals(2, count);
|
||||
}
|
||||
|
||||
protected DataSource getDataSource() {
|
||||
return (DataSource) ctx.getBean("dataSource");
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.internal.runners.JUnit4ClassRunner;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RunWith(JUnit4ClassRunner.class)
|
||||
public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
|
||||
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean();
|
||||
factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass()));
|
||||
|
||||
Reference in New Issue
Block a user