IN PROGRESS - BATCH-971: add database writers to iosample
added processing phase to iosample included jdbcBatch and hibernate into iosample and removed the redundant original samples
This commit is contained in:
@@ -18,14 +18,12 @@
|
||||
<config>src/main/resources/jobs/adhocLoopJob.xml</config>
|
||||
<config>src/main/resources/jobs/infiniteLoopJob.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/hibernateJob.xml</config>
|
||||
<config>src/main/resources/jobs/ibatisJob.xml</config>
|
||||
<config>src/main/resources/jobs/footballJob.xml</config>
|
||||
<config>src/main/resources/jobs/delegatingJob.xml</config>
|
||||
<config>src/main/resources/jobs/parallelJob.xml</config>
|
||||
<config>src/main/resources/jobs/retrySample.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/jobs/batchUpdateJob.xml</config>
|
||||
<config>src/main/resources/adhoc-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/alt-data-source-context.xml</config>
|
||||
<config>src/main/resources/quartz-job-launcher-context.xml</config>
|
||||
@@ -49,6 +47,7 @@
|
||||
<config>src/main/resources/jobs/iosample/multiRecordType.xml</config>
|
||||
<config>src/main/resources/jobs/iosample/multiResource.xml</config>
|
||||
<config>src/main/resources/jobs/iosample/xml.xml</config>
|
||||
<config>src/main/resources/jobs/iosample/hibernate.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
@@ -205,7 +204,6 @@
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/data-source-context-init.xml</config>
|
||||
<config>src/main/resources/jobs/batchUpdateJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
</configs>
|
||||
@@ -289,7 +287,6 @@
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/main/resources/jobs/hibernateJob.xml</config>
|
||||
<config>src/main/resources/simple-job-launcher-context.xml</config>
|
||||
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
|
||||
<config>src/main/resources/hibernate-context.xml</config>
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
*/
|
||||
public class CustomerCreditIncreaseProcessor implements ItemProcessor<CustomerCredit, CustomerCredit> {
|
||||
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal("1000");
|
||||
public static final BigDecimal FIXED_AMOUNT = new BigDecimal("5");
|
||||
|
||||
public CustomerCredit process(CustomerCredit item) throws Exception {
|
||||
return item.increaseCreditBy(FIXED_AMOUNT);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
UK21341EAH45,978,98.34,customer1
|
||||
UK21341EAH46,112,18.12,customer2
|
||||
UK21341EAH47,245,12.78,customer3
|
||||
UK21341EAH48,108,109.25,customer4
|
||||
UK21341EAH49,854,123.39,customer5
|
||||
UK21341EAH50,234,32.45,customer6
|
||||
customer1,10
|
||||
customer2,20
|
||||
customer3,30
|
||||
customer4,40
|
||||
customer5,50
|
||||
customer6,60
|
||||
|
@@ -1,2 +1,2 @@
|
||||
UK21341EAH51,643,594.23,customer7
|
||||
UK21341EAH52,393,65.21,customer8
|
||||
customer7,70
|
||||
customer8,80
|
||||
|
@@ -1,6 +1,6 @@
|
||||
UK21341EAH45978 98.34customer1
|
||||
UK21341EAH46112 18.12customer2
|
||||
UK21341EAH47245 12.78customer3
|
||||
UK21341EAH48108109.25customer4
|
||||
UK21341EAH49854123.39customer5
|
||||
UK21341EAH50234 32.45customer6
|
||||
customer110
|
||||
customer220
|
||||
customer330
|
||||
customer440
|
||||
customer550
|
||||
customer660
|
||||
@@ -1,39 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<trades>
|
||||
<trade>
|
||||
<isin>UK21341EAH45</isin>
|
||||
<quantity>978</quantity>
|
||||
<price>98.34</price>
|
||||
<customer>customer1</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>UK21341EAH46</isin>
|
||||
<quantity>112</quantity>
|
||||
<price>18.12</price>
|
||||
<customer>customer2</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>UK21341EAH47</isin>
|
||||
<quantity>245</quantity>
|
||||
<price>12.78</price>
|
||||
<customer>customer3</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>UK21341EAH48</isin>
|
||||
<quantity>108</quantity>
|
||||
<price>109.25</price>
|
||||
<customer>customer4</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>UK21341EAH49</isin>
|
||||
<quantity>854</quantity>
|
||||
<price>123.39</price>
|
||||
<customer>customer5</customer>
|
||||
</trade>
|
||||
<trade>
|
||||
<isin>UK21341EAH50</isin>
|
||||
<quantity>234</quantity>
|
||||
<price>32.45</price>
|
||||
<customer>customer6</customer>
|
||||
</trade>
|
||||
</trades>
|
||||
<customers>
|
||||
<customer>
|
||||
<name>customer1</name>
|
||||
<credit>10</credit>
|
||||
</customer>
|
||||
<customer>
|
||||
<name>customer2</name>
|
||||
<credit>20</credit>
|
||||
</customer>
|
||||
<customer>
|
||||
<name>customer3</name>
|
||||
<credit>30</credit>
|
||||
</customer>
|
||||
<customer>
|
||||
<name>customer4</name>
|
||||
<credit>40</credit>
|
||||
</customer>
|
||||
<customer>
|
||||
<name>customer5</name>
|
||||
<credit>50</credit>
|
||||
</customer>
|
||||
</customers>
|
||||
@@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<description>Example for SQL Batch Update integration.</description>
|
||||
|
||||
<bean id="batchUpdateJob" parent="simpleJob">
|
||||
<!-- set restartable=false so that this job can be used by more than one test -->
|
||||
<property name="restartable" value="false" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="skipLimitStep">
|
||||
<property name="skipLimit" value="5" />
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="commitInterval" value="3" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="sql">
|
||||
<util:constant static-field="org.springframework.batch.sample.domain.trade.internal.CustomerCreditUpdatePreparedStatementSetter.QUERY"/>
|
||||
</property>
|
||||
<property name="itemPreparedStatementSetter">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditUpdatePreparedStatementSetter" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="sql" value="SELECT id, name, credit FROM customer " />
|
||||
<property name="mapper">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditRowMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -17,6 +17,9 @@
|
||||
<property name="commitInterval" value="2"/>
|
||||
<property name="itemReader" ref="itemReader"/>
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="itemProcessor">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -18,27 +18,34 @@
|
||||
<property name="lineTokenizer">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value=","/>
|
||||
<property name="names" value="name,credit" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="fieldSetMapper">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper"/>
|
||||
<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="targetType" value="org.springframework.batch.sample.domain.trade.CustomerCredit" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/delimitedOutput.csv" />
|
||||
<property name="resource" ref="outputResource" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
|
||||
<property name="delimiter" value=","/>
|
||||
<property name="fieldExtractor">
|
||||
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="isin,quantity,price,customer"/>
|
||||
<property name="names" value="name,credit"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg value="target/test-outputs/delimitedOutput.csv" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
@@ -16,29 +14,41 @@
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
<bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="columns" value="1-12,13-15,16-21,22-30"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="name,credit" />
|
||||
<property name="columns" value="1-9,10-11" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="fieldSetMapper">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="targetType"
|
||||
value="org.springframework.batch.sample.domain.trade.CustomerCredit" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/fixedLengthOutput.txt" />
|
||||
<property name="resource" ref="outputResource" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<property name="fieldExtractor">
|
||||
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="isin,quantity,price,customer"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="name,credit" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="format" value="%-12s%-3d%6s%-9s"/>
|
||||
<property name="format" value="%-9s%-2.0f" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg value="target/test-outputs/fixedLengthOutput.txt" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="itemReader"
|
||||
class="org.springframework.batch.item.database.HibernateCursorItemReader">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
<property name="queryString" value="from CustomerCredit" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter"
|
||||
class="org.springframework.batch.item.database.HibernateItemWriter">
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -19,16 +19,13 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.sample.iosample.internal.TradeCustomerItemWriter">
|
||||
<property name="dao">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.JdbcTradeDao" p:dataSource-ref="dataSource">
|
||||
<property name="incrementer">
|
||||
<bean parent="incrementerParent">
|
||||
<property name="incrementerName" value="TRADE_SEQ" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
|
||||
<property name="assertUpdates" value="true" />
|
||||
<property name="itemSqlParameterSourceProvider">
|
||||
<bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
|
||||
</property>
|
||||
<property name="sql" value="UPDATE customer set credit = :credit where id = :id" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,27 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<bean id="itemReader" class="org.springframework.batch.sample.iosample.internal.MultiLineTradeItemReader">
|
||||
|
||||
<bean id="multiLineJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemReader"
|
||||
class="org.springframework.batch.sample.iosample.internal.MultiLineTradeItemReader">
|
||||
<property name="delegate">
|
||||
<bean class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="resource" value="data/iosample/input/multiLine.txt" />
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer" />
|
||||
</property>
|
||||
<property name="fieldSetMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
@@ -29,12 +41,15 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.sample.iosample.internal.MultiLineTradeItemWriter">
|
||||
<bean id="itemWriter"
|
||||
class="org.springframework.batch.sample.iosample.internal.MultiLineTradeItemWriter">
|
||||
<property name="delegate">
|
||||
<bean class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/multiLineOutput.txt" />
|
||||
<property name="resource"
|
||||
value="file:target/test-outputs/multiLineOutput.txt" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
@@ -11,17 +9,28 @@
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="resource" value="data/iosample/input/multiRecordType.txt" />
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer" ref="compositeLineTokenizer"/>
|
||||
<property name="fieldSetMapper" ref="compositeFieldSetMapper"/>
|
||||
<bean id="multiRecordJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="compositeLineTokenizer" class="org.springframework.batch.item.file.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="resource" value="data/iosample/input/multiRecordType.txt" />
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer" ref="compositeLineTokenizer" />
|
||||
<property name="fieldSetMapper" ref="compositeFieldSetMapper" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="compositeLineTokenizer"
|
||||
class="org.springframework.batch.item.file.transform.PrefixMatchingCompositeLineTokenizer">
|
||||
<property name="tokenizers">
|
||||
<map>
|
||||
<entry key="TRAD" value-ref="tradeLineTokenizer" />
|
||||
@@ -30,17 +39,20 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeLineTokenizer" class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="isin,quantity,price,customer,prefix"/>
|
||||
<property name="columns" value="5-16,17-19,20-25,26-34,1-4"/>
|
||||
<bean id="tradeLineTokenizer"
|
||||
class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="isin,quantity,price,customer,prefix" />
|
||||
<property name="columns" value="5-16,17-19,20-25,26-34,1-4" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerLineTokenizer" class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="id,name,credit,prefix"/>
|
||||
<property name="columns" value="5-9,10-18,19-26,1-4"/>
|
||||
|
||||
<bean id="customerLineTokenizer"
|
||||
class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
|
||||
<property name="names" value="id,name,credit,prefix" />
|
||||
<property name="columns" value="5-9,10-18,19-26,1-4" />
|
||||
</bean>
|
||||
|
||||
<bean id="compositeFieldSetMapper" class="org.springframework.batch.sample.iosample.internal.PrefixMatchingCompositeFieldSetMapper">
|
||||
|
||||
<bean id="compositeFieldSetMapper"
|
||||
class="org.springframework.batch.sample.iosample.internal.PrefixMatchingCompositeFieldSetMapper">
|
||||
<property name="mappers">
|
||||
<map>
|
||||
<entry key="TRAD" value-ref="tradeFieldSetMapper" />
|
||||
@@ -49,35 +61,43 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeFieldSetMapper" class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper"/>
|
||||
<bean id="customerFieldSetMapper" class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditFieldSetMapper"/>
|
||||
<bean id="tradeFieldSetMapper"
|
||||
class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper" />
|
||||
<bean id="customerFieldSetMapper"
|
||||
class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditFieldSetMapper" />
|
||||
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/multiRecordTypeOutput.txt" />
|
||||
<property name="resource"
|
||||
value="file:target/test-outputs/multiRecordTypeOutput.txt" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.sample.iosample.internal.DelegatingTradeLineAggregator">
|
||||
<property name="tradeLineAggregator" ref="tradeLineAggregator"/>
|
||||
<property name="customerLineAggregator" ref="customerLineAggregator"/>
|
||||
<bean
|
||||
class="org.springframework.batch.sample.iosample.internal.DelegatingTradeLineAggregator">
|
||||
<property name="tradeLineAggregator" ref="tradeLineAggregator" />
|
||||
<property name="customerLineAggregator" ref="customerLineAggregator" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeLineAggregator" class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<bean id="tradeLineAggregator"
|
||||
class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<property name="fieldExtractor">
|
||||
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="isin,quantity,price,customer"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="isin,quantity,price,customer" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="format" value="TRAD%-12s%-3d%6s%-9s"/>
|
||||
<property name="format" value="TRAD%-12s%-3d%6s%-9s" />
|
||||
</bean>
|
||||
|
||||
<bean id="customerLineAggregator" class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<bean id="customerLineAggregator"
|
||||
class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
|
||||
<property name="fieldExtractor">
|
||||
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="id,name,credit"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="id,name,credit" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="format" value="CUST%05d%-9s%08.0f"/>
|
||||
<property name="format" value="CUST%05d%-9s%08.0f" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
@@ -11,39 +9,52 @@
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<bean id="itemReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
|
||||
<bean id="itemReader"
|
||||
class="org.springframework.batch.item.file.MultiResourceItemReader">
|
||||
<property name="resources" value="classpath:data/iosample/input/delimited*.csv" />
|
||||
<property name="delegate" ref="delegateReader" />
|
||||
</bean>
|
||||
|
||||
<bean id="delegateReader" class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="lineMapper">
|
||||
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value=","/>
|
||||
<property name="delegate">
|
||||
<bean class="org.springframework.batch.item.file.FlatFileItemReader">
|
||||
<property name="lineMapper">
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
|
||||
<property name="lineTokenizer">
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
|
||||
<property name="delimiter" value="," />
|
||||
<property name="names" value="name,credit" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="fieldSetMapper">
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
|
||||
<property name="targetType"
|
||||
value="org.springframework.batch.sample.domain.trade.CustomerCredit" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="fieldSetMapper">
|
||||
<bean class="org.springframework.batch.sample.domain.trade.internal.TradeFieldSetMapper"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.file.MultiResourceItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/multiResourceOutput.csv" />
|
||||
<bean id="itemWriter"
|
||||
class="org.springframework.batch.item.file.MultiResourceItemWriter">
|
||||
<property name="resource"
|
||||
value="file:target/test-outputs/multiResourceOutput.csv" />
|
||||
<property name="itemCountLimitPerResource" value="6" />
|
||||
<property name="delegate" ref="delegateWriter"/>
|
||||
<property name="delegate" ref="delegateWriter" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="delegateWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
|
||||
<property name="delimiter" value=","/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
|
||||
<property name="delimiter" value="," />
|
||||
<property name="fieldExtractor">
|
||||
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="isin,quantity,price,customer"/>
|
||||
<bean
|
||||
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
|
||||
<property name="names" value="name,credit" />
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
@@ -12,28 +10,31 @@
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<bean id="itemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
|
||||
<property name="fragmentRootElementName" value="trade" />
|
||||
<property name="fragmentRootElementName" value="customer" />
|
||||
<property name="resource" value="data/iosample/input/input.xml" />
|
||||
<property name="unmarshaller" ref="tradeMarshaller"/>
|
||||
<property name="unmarshaller" ref="customerCreditMarshaller" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
|
||||
<property name="resource" value="file:target/test-outputs/output.xml" />
|
||||
<property name="marshaller" ref="tradeMarshaller" />
|
||||
<property name="rootTagName" value="trades" />
|
||||
<property name="resource" ref="outputResource" />
|
||||
<property name="marshaller" ref="customerCreditMarshaller" />
|
||||
<property name="rootTagName" value="customers" />
|
||||
<property name="overwriteOutput" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="tradeMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
|
||||
<bean id="customerCreditMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
|
||||
<property name="aliases">
|
||||
<util:map id="aliases">
|
||||
<entry key="trade" value="org.springframework.batch.sample.domain.trade.Trade" />
|
||||
<entry key="isin" value="java.lang.String" />
|
||||
<entry key="quantity" value="long" />
|
||||
<entry key="price" value="java.math.BigDecimal" />
|
||||
<entry key="customer" value="java.lang.String" />
|
||||
<entry key="customer"
|
||||
value="org.springframework.batch.sample.domain.trade.CustomerCredit" />
|
||||
<entry key="price" value="java.math.BigDecimal" />
|
||||
<entry key="name" value="java.lang.String" />
|
||||
</util:map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg value="target/test-outputs/output.xml" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Test for HibernateJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class HibernateJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Test for JdbcBatchItemWriterJob - checks that customer credit has been updated to expected value.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class JdbcBatchJobFunctionalTests extends AbstractCustomerCreditIncreaseTests {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Base class for IoSample tests that increase input customer credit by fixed
|
||||
* amount. Assumes inputs and outputs are in the same format and uses the job's
|
||||
* {@link ItemReader} to parse the outputs.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractIoSampleTests extends AbstractJobTests {
|
||||
|
||||
@Autowired
|
||||
private ItemReader<CustomerCredit> reader;
|
||||
|
||||
/**
|
||||
* Check the resulting credits correspond to inputs increased by fixed
|
||||
* amount.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateCredit() throws Exception {
|
||||
|
||||
open(reader);
|
||||
List<CustomerCredit> inputs = getCredits(reader);
|
||||
close(reader);
|
||||
|
||||
JobExecution jobExecution = this.launchJob();
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
|
||||
pointReaderToOutput(reader);
|
||||
open(reader);
|
||||
List<CustomerCredit> outputs = getCredits(reader);
|
||||
close(reader);
|
||||
|
||||
assertEquals(inputs.size(), outputs.size());
|
||||
int itemCount = inputs.size();
|
||||
assertTrue(itemCount > 0);
|
||||
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
assertEquals(inputs.get(i).getCredit().add(CustomerCreditIncreaseProcessor.FIXED_AMOUNT).intValue(),
|
||||
outputs.get(i).getCredit().intValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the reader to read outputs (if necessary). Required for
|
||||
* file-to-file jobs jobs, usually no-op for database jobs where inputs are
|
||||
* updated (rather than outputs created).
|
||||
*/
|
||||
protected abstract void pointReaderToOutput(ItemReader<CustomerCredit> reader);
|
||||
|
||||
/**
|
||||
* Read all credits using the provided reader.
|
||||
*/
|
||||
private List<CustomerCredit> getCredits(ItemReader<CustomerCredit> reader) throws Exception {
|
||||
CustomerCredit credit;
|
||||
List<CustomerCredit> result = new ArrayList<CustomerCredit>();
|
||||
while ((credit = reader.read()) != null) {
|
||||
result.add(credit);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the reader if applicable.
|
||||
*/
|
||||
private void open(ItemReader<?> reader) {
|
||||
if (reader instanceof ItemStream) {
|
||||
((ItemStream) reader).open(new ExecutionContext());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the reader if applicable.
|
||||
*/
|
||||
private void close(ItemReader<?> reader) {
|
||||
if (reader instanceof ItemStream) {
|
||||
((ItemStream) reader).close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.FlatFileItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -31,17 +32,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/delimited.xml" })
|
||||
public class DelimitedFunctionalTests extends AbstractJobTests {
|
||||
public class DelimitedFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/delimitedOutput.csv";
|
||||
private static final String INPUT_FILE = "src/main/resources/data/iosample/input/delimited.csv";
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.launchJob();
|
||||
AssertFile.assertFileEquals(new FileSystemResource(OUTPUT_FILE), new FileSystemResource(INPUT_FILE));
|
||||
@Autowired
|
||||
private Resource outputResource;
|
||||
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
FlatFileItemReader<CustomerCredit> fileReader = (FlatFileItemReader<CustomerCredit>) reader;
|
||||
fileReader.setResource(outputResource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,28 +16,26 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.FlatFileItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/fixedLength.xml" })
|
||||
public class FixedLengthFunctionalTests extends AbstractJobTests {
|
||||
public class FixedLengthFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/fixedLengthOutput.txt";
|
||||
private static final String INPUT_FILE = "src/main/resources/data/iosample/input/fixedLength.txt";
|
||||
@Autowired
|
||||
private Resource outputResource;
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.launchJob();
|
||||
AssertFile.assertFileEquals(new FileSystemResource(OUTPUT_FILE), new FileSystemResource(INPUT_FILE));
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
FlatFileItemReader<?> fileReader = (FlatFileItemReader<?>) reader;
|
||||
fileReader.setResource(outputResource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/hibernate-context.xml",
|
||||
"/jobs/ioSampleJob.xml", "/jobs/iosample/hibernate.xml" })
|
||||
public class HibernateFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,18 +16,11 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
@@ -36,28 +29,11 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/jdbcCursor.xml" })
|
||||
public class JdbcCursorFunctionalTests extends AbstractJobTests {
|
||||
public class JdbcCursorFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.simpleJdbcTemplate.update("delete from TRADE");
|
||||
|
||||
this.launchJob();
|
||||
|
||||
assertEquals(4, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "TRADE"));
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String sql = "select count(*) from TRADE where CUSTOMER = ?";
|
||||
assertEquals(1, simpleJdbcTemplate.queryForInt(sql, "customer" + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @since 2.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/multiLine.xml" })
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiLine.xml" })
|
||||
public class MultiLineFunctionalTests extends AbstractJobTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/multiLineOutput.txt";
|
||||
|
||||
private static final String INPUT_FILE = "src/main/resources/data/iosample/input/multiLine.txt";
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @since 2.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/multiRecordType.xml" })
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/iosample/multiRecordType.xml" })
|
||||
public class MultiRecordTypeFunctionalTests extends AbstractJobTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/multiRecordTypeOutput.txt";
|
||||
|
||||
private static final String INPUT_FILE = "src/main/resources/data/iosample/input/multiRecordType.txt";
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.MultiResourceItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -31,18 +32,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/multiResource.xml" })
|
||||
public class MultiResourceFunctionalTests extends AbstractJobTests {
|
||||
public class MultiResourceFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.launchJob();
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
MultiResourceItemReader<?> multiReader = (MultiResourceItemReader<?>) reader;
|
||||
multiReader.setResources(new Resource[] {
|
||||
new FileSystemResource("target/test-outputs/multiResourceOutput.csv.1"),
|
||||
new FileSystemResource("target/test-outputs/multiResourceOutput.csv.2") });
|
||||
|
||||
AssertFile.assertFileEquals(new FileSystemResource("target/test-outputs/multiResourceOutput.csv.1"),
|
||||
new FileSystemResource("src/main/resources/data/iosample/input/delimited.csv"));
|
||||
AssertFile.assertFileEquals(new FileSystemResource("target/test-outputs/multiResourceOutput.csv.2"),
|
||||
new FileSystemResource("src/main/resources/data/iosample/input/delimited2.csv"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLAssert;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.xml.StaxEventItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -33,18 +32,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
|
||||
"/jobs/iosample/xml.xml" })
|
||||
public class XmlFunctionalTests extends AbstractJobTests {
|
||||
public class XmlFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
private static final String OUTPUT_FILE = "target/test-outputs/output.xml";
|
||||
private static final String INPUT_FILE = "src/main/resources/data/iosample/input/input.xml";
|
||||
|
||||
/**
|
||||
* Output should be the same as input
|
||||
*/
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
this.launchJob();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
XMLAssert.assertXMLEqual(new FileReader(INPUT_FILE), new FileReader(OUTPUT_FILE));
|
||||
@Autowired
|
||||
private Resource outputResource;
|
||||
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
StaxEventItemReader<?> xmlReader = (StaxEventItemReader<?>) reader;
|
||||
xmlReader.setResource(outputResource);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:/hibernate-context.xml" />
|
||||
<import resource="classpath:/jobs/hibernateJob.xml" />
|
||||
|
||||
</beans>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:/jobs/batchUpdateJob.xml" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user