diff --git a/spring-batch-samples/.settings/jobLauncher.launch b/spring-batch-samples/.settings/jobLauncher.launch
index d491336bb..cdfee2933 100644
--- a/spring-batch-samples/.settings/jobLauncher.launch
+++ b/spring-batch-samples/.settings/jobLauncher.launch
@@ -1,15 +1,15 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-batch-samples/src/main/resources/data-source-context.xml b/spring-batch-samples/src/main/resources/data-source-context.xml
index 2fd9997ee..452da172a 100644
--- a/spring-batch-samples/src/main/resources/data-source-context.xml
+++ b/spring-batch-samples/src/main/resources/data-source-context.xml
@@ -37,7 +37,7 @@
-
@@ -50,7 +50,7 @@
-
-
+
@@ -19,7 +19,7 @@
-
+
@@ -37,13 +37,10 @@
-
+
-
-
-
-
+
@@ -75,11 +72,17 @@
-
+
+
+
+
+
+
diff --git a/spring-batch-samples/src/main/resources/jobs/footballJob.xml b/spring-batch-samples/src/main/resources/jobs/footballJob.xml
index 30d23d09c..415f85f9f 100644
--- a/spring-batch-samples/src/main/resources/jobs/footballJob.xml
+++ b/spring-batch-samples/src/main/resources/jobs/footballJob.xml
@@ -167,7 +167,7 @@
-
diff --git a/spring-batch-samples/src/main/resources/simple-container-definition.xml b/spring-batch-samples/src/main/resources/simple-container-definition.xml
index ecf960aa8..e555cd3e0 100644
--- a/spring-batch-samples/src/main/resources/simple-container-definition.xml
+++ b/spring-batch-samples/src/main/resources/simple-container-definition.xml
@@ -15,7 +15,7 @@
-
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
index 126f7a23d..79e8adec8 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AbstractCustomerCreditIncreaseTests.java
@@ -6,6 +6,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import org.hibernate.SessionFactory;
import org.springframework.batch.sample.item.processor.CustomerCreditIncreaseProcessor;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
@@ -28,6 +29,13 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
protected PlatformTransactionManager transactionManager;
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
+
+ private static String[] customers = { "INSERT INTO customer (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
+ "INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
+ "INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
+ "INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
+
+ private static String DELETE_CUSTOMERS = "DELETE FROM customer";
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
@@ -36,6 +44,8 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
protected static final String ID_COLUMN = "ID";
private List creditsBeforeUpdate;
+
+ private SessionFactory sessionFactory;
/**
* @param jdbcTemplate
@@ -44,6 +54,10 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
this.jdbcTemplate = jdbcTemplate;
}
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
/**
* Public setter for the PlatformTransactionManager.
* @param transactionManager the transactionManager to set
@@ -57,8 +71,10 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
*/
protected void validatePreConditions() throws Exception {
super.validatePreConditions();
+ ensureState();
creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
+
return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getBigDecimal(CREDIT_COLUMN);
@@ -68,6 +84,24 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
});
}
+ /*
+ * Ensure the state of the database is accurate by delete all the contents of the
+ * customer table and reading the expected defaults.
+ */
+ private void ensureState(){
+ new TransactionTemplate(transactionManager).execute(new TransactionCallback(){
+
+ public Object doInTransaction(TransactionStatus status) {
+ jdbcTemplate.update(DELETE_CUSTOMERS);
+ for(int i = 0; i < customers.length;i++){
+ jdbcTemplate.update(customers[i]);
+ }
+ return null;
+ }
+ });
+
+ }
+
/**
* Credit was increased by CREDIT_INCREASE
*/
@@ -94,8 +128,7 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
});
assertEquals(getExpectedMatches(), matches.size());
- checkMatches(matches);
-
+ checkMatches(matches);
}
/**
diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java
index 80894affb..8f9cf03aa 100644
--- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java
+++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/FixedLengthImportJobFunctionalTests.java
@@ -21,8 +21,14 @@ import java.io.FileReader;
import java.sql.ResultSet;
import java.sql.SQLException;
+import org.springframework.batch.io.file.DefaultFlatFileItemReader;
+import org.springframework.batch.io.file.mapping.FieldSetMapper;
+import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.sample.domain.Trade;
+import org.springframework.batch.sample.mapping.TradeFieldSetMapper;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowCallbackHandler;
@@ -35,11 +41,17 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
//auto-injected attributes
private JdbcOperations jdbcTemplate;
private Resource fileLocator;
- private ItemReader inputSource;
+ private DefaultFlatFileItemReader inputSource;
+ private LineTokenizer lineTokenizer;
protected void onSetUp() throws Exception {
super.onSetUp();
jdbcTemplate.update("delete from TRADE");
+ fileLocator = new ClassPathResource("data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt");
+ inputSource = new DefaultFlatFileItemReader();
+ inputSource.setFieldSetMapper(new TradeFieldSetMapper());
+ inputSource.setTokenizer(lineTokenizer);
+ inputSource.setResource(fileLocator);
}
protected String[] getConfigLocations() {
@@ -89,12 +101,9 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
-
- public void setFileLocator(Resource fileLocator) {
- this.fileLocator = fileLocator;
+
+ public void setLineTokenizer(LineTokenizer lineTokenizer) {
+ this.lineTokenizer = lineTokenizer;
}
- public void setItemReader(ItemReader inputSource){
- this.inputSource = inputSource;
- }
}