Configuring the Testing Environment
To isolate your test execution from external resource requirements (specific database servers, and so
on), you should configure a couple of things. Specifically, you should use a test configuration for your
database that creates an instance of HSQLDB for you in memory. To do that, you need to do the
Update your POM file to include the HSQLDB database drivers.
Refactor the inclusion of Spring context files to allow for easier overriding of
configurations for testing.
3. Configure test-specific properties.
Let's get started by adding the HSQLDB drivers to your POM file. 5 The specific dependency you need
to add is shown in Listing 12-8.
Listing 12-8. HSQLDB's Database Driver Dependency
The next step is to do a bit of refactoring. Up to this point, you've structured your Spring
configuration files in a way that works great for batch jobs. You've put common components in the
launch-context.xml file and had a job-specific XML file for each job after that. However, you run into an
issue here: you currently have the properties hard-coded in launch-context.xml to be batch.properties ,
which is configured for MySQL.
To make this more flexible, you restructure the XML files so that there are three instead of two. The
first is the normal launch-context.xml file without the placeholderProperties bean. The second is the
normal statementJob.xml file without the import statement for the launch-context.xml file. The new file
you create joins the three and configures the properties file location. Listing 12-9 shows the contents of
the new configuration file, job-context.xml .
Listing 12-9. job-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans"
5 For the record, if you're using the POM file that comes with the Spring Batch CLI Archetype, you don't
need to do this—the drivers are already included for Spring Batch's own testing. However, because
you've used MySQL for all examples thus far, you may need to add them back.