Java Reference
In-Depth Information
Testing a Step
Jobs are broken into steps. This topic has established that. Each step is an independent piece of
functionality that can be executed with minimal impact on other steps. Because of the inherent
decoupling of steps with a batch job, steps become prime candidates for testing. In this section, you look
at how to test a Spring Batch step in its entirety.
In the step scope-based examples in the previous section, you tested the ItemReader of a job that
reads in a file and writes out the exact same file. This single-step job is the job you use now to
demonstrate how to test the execution of a single step in Spring Batch. To begin, let's look at the
configuration for the job; Listing 12-17 has the XML for the entire carJob .
Listing 12-17. carJob.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=" http://www.springframework.org/schema/batch"
xmlns:beans=" http://www.springframework.org/schema/beans"
xmlns:util=" 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-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:bean id="carFileReader"
class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<beans:property name="resource" value="#{jobParameters[carFile]}"/>
<beans:property name="lineMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.PassThroughLineMapper"/>
</beans:property>
</beans:bean>
<beans:bean id="carFileWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<beans:property name="resource" value="#{jobParameters[outputFile]}"/>
<beans:property name="lineAggregator">
<beans:bean
class="org.springframework.batch.item.file.transform.PassThroughLineAggregator"/>
</beans:property>
</beans:bean>
<job id="carJob">
<step id="carProcessingStep">
<tasklet>
<chunk reader="carFileReader" writer="carFileWriter" commit-interval="10"/>
</tasklet>
</step>
</job>
</beans:beans>
 
Search WWH ::




Custom Search