BATCH-1344: added JobRunnerTestUtils and deprecated the old AbstractJobTests
This commit is contained in:
@@ -12,6 +12,7 @@ import org.springframework.batch.test.sample.SampleTasklet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* This is an abstract test class to be used by test classes to test the
|
||||
@@ -20,10 +21,14 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractSampleJobTests extends AbstractJobTests {
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml" })
|
||||
public abstract class AbstractSampleJobTests {
|
||||
|
||||
private SimpleJdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private JobRunnerTestUtils jobRunnerUtils;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("tasklet2")
|
||||
private SampleTasklet tasklet2;
|
||||
@@ -46,25 +51,25 @@ public abstract class AbstractSampleJobTests extends AbstractJobTests {
|
||||
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
assertEquals(BatchStatus.COMPLETED, this.launchJob().getStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jobRunnerUtils.launchJob().getStatus());
|
||||
this.verifyTasklet(1);
|
||||
this.verifyTasklet(2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testNonExistentStep() {
|
||||
launchStep("nonExistent");
|
||||
jobRunnerUtils.launchStep("nonExistent");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStep1Execution() {
|
||||
assertEquals(BatchStatus.COMPLETED, this.launchStep("step1").getStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jobRunnerUtils.launchStep("step1").getStatus());
|
||||
this.verifyTasklet(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStep2Execution() {
|
||||
assertEquals(BatchStatus.COMPLETED, this.launchStep("step2").getStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jobRunnerUtils.launchStep("step2").getStatus());
|
||||
this.verifyTasklet(2);
|
||||
}
|
||||
|
||||
@@ -72,7 +77,7 @@ public abstract class AbstractSampleJobTests extends AbstractJobTests {
|
||||
public void testStepLaunchJobContextEntry() {
|
||||
ExecutionContext jobContext = new ExecutionContext();
|
||||
jobContext.put("key1", "value1");
|
||||
assertEquals(BatchStatus.COMPLETED, this.launchStep("step2", jobContext).getStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jobRunnerUtils.launchStep("step2", jobContext).getStatus());
|
||||
this.verifyTasklet(2);
|
||||
assertTrue(tasklet2.jobContextEntryFound);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* This class will specifically test the capabilities of
|
||||
* {@link AbstractSampleJobTests} to test {@link FlowJob}s.
|
||||
* {@link JobRepositoryTestUtils} to test {@link FlowJob}s.
|
||||
*
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/sampleFlowJob.xml" })
|
||||
@ContextConfiguration(locations = "/jobs/sampleFlowJob.xml")
|
||||
public class SampleFlowJobTests extends AbstractSampleJobTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* This class will specifically test the capabilities of
|
||||
* {@link AbstractSampleJobTests} to test {@link SimpleJob}s.
|
||||
* {@link JobRepositoryTestUtils} to test {@link SimpleJob}s.
|
||||
*
|
||||
* @author Dan Garrette
|
||||
* @since 2.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/sampleSimpleJob.xml" })
|
||||
@ContextConfiguration(locations = "/jobs/sampleSimpleJob.xml")
|
||||
public class SampleSimpleJobTests extends AbstractSampleJobTests {
|
||||
|
||||
|
||||
}
|
||||
|
||||
10
spring-batch-test/src/test/resources/job-runner-context.xml
Normal file
10
spring-batch-test/src/test/resources/job-runner-context.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
<bean class="org.springframework.batch.test.JobRunnerTestUtils"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user