Java Reference
In-Depth Information
@Test
public void testCarProcessingStep() throws Exception {
assertEquals(BatchStatus.COMPLETED,
jobLauncherUtils.launchStep("carProcessingStep", getParams())
.getStatus());
assertFileEquals(new ClassPathResource(INPUT_FILE),
new FileSystemResource(OUTPUT_FILE));
}
private JobParameters getParams() {
return new JobParametersBuilder().addString("carFile", INPUT_FILE)
.addString("outputFile", "file:/" + OUTPUT_FILE)
.toJobParameters();
}
}
As mentioned, the structure of this test should be familiar. It's the same as you've used for the past
few tests. However, a few aspects are interesting for this test. First is the bean jobLauncherUtils . This is
the utility class mentioned earlier. Spring autowires it into your test and autowires its own dependencies
to things like a datasource as well as a job launcher. Because of JobLauncherTestUtils ' need to be
autowired, you need to be sure to add it to your test-context.xml file. Listing 12-19 shows the contents
of the test-context.xml file for this test.
Listing 12-19. test-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=" http://www.springframework.org/schema/context"
xmlns:util=" http://www.springframework.org/schema/beans"
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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<import resource="launch-context.xml"/>
<import resource="jobs/carJob.xml"/>
<bean id="placeholderProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:test-batch.properties" />
<property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>
<bean id="jobLauncherUtils" class="org.springframework.batch.test.JobLauncherTestUtils"/>
 
Search WWH ::




Custom Search