IN PROGRESS - issue BATCH-212: Merge InputSource with ItemProvider
http://opensource.atlassian.com/projects/spring/browse/BATCH-212 Merge InputSource/ItemProvider -> ItemReader.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorInputSource} using standard hibernate {@link Session}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorInputSourceStatefulIntegrationTests extends HibernateCursorInputSourceIntegrationTests {
|
||||
|
||||
protected boolean isUseStatelessSession() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,20 +2,20 @@ package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorInputSource} using {@link StatelessSession}.
|
||||
* Tests for {@link HibernateCursorItemReader} using {@link StatelessSession}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class HibernateCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
|
||||
factoryBean.setDataSource(super.getJdbcTemplate().getDataSource());
|
||||
factoryBean.setMappingLocations(new Resource[] { new ClassPathResource("Foo.hbm.xml", getClass()) });
|
||||
@@ -25,7 +25,7 @@ public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSour
|
||||
|
||||
String hsqlQuery = "from Foo";
|
||||
|
||||
HibernateCursorInputSource inputSource = new HibernateCursorInputSource();
|
||||
HibernateCursorItemReader inputSource = new HibernateCursorItemReader();
|
||||
inputSource.setQueryString(hsqlQuery);
|
||||
inputSource.setSessionFactory(sessionFactory);
|
||||
inputSource.setUseStatelessSession(isUseStatelessSession());
|
||||
@@ -41,11 +41,11 @@ public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSour
|
||||
/**
|
||||
* Exception scenario.
|
||||
*
|
||||
* {@link HibernateCursorInputSource#setUseStatelessSession(boolean)} can be
|
||||
* {@link HibernateCursorItemReader#setUseStatelessSession(boolean)} can be
|
||||
* called only in uninitialized state.
|
||||
*/
|
||||
public void testSetUseStatelessSession() {
|
||||
HibernateCursorInputSource inputSource = ((HibernateCursorInputSource) source);
|
||||
HibernateCursorItemReader inputSource = ((HibernateCursorItemReader) source);
|
||||
|
||||
// initialize and call setter => error
|
||||
inputSource.open();
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorItemReader} using standard hibernate {@link Session}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorItemReaderStatefulIntegrationTests extends HibernateCursorItemReaderIntegrationTests {
|
||||
|
||||
protected boolean isUseStatelessSession() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.FooRowMapper;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* Tests for {@link JdbcCursorInputSource}
|
||||
* Tests for {@link JdbcCursorItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcCursorInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class JdbcCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
JdbcCursorInputSource result = new JdbcCursorInputSource();
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
JdbcCursorItemReader result = new JdbcCursorItemReader();
|
||||
result.setDataSource(super.getJdbcTemplate().getDataSource());
|
||||
result.setSql("select ID, NAME, VALUE from T_FOOS");
|
||||
result.setIgnoreWarnings(true);
|
||||
@@ -6,8 +6,8 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -17,9 +17,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DrivingQueryInputSourceTests extends TestCase {
|
||||
public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
InputSource source;
|
||||
ItemReader source;
|
||||
|
||||
static {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
@@ -28,12 +28,12 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
}
|
||||
|
||||
private InputSource createInputSource() throws Exception{
|
||||
private ItemReader createItemReader() throws Exception{
|
||||
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(new MockKeyGenerator());
|
||||
|
||||
return inputSource;
|
||||
@@ -79,7 +79,7 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -117,8 +117,9 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -129,8 +130,9 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Rollback scenario.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -159,11 +161,11 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
class FooInputSource implements InputSource, Restartable, DisposableBean, InitializingBean{
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, Restartable, DisposableBean, InitializingBean{
|
||||
|
||||
DrivingQueryInputSource inputSource;
|
||||
DrivingQueryItemReader inputSource;
|
||||
FooDao fooDao = new SingleKeyFooDao();
|
||||
|
||||
public FooInputSource(DrivingQueryInputSource inputSource, JdbcTemplate jdbcTemplate) {
|
||||
public FooItemReader(DrivingQueryItemReader inputSource, JdbcTemplate jdbcTemplate) {
|
||||
this.inputSource = inputSource;
|
||||
fooDao.setJdbcTemplate(jdbcTemplate);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.IbatisKeyGenerator;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
/**
|
||||
* Tests for {@link IbatisDrivingQueryInputSource}
|
||||
* Tests for {@link IbatisDrivingQueryItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class IbatisInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class IbatisItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean();
|
||||
factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass()));
|
||||
@@ -23,7 +23,7 @@ public class IbatisInputSourceIntegrationTests extends AbstractDataSourceInputSo
|
||||
factory.afterPropertiesSet();
|
||||
SqlMapClient sqlMapClient = (SqlMapClient) factory.getObject();
|
||||
|
||||
IbatisDrivingQueryInputSource inputSource = new IbatisDrivingQueryInputSource();
|
||||
IbatisDrivingQueryItemReader inputSource = new IbatisDrivingQueryItemReader();
|
||||
IbatisKeyGenerator keyGenerator = new IbatisKeyGenerator();
|
||||
keyGenerator.setDrivingQueryId("getAllFooIds");
|
||||
inputSource.setDetailsQueryId("getFooById");
|
||||
@@ -15,29 +15,29 @@
|
||||
*/
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.MultipleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class MultipleColumnJdbcDrivingQueryInputSourceIntegrationTests extends
|
||||
AbstractJdbcInputSourceIntegrationTests {
|
||||
public class MultipleColumnJdbcDrivingQueryItemReaderIntegrationTests extends
|
||||
AbstractJdbcItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
MultipleColumnJdbcKeyGenerator keyGenerator =
|
||||
new MultipleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID, VALUE from T_FOOS order by ID, VALUE");
|
||||
|
||||
keyGenerator.setRestartQuery("SELECT ID, VALUE from T_FOOS where ID > ? and VALUE > ? order by ID");
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(keyGenerator);
|
||||
FooInputSource fooInputSource = new FooInputSource(inputSource, getJdbcTemplate());
|
||||
fooInputSource.setFooDao(new CompositeKeyFooDao(getJdbcTemplate()));
|
||||
return fooInputSource;
|
||||
FooItemReader fooItemReader = new FooItemReader(inputSource, getJdbcTemplate());
|
||||
fooItemReader.setFooDao(new CompositeKeyFooDao(getJdbcTemplate()));
|
||||
return fooItemReader;
|
||||
}
|
||||
|
||||
// private static class FooRestartDataConverter implements RestartDataRowMapper{
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.SingleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcInputSourceIntegrationTests;
|
||||
|
||||
public class SingleColumnJdbcDrivingQueryInputSourceIntegrationTests extends AbstractJdbcInputSourceIntegrationTests {
|
||||
|
||||
protected InputSource source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
|
||||
SingleColumnJdbcKeyGenerator keyStrategy = new SingleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID from T_FOOS order by ID");
|
||||
keyStrategy.setRestartSql("SELECT ID from T_FOOS where ID > ? order by ID");
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
inputSource.setKeyGenerator(keyStrategy);
|
||||
|
||||
return new FooInputSource(inputSource, getJdbcTemplate());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.driving.support.SingleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
public class SingleColumnJdbcDrivingQueryItemReaderIntegrationTests extends AbstractJdbcItemReaderIntegrationTests {
|
||||
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
SingleColumnJdbcKeyGenerator keyStrategy = new SingleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID from T_FOOS order by ID");
|
||||
keyStrategy.setRestartSql("SELECT ID from T_FOOS where ID > ? order by ID");
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(keyStrategy);
|
||||
|
||||
return new FooItemReader(inputSource, getJdbcTemplate());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileItemReader;
|
||||
import org.springframework.batch.io.file.support.transform.LineTokenizer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -30,17 +30,17 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultFlatFileInputSource}
|
||||
* Tests for {@link DefaultFlatFileItemReader}
|
||||
*
|
||||
* @author robert.kasanicky
|
||||
*
|
||||
* TODO only regular reading is tested currently, add exception cases, restart,
|
||||
* skip, validation...
|
||||
*/
|
||||
public class DefaultFlatFileInputSourceTests extends TestCase {
|
||||
public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private DefaultFlatFileInputSource inputSource = new DefaultFlatFileInputSource();
|
||||
private DefaultFlatFileItemReader inputSource = new DefaultFlatFileItemReader();
|
||||
|
||||
// common value used for writing to a file
|
||||
private String TEST_STRING = "FlatFileInputTemplate-TestData";
|
||||
@@ -156,7 +156,7 @@ public class DefaultFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRestartWithNullReader() throws Exception {
|
||||
inputSource = new DefaultFlatFileInputSource();
|
||||
inputSource = new DefaultFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
// do not open the template...
|
||||
@@ -34,15 +34,15 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleFlatFileInputSourceTests}
|
||||
* Tests for {@link SimpleFlatFileItemReaderTests}
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public class SimpleFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private SimpleFlatFileInputSource inputSource = new SimpleFlatFileInputSource();
|
||||
private SimpleFlatFileItemReader inputSource = new SimpleFlatFileItemReader();
|
||||
|
||||
// common value used for writing to a file
|
||||
private String TEST_STRING = "FlatFileInputTemplate-TestData";
|
||||
@@ -135,14 +135,14 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testReadBeforeOpen() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
|
||||
}
|
||||
|
||||
public void testCloseBeforeOpen() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
inputSource.close();
|
||||
@@ -152,7 +152,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
|
||||
public void testCloseOnDestroy() throws Exception {
|
||||
final List list = new ArrayList();
|
||||
inputSource = new SimpleFlatFileInputSource() {
|
||||
inputSource = new SimpleFlatFileItemReader() {
|
||||
public void close() {
|
||||
list.add("close");
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testInitializationWithNullResource() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
try {
|
||||
inputSource.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
@@ -178,7 +178,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetValidEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding("UTF-8");
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -186,7 +186,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetNullEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding(null);
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
try {
|
||||
@@ -199,7 +199,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetInvalidEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding("foo");
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
try {
|
||||
@@ -229,7 +229,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testInvalidFile() throws IOException {
|
||||
DefaultFlatFileInputSource ffit = new DefaultFlatFileInputSource();
|
||||
DefaultFlatFileItemReader ffit = new DefaultFlatFileItemReader();
|
||||
|
||||
FileSystemResource resource = new FileSystemResource("FooDummy.txt");
|
||||
assertTrue(!resource.exists());
|
||||
@@ -251,7 +251,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public void testColumnNamesInHeader() throws Exception {
|
||||
final String INPUT = "name1|name2\nvalue1|value2\nvalue3|value4";
|
||||
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(INPUT));
|
||||
inputSource.setTokenizer(new DelimitedLineTokenizer('|'));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -274,7 +274,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public void testLinesToSkip() throws Exception {
|
||||
final String INPUT = "foo bar spam\none two\nthree four";
|
||||
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(INPUT));
|
||||
inputSource.setTokenizer(new DelimitedLineTokenizer(' '));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -15,7 +15,7 @@ import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderInputSource;
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderItemReader;
|
||||
import org.springframework.batch.io.file.support.stax.FragmentDeserializer;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -26,14 +26,14 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
|
||||
/**
|
||||
* Tests for {@link StaxEventReaderInputSource}.
|
||||
* Tests for {@link StaxEventReaderItemReader}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private StaxEventReaderInputSource source;
|
||||
private StaxEventReaderItemReader source;
|
||||
|
||||
// test xml input
|
||||
private String xml = "<root> <fragment> <misc1/> </fragment> <misc2/> <fragment> testString </fragment> </root>";
|
||||
@@ -83,7 +83,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
* InputSource should pass XML fragments to deserializer wrapped with
|
||||
* ItemReader should pass XML fragments to deserializer wrapped with
|
||||
* StartDocument and EndDocument events.
|
||||
*/
|
||||
public void testFragmentWrapping() throws Exception {
|
||||
@@ -120,7 +120,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
source.read();
|
||||
RestartData restartData = source.getRestartData();
|
||||
assertEquals("1", restartData.getProperties().
|
||||
getProperty("StaxEventReaderInputSource.recordcount"));
|
||||
getProperty("StaxEventReaderItemReader.recordcount"));
|
||||
List expectedAfterRestart = (List) source.read();
|
||||
|
||||
source = createNewInputSouce();
|
||||
@@ -136,7 +136,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
public void testInvalidRestore() {
|
||||
Properties props = new Properties() {{
|
||||
final String MORE_RECORDS_THAN_INPUT_CONTAINS = "100000";
|
||||
setProperty("StaxEventReaderInputSource.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
setProperty("StaxEventReaderItemReader.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
}};
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(props));
|
||||
@@ -219,7 +219,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
public void testClose() throws Exception{
|
||||
|
||||
MockStaxEventReaderInputSource newSource = new MockStaxEventReaderInputSource();
|
||||
MockStaxEventReaderItemReader newSource = new MockStaxEventReaderItemReader();
|
||||
Resource resource = new ByteArrayResource(xml.getBytes());
|
||||
newSource.setResource(resource);
|
||||
|
||||
@@ -258,13 +258,13 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
private int extractRecordCountFrom(Properties statistics) {
|
||||
return Integer.valueOf(
|
||||
source.getStatistics().getProperty(StaxEventReaderInputSource.READ_COUNT_STATISTICS_NAME)).intValue();
|
||||
source.getStatistics().getProperty(StaxEventReaderItemReader.READ_COUNT_STATISTICS_NAME)).intValue();
|
||||
}
|
||||
|
||||
private StaxEventReaderInputSource createNewInputSouce() {
|
||||
private StaxEventReaderItemReader createNewInputSouce() {
|
||||
Resource resource = new ByteArrayResource(xml.getBytes());
|
||||
|
||||
StaxEventReaderInputSource newSource = new StaxEventReaderInputSource();
|
||||
StaxEventReaderItemReader newSource = new StaxEventReaderItemReader();
|
||||
newSource.setResource(resource);
|
||||
|
||||
newSource.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT);
|
||||
@@ -282,7 +282,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* A simple mapFragment implementation checking the
|
||||
* StaxEventReaderInputSource basic read functionality.
|
||||
* StaxEventReaderItemReader basic read functionality.
|
||||
* @param eventReader
|
||||
* @return list of the events from fragment body
|
||||
*/
|
||||
@@ -349,7 +349,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private static class MockStaxEventReaderInputSource extends StaxEventReaderInputSource {
|
||||
private static class MockStaxEventReaderItemReader extends StaxEventReaderItemReader {
|
||||
|
||||
private boolean openCalled = false;
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.springframework.batch.io.sql;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -17,20 +17,20 @@ import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Common scenarios for testing {@link InputSource} implementations which read data from database.
|
||||
* Common scenarios for testing {@link ItemReader} implementations which read data from database.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected InputSource source;
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected abstract InputSource createInputSource() throws Exception;
|
||||
protected abstract ItemReader createItemReader() throws Exception;
|
||||
|
||||
protected String[] getConfigLocations(){
|
||||
return new String[] { "org/springframework/batch/io/sql/data-source-context.xml"};
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
protected void onSetUp()throws Exception{
|
||||
super.onSetUp();
|
||||
BatchTransactionSynchronizationManager.clearSynchronizations();
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
getAsInitializingBean(source).afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -126,8 +126,9 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -138,8 +139,9 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
|
||||
/**
|
||||
* Rollback scenario.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -168,15 +170,15 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private DisposableBean getAsDisposableBean(InputSource source) {
|
||||
private DisposableBean getAsDisposableBean(ItemReader source) {
|
||||
return (DisposableBean) source;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.springframework.batch.io.support;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -18,20 +18,20 @@ import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Common scenarios for testing {@link InputSource} implementations which read data from database.
|
||||
* Common scenarios for testing {@link ItemReader} implementations which read data from database.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractDataSourceInputSourceIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
public abstract class AbstractDataSourceItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected InputSource source;
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return configured input source ready for use
|
||||
*/
|
||||
protected abstract InputSource createInputSource() throws Exception;
|
||||
protected abstract ItemReader createItemReader() throws Exception;
|
||||
|
||||
protected String[] getConfigLocations(){
|
||||
return new String[] { "org/springframework/batch/io/sql/data-source-context.xml"};
|
||||
@@ -43,7 +43,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
super.onSetUpInTransaction();
|
||||
BatchTransactionSynchronizationManager.clearSynchronizations();
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -95,7 +95,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -133,8 +133,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -145,8 +146,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Rollback scenario - input source rollbacks to last commit point.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -164,8 +166,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Rollback scenario with skip - input source rollbacks to last commit point.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollbackAndSkip() {
|
||||
public void testRollbackAndSkip() throws Exception {
|
||||
|
||||
if (!(source instanceof Skippable)) {
|
||||
return;
|
||||
@@ -217,7 +220,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -238,19 +241,19 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Skippable getAsSkippable(InputSource source) {
|
||||
private Skippable getAsSkippable(ItemReader source) {
|
||||
return (Skippable) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private DisposableBean getAsDisposableBean(InputSource source) {
|
||||
private DisposableBean getAsDisposableBean(ItemReader source) {
|
||||
return (DisposableBean) source;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
}
|
||||
|
||||
//AbstractInputSource should synchronize on first call to read.
|
||||
//AbstractItemReader should synchronize on first call to read.
|
||||
public void testSynchronizationRegistration(){
|
||||
|
||||
source.registerSynchronization();
|
||||
@@ -97,7 +97,7 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
assertFalse(source.rollbackCalled);
|
||||
}
|
||||
|
||||
private static class MockIoSource extends AbstractTransactionalIoSource{
|
||||
private static class MockIoSource extends AbstractTransactionalIoSource {
|
||||
|
||||
private boolean commitCalled = false;
|
||||
private boolean rollbackCalled = false;
|
||||
@@ -110,7 +110,11 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
protected void transactionRolledBack() {
|
||||
Assert.isTrue(!rollbackCalled, "Rollback aleady called");
|
||||
rollbackCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Object read() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
|
||||
@@ -18,18 +18,18 @@ package org.springframework.batch.item;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
|
||||
public class ItemProviderTests extends TestCase {
|
||||
|
||||
ItemProvider provider = new AbstractItemProvider() {
|
||||
public Object next() {
|
||||
ItemReader provider = new AbstractItemReader() {
|
||||
public Object read() {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingItemProcessor}.
|
||||
* Tests for {@link ItemProcessorAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProcessorIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private DelegatingItemProcessor processor;
|
||||
private ItemProcessorAdapter processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DelegatingItemProcessorIntegrationTests extends AbstractDependencyI
|
||||
}
|
||||
|
||||
//setter for auto-injection
|
||||
public void setProcessor(DelegatingItemProcessor processor) {
|
||||
public void setProcessor(ItemProcessorAdapter processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,27 +6,27 @@ import java.util.Iterator;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
public class AggregateItemProviderTests extends TestCase {
|
||||
public class AggregateItemReaderTests extends TestCase {
|
||||
|
||||
private MockControl inputControl;
|
||||
private InputSource input;
|
||||
private AggregateItemProvider provider;
|
||||
private ItemReader input;
|
||||
private AggregateItemReader provider;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock for input
|
||||
inputControl = MockControl.createControl(InputSource.class);
|
||||
input = (InputSource) inputControl.getMock();
|
||||
inputControl = MockControl.createControl(ItemReader.class);
|
||||
input = (ItemReader) inputControl.getMock();
|
||||
|
||||
//create provider
|
||||
provider = new AggregateItemProvider();
|
||||
provider.setInputSource(input);
|
||||
provider = new AggregateItemReader();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
public void testNext() {
|
||||
public void testNext() throws Exception {
|
||||
|
||||
//set-up mock input
|
||||
input.read();
|
||||
@@ -40,7 +40,7 @@ public class AggregateItemProviderTests extends TestCase {
|
||||
inputControl.replay();
|
||||
|
||||
//read object
|
||||
Object result = provider.next();
|
||||
Object result = provider.read();
|
||||
|
||||
//it should be collection of 3 strings "line"
|
||||
assertTrue(result instanceof Collection);
|
||||
@@ -52,7 +52,7 @@ public class AggregateItemProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
//read object again - it should return null
|
||||
assertNull(provider.next());
|
||||
assertNull(provider.read());
|
||||
|
||||
//verify method calls
|
||||
inputControl.verify();
|
||||
@@ -7,13 +7,13 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingItemProvider}.
|
||||
* Tests for {@link ItemReaderAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProviderIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public class DelegatingItemReaderIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private DelegatingItemProvider provider;
|
||||
private ItemReaderAdapter provider;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DelegatingItemProviderIntegrationTests extends AbstractDependencyIn
|
||||
public void testNext() throws Exception {
|
||||
List returnedItems = new ArrayList();
|
||||
Object item;
|
||||
while ((item = provider.next()) != null) {
|
||||
while ((item = provider.read()) != null) {
|
||||
returnedItems.add(item);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DelegatingItemProviderIntegrationTests extends AbstractDependencyIn
|
||||
assertFalse(provider.recover(null, null));
|
||||
}
|
||||
|
||||
public void setProvider(DelegatingItemProvider provider) {
|
||||
public void setProvider(ItemReaderAdapter provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -29,21 +29,21 @@ import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* Unit test for {@link InputSourceItemProvider}
|
||||
* Unit test for {@link DelegatingItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class InputSourceItemProviderTests extends TestCase {
|
||||
public class DelegatingItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private InputSourceItemProvider itemProvider = new InputSourceItemProvider();
|
||||
private DelegatingItemReader itemProvider = new DelegatingItemReader();
|
||||
|
||||
private InputSource source;
|
||||
private ItemReader source;
|
||||
|
||||
// create input template and inject it to data provider
|
||||
protected void setUp() throws Exception {
|
||||
source = new MockInputSource(this);
|
||||
itemProvider.setInputSource(source);
|
||||
source = new MockItemReader(this);
|
||||
itemProvider.setItemReader(source);
|
||||
}
|
||||
|
||||
public void testAfterPropertiesSet()throws Exception{
|
||||
@@ -51,9 +51,9 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
itemProvider.afterPropertiesSet();
|
||||
}
|
||||
|
||||
public void testNullInputSource(){
|
||||
public void testNullItemReader(){
|
||||
try{
|
||||
itemProvider.setInputSource(null);
|
||||
itemProvider.setItemReader(null);
|
||||
itemProvider.afterPropertiesSet();
|
||||
fail();
|
||||
}catch(Exception ex){
|
||||
@@ -63,9 +63,10 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Uses input template to provide the domain object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testNext() {
|
||||
Object result = itemProvider.next();
|
||||
public void testNext() throws Exception {
|
||||
Object result = itemProvider.read();
|
||||
assertSame("domain object is provided by the input template", this, result);
|
||||
}
|
||||
|
||||
@@ -87,18 +88,19 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forwared restart data to input template
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() {
|
||||
public void testRestoreFrom() throws Exception {
|
||||
itemProvider.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
assertEquals("bar", itemProvider.next());
|
||||
assertEquals("bar", itemProvider.read());
|
||||
}
|
||||
|
||||
public void testSkip() {
|
||||
public void testSkip() throws Exception {
|
||||
itemProvider.skip();
|
||||
assertEquals("after skip", itemProvider.next());
|
||||
assertEquals("after skip", itemProvider.read());
|
||||
}
|
||||
|
||||
private static class MockInputSource implements InputSource, StatisticsProvider, Restartable, Skippable {
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, Restartable, Skippable {
|
||||
|
||||
private Object value;
|
||||
|
||||
@@ -114,7 +116,7 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
public MockInputSource(Object value) {
|
||||
public MockItemReader(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.jms.core.JmsOperations;
|
||||
|
||||
public class JmsItemProviderTests extends TestCase {
|
||||
public class JmsItemReaderTests extends TestCase {
|
||||
|
||||
JmsItemProvider itemProvider = new JmsItemProvider();
|
||||
JmsItemReader itemProvider = new JmsItemReader();
|
||||
|
||||
public void testNoItemTypeSunnyDay() {
|
||||
MockControl templateControl = MockControl.createControl(JmsOperations.class);
|
||||
@@ -38,7 +38,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
templateControl.replay();
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
assertEquals("foo", itemProvider.next());
|
||||
assertEquals("foo", itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(String.class);
|
||||
assertEquals("foo", itemProvider.next());
|
||||
assertEquals("foo", itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Date.class);
|
||||
assertEquals(date, itemProvider.next());
|
||||
assertEquals(date, itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Date.class);
|
||||
try {
|
||||
itemProvider.next();
|
||||
itemProvider.read();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -97,7 +97,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Message.class);
|
||||
assertEquals(message, itemProvider.next());
|
||||
assertEquals(message, itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ListItemProviderTests extends TestCase {
|
||||
public class ListItemReaderTests extends TestCase {
|
||||
|
||||
ListItemProvider provider = new ListItemProvider(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
ListItemReader provider = new ListItemReader(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("a", provider.next());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("c", provider.next());
|
||||
assertEquals(null, provider.next());
|
||||
assertEquals("a", provider.read());
|
||||
assertEquals("b", provider.read());
|
||||
assertEquals("c", provider.read());
|
||||
assertEquals(null, provider.read());
|
||||
}
|
||||
|
||||
public void testChangeList() throws Exception {
|
||||
List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
provider = new ListItemProvider(list);
|
||||
assertEquals("a", provider.next());
|
||||
provider = new ListItemReader(list);
|
||||
assertEquals("a", provider.read());
|
||||
list.clear();
|
||||
assertEquals(0, list.size());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("b", provider.read());
|
||||
}
|
||||
}
|
||||
@@ -29,25 +29,25 @@ import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
public class TransactionAwareListItemReaderTests extends TestCase {
|
||||
|
||||
// TransactionAwareListItemProvider provider = new
|
||||
// TransactionAwareListItemProvider(Arrays.asList(new String[] { "a",
|
||||
// "b", "c" }));
|
||||
ListItemProvider provider;
|
||||
ListItemReader provider;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
TransactionAwareProxyFactory factory = new TransactionAwareProxyFactory(Arrays.asList(new String[] { "a", "b",
|
||||
"c" }));
|
||||
provider = new ListItemProvider((List) factory.createInstance());
|
||||
provider = new ListItemReader((List) factory.createInstance());
|
||||
}
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("a", provider.next());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("c", provider.next());
|
||||
assertEquals(null, provider.next());
|
||||
assertEquals("a", provider.read());
|
||||
assertEquals("b", provider.read());
|
||||
assertEquals("c", provider.read());
|
||||
assertEquals(null, provider.read());
|
||||
}
|
||||
|
||||
public void testCommit() throws Exception {
|
||||
@@ -56,7 +56,7 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
taken.add(provider.next());
|
||||
taken.add(provider.read());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -68,10 +68,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
assertEquals(1, taken.size());
|
||||
assertEquals("a", taken.get(0));
|
||||
taken.clear();
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
// System.err.println(taken);
|
||||
assertFalse(taken.contains("a"));
|
||||
@@ -82,10 +82,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
final List taken = new ArrayList();
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
taken.add(provider.next());
|
||||
taken.add(provider.read());
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
});
|
||||
@@ -112,10 +112,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
assertEquals(1, taken.size());
|
||||
assertEquals("a", taken.get(0));
|
||||
taken.clear();
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
System.err.println(taken);
|
||||
assertTrue(taken.contains("a"));
|
||||
@@ -18,18 +18,18 @@ package org.springframework.batch.item.provider;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.exception.ValidationException;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.validator.Validator;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class ValidatingItemProviderTests extends TestCase {
|
||||
public class ValidatingItemReaderTests extends TestCase {
|
||||
|
||||
InputSource inputSource;
|
||||
ValidatingItemProvider itemProvider;
|
||||
ItemReader inputSource;
|
||||
ValidatingItemReader itemProvider;
|
||||
Validator validator;
|
||||
MockControl validatorControl = MockControl.createControl(Validator.class);
|
||||
|
||||
@@ -39,20 +39,20 @@ public class ValidatingItemProviderTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
inputSource = new MockInputSource(this);
|
||||
inputSource = new MockItemReader(this);
|
||||
validator = (Validator)validatorControl.getMock();
|
||||
itemProvider = new ValidatingItemProvider();
|
||||
itemProvider.setInputSource(inputSource);
|
||||
itemProvider = new ValidatingItemReader();
|
||||
itemProvider.setItemReader(inputSource);
|
||||
itemProvider.setValidator(validator);
|
||||
}
|
||||
|
||||
/*
|
||||
* Super class' afterPropertieSet should be called to
|
||||
* ensure InputSource is set.
|
||||
* ensure ItemReader is set.
|
||||
*/
|
||||
public void testInputSourcePropertiesSet(){
|
||||
public void testItemReaderPropertiesSet(){
|
||||
try{
|
||||
itemProvider.setInputSource(null);
|
||||
itemProvider.setItemReader(null);
|
||||
itemProvider.afterPropertiesSet();
|
||||
fail();
|
||||
}catch(Exception ex){
|
||||
@@ -70,40 +70,40 @@ public class ValidatingItemProviderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidation(){
|
||||
public void testValidation() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.replay();
|
||||
assertEquals(itemProvider.next(), this);
|
||||
assertEquals(itemProvider.read(), this);
|
||||
validatorControl.verify();
|
||||
}
|
||||
|
||||
public void testValidationException(){
|
||||
public void testValidationException() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.setThrowable(new ValidationException(""));
|
||||
validatorControl.replay();
|
||||
try{
|
||||
itemProvider.next();
|
||||
itemProvider.read();
|
||||
fail();
|
||||
}catch(ValidationException ex){
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testNullInput(){
|
||||
public void testNullInput() throws Exception{
|
||||
validatorControl.replay();
|
||||
itemProvider.setInputSource(new MockInputSource(null));
|
||||
assertNull(itemProvider.next());
|
||||
itemProvider.setItemReader(new MockItemReader(null));
|
||||
assertNull(itemProvider.read());
|
||||
//assert validator wasn't called.
|
||||
validatorControl.verify();
|
||||
}
|
||||
|
||||
private static class MockInputSource implements InputSource{
|
||||
private static class MockItemReader extends AbstractItemReader {
|
||||
|
||||
Object value;
|
||||
|
||||
public MockInputSource(Object value){
|
||||
public MockItemReader(Object value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
|
||||
public class ItemProviderRepeatCallbackTests extends TestCase {
|
||||
public class ItemReaderRepeatCallbackTests extends TestCase {
|
||||
|
||||
ItemProviderRepeatCallback callback;
|
||||
ItemReaderRepeatCallback callback;
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
public void testDoWithRepeat() throws Exception {
|
||||
callback = new ItemProviderRepeatCallback(new ListItemProvider(Arrays.asList(new String[] { "foo", "bar" })),
|
||||
callback = new ItemReaderRepeatCallback(new ListItemReader(Arrays.asList(new String[] { "foo", "bar" })),
|
||||
new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
list.add(data);
|
||||
@@ -44,11 +44,11 @@ public class ItemProviderRepeatCallbackTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDoWithRepeatNullProcessor() throws Exception {
|
||||
ListItemProvider provider = new ListItemProvider(Arrays.asList(new String[] { "foo", "bar" }));
|
||||
callback = new ItemProviderRepeatCallback(provider);
|
||||
ListItemReader provider = new ListItemReader(Arrays.asList(new String[] { "foo", "bar" }));
|
||||
callback = new ItemReaderRepeatCallback(provider);
|
||||
callback.doInIteration(null);
|
||||
assertEquals(0, list.size());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.SimpleFlatFileInputSource;
|
||||
import org.springframework.batch.io.file.support.SimpleFlatFileItemReader;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.InputSourceItemProvider;
|
||||
import org.springframework.batch.item.provider.DelegatingItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@@ -40,26 +40,26 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
|
||||
protected TradeProcessor processor = new TradeProcessor();
|
||||
|
||||
protected TradeItemProvider provider;
|
||||
protected TradeItemReader provider;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
provider = new TradeItemProvider(resource);
|
||||
provider = new TradeItemReader(resource);
|
||||
}
|
||||
|
||||
protected static class TradeItemProvider extends InputSourceItemProvider {
|
||||
protected static class TradeItemReader extends DelegatingItemReader {
|
||||
|
||||
protected TradeItemProvider(Resource resource) throws Exception {
|
||||
protected TradeItemReader(Resource resource) throws Exception {
|
||||
super();
|
||||
SimpleFlatFileInputSource inputSource = new SimpleFlatFileInputSource();
|
||||
SimpleFlatFileItemReader inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(resource);
|
||||
inputSource.setFieldSetMapper(new TradeMapper());
|
||||
inputSource.afterPropertiesSet();
|
||||
setInputSource(inputSource);
|
||||
setItemReader(inputSource);
|
||||
}
|
||||
|
||||
public synchronized Object next() {
|
||||
return super.next();
|
||||
public synchronized Object read() throws Exception {
|
||||
return super.read();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
|
||||
public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
@@ -41,7 +41,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final String threadName = Thread.currentThread().getName();
|
||||
final Set threadNames = new HashSet();
|
||||
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor) {
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
@@ -72,7 +72,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final String threadName = Thread.currentThread().getName();
|
||||
final Set threadNames = new HashSet();
|
||||
|
||||
final RepeatCallback stepCallback = new ItemProviderRepeatCallback(provider, processor) {
|
||||
final RepeatCallback stepCallback = new ItemReaderRepeatCallback(provider, processor) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.batch.repeat.support;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -46,7 +46,7 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
public void testChunkedBatchWithTerminationPolicy() throws Exception {
|
||||
|
||||
RepeatTemplate repeatTemplate = new RepeatTemplate();
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor);
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor);
|
||||
|
||||
final RepeatTemplate chunkTemplate = new RepeatTemplate();
|
||||
// The policy is resettable so we only have to resolve this dependency
|
||||
@@ -80,7 +80,7 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
public void testAsynchronousChunkedBatchWithCompletionPolicy() throws Exception {
|
||||
|
||||
RepeatTemplate repeatTemplate = new RepeatTemplate();
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor);
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor);
|
||||
|
||||
final TaskExecutorRepeatTemplate chunkTemplate = new TaskExecutorRepeatTemplate();
|
||||
// The policy is resettable so we only have to resolve this dependency
|
||||
@@ -148,17 +148,17 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
|
||||
while (!chunker.ready()) {
|
||||
|
||||
ItemProvider truncated = new AbstractItemProvider() {
|
||||
ItemReader truncated = new AbstractItemReader() {
|
||||
int count = 0;
|
||||
|
||||
public Object next() throws Exception {
|
||||
public Object read() throws Exception {
|
||||
if (count++ < 2)
|
||||
return provider.next();
|
||||
return provider.read();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
chunker.reset();
|
||||
template.iterate(new ItemProviderRepeatCallback(truncated, processor) {
|
||||
template.iterate(new ItemReaderRepeatCallback(truncated, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
@@ -44,7 +44,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}
|
||||
|
||||
public void testExecute() throws Exception {
|
||||
template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
|
||||
template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
|
||||
assertEquals(2, processor.count);
|
||||
|
||||
@@ -197,7 +197,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContext() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
@@ -225,7 +225,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContextTerminated() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
@@ -321,7 +321,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testResult() throws Exception {
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
// We are complete - do not expect to be called again
|
||||
assertFalse(result.isContinuable());
|
||||
@@ -360,7 +360,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
ExitStatus result = ExitStatus.FINISHED;
|
||||
|
||||
try {
|
||||
result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
|
||||
@@ -18,23 +18,23 @@ package org.springframework.batch.retry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
|
||||
public class ListItemProviderRecoverer extends ListItemProvider implements ItemProvider, ItemRecoverer {
|
||||
public class ListItemReaderRecoverer extends ListItemReader implements ItemReader, ItemRecoverer {
|
||||
|
||||
/**
|
||||
* Delegate to super class constructor.
|
||||
* @param list
|
||||
*/
|
||||
public ListItemProviderRecoverer(List list) {
|
||||
public ListItemReaderRecoverer(List list) {
|
||||
super(list);
|
||||
}
|
||||
/**
|
||||
* Do nothing. Subclassses should override to implement recovery behaviour.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProvider#recover(java.lang.Object,
|
||||
* @see org.springframework.batch.item.ItemReader#recover(java.lang.Object,
|
||||
* Throwable)
|
||||
*
|
||||
* @return false if nothing can be done (the default), or true if the item
|
||||
@@ -23,8 +23,8 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.exception.RetryException;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.retry.exception.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.policy.NeverRetryPolicy;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
|
||||
public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public class ItemReaderRetryCallbackTests extends TestCase {
|
||||
|
||||
List calls = new ArrayList();
|
||||
|
||||
@@ -40,14 +40,14 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
|
||||
RetryTemplate template;
|
||||
|
||||
ListItemProvider provider;
|
||||
ListItemReader provider;
|
||||
|
||||
ItemProviderRetryCallback callback;
|
||||
ItemReaderRetryCallback callback;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
template = new RetryTemplate();
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
provider = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
calls.add(data);
|
||||
@@ -57,7 +57,7 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
return "key" + (count++);
|
||||
}
|
||||
};
|
||||
callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
if (data.equals("bar")) {
|
||||
@@ -73,8 +73,8 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDataExhausted() throws Exception {
|
||||
provider.next();
|
||||
provider.next(); // line up a null data item...
|
||||
provider.read();
|
||||
provider.read(); // line up a null data item...
|
||||
|
||||
try {
|
||||
template.execute(callback);
|
||||
@@ -90,12 +90,12 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public void testContextInitializedWithItemAndCanRetry() throws Exception {
|
||||
// We can use the policy to intercept the context and do something with
|
||||
// the item...
|
||||
provider.next(); // line up an unsuccessful call...
|
||||
provider.read(); // line up an unsuccessful call...
|
||||
assertEquals(0, calls.size());
|
||||
template.setRetryPolicy(new NeverRetryPolicy() {
|
||||
public boolean canRetry(RetryContext context) {
|
||||
// ...register the failed item
|
||||
calls.add("item(" + count + ")=" + context.getAttribute(ItemProviderRetryCallback.ITEM));
|
||||
calls.add("item(" + count + ")=" + context.getAttribute(ItemReaderRetryCallback.ITEM));
|
||||
// Do not call the base class method - the attempt counts as
|
||||
// successful now
|
||||
if (count < 2) // only retry once
|
||||
@@ -121,12 +121,12 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public void testContextInitializedWithItemAndRegisterThrowable() throws Exception {
|
||||
// We can use the policy to intercept the context and do something with
|
||||
// the item...
|
||||
provider.next(); // line up an unsuccessful call...
|
||||
provider.read(); // line up an unsuccessful call...
|
||||
assertEquals(0, calls.size());
|
||||
template.setRetryPolicy(new NeverRetryPolicy() {
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
// ...register the failed item
|
||||
calls.add("item=" + context.getAttribute(ItemProviderRetryCallback.ITEM));
|
||||
calls.add("item=" + context.getAttribute(ItemReaderRetryCallback.ITEM));
|
||||
// Call the base class method so that the next attempt is a
|
||||
// failure.
|
||||
super.registerThrowable(context, throwable);
|
||||
@@ -25,23 +25,23 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.FailedItemIdentifier;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
|
||||
public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
|
||||
private ItemProviderRetryPolicy policy = new ItemProviderRetryPolicy();
|
||||
private ItemReaderRetryPolicy policy = new ItemReaderRetryPolicy();
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
super.setUp();
|
||||
// The list simulates a failed delivery, redelivery of the same message,
|
||||
// then a new message...
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
provider = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -61,7 +61,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOpenSunnyDay() throws Exception {
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -71,8 +71,8 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// we haven't called the processor yet...
|
||||
assertEquals(0, count);
|
||||
// but the provider has been accessed:
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testOpenWithWrongCallbackType() {
|
||||
@@ -92,7 +92,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
public void testCanRetry() {
|
||||
policy.setDelegate(new AlwaysRetryPolicy());
|
||||
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testRegisterThrowable() {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -118,7 +118,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testClose() throws Exception {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -132,12 +132,12 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// (not that this would happen in practice)...
|
||||
assertFalse(policy.canRetry(context));
|
||||
// The provider has been accessed only once:
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testOpenTwice() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -162,13 +162,13 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// The provider has been accessed twice, so this
|
||||
// mimics a message receive by repeating the value of the first
|
||||
// message...
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testRecover() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
}
|
||||
});
|
||||
@@ -196,18 +196,18 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testFailedItemIdentifier() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
MockFailedItemProvider provider = new MockFailedItemProvider(Collections.EMPTY_LIST);
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, null);
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, null);
|
||||
policy.open(callback);
|
||||
assertEquals(1, provider.hasFailedCount);
|
||||
}
|
||||
|
||||
public void testRecoverWithTemplate() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExhaustedClearsHistoryAfterLastAttempt() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -256,9 +256,9 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRetryCount() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -273,14 +273,14 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRetryCountPreservedBetweenRetries() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
});
|
||||
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
RetryContext context = policy.open(callback);
|
||||
assertNotNull(context);
|
||||
@@ -299,7 +299,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
assertTrue(policy.hasFailed(provider, "foo"));
|
||||
}
|
||||
|
||||
private static class MockFailedItemProvider extends ListItemProvider implements FailedItemIdentifier {
|
||||
private static class MockFailedItemProvider extends ListItemReader implements FailedItemIdentifier {
|
||||
|
||||
private int hasFailedCount = 0;
|
||||
|
||||
@@ -8,16 +8,16 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractDelegator}
|
||||
* Tests for {@link AbstractMethodInvokingDelegator}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class AbstractDelegatorTests extends TestCase {
|
||||
|
||||
private static class ConcreteDelegator extends AbstractDelegator {
|
||||
private static class ConcreteDelegator extends AbstractMethodInvokingDelegator {
|
||||
}
|
||||
|
||||
private AbstractDelegator delegator = new ConcreteDelegator();
|
||||
private AbstractMethodInvokingDelegator delegator = new ConcreteDelegator();
|
||||
|
||||
private Foo foo = new Foo(0, "foo", 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user