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=""
<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 id="carFileWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<beans:property name="resource" value="#{jobParameters[outputFile]}"/>
<beans:property name="lineAggregator">
<job id="carJob">
<step id="carProcessingStep">
<chunk reader="carFileReader" writer="carFileWriter" commit-interval="10"/>
Search WWH ::

Custom Search