BATCH-1344: added JobRunnerTestUtils and deprecated the old AbstractJobTests
This commit is contained in:
@@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -36,7 +35,6 @@ import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -66,16 +64,6 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
|
||||
private static boolean initialized = false;
|
||||
|
||||
/**
|
||||
* Main method as convenient entry point.
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(DataSourceInitializer.class,
|
||||
DataSourceInitializer.class.getSimpleName() + "-context.xml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
* @see java.lang.Object#finalize()
|
||||
|
||||
@@ -24,18 +24,21 @@ import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.test.AbstractJobTests;
|
||||
import org.springframework.batch.test.JobRunnerTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration(locations = { "/launch-context.xml" })
|
||||
@ContextConfiguration(locations = { "/test-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ExampleJobConfigurationTests extends AbstractJobTests {
|
||||
public class ExampleJobConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
private JobOperator jobOperator;
|
||||
|
||||
@Autowired
|
||||
private JobRunnerTestUtils jobRunnerUtils;
|
||||
|
||||
/**
|
||||
* Create a unique job instance and check it's execution completes
|
||||
* successfully - uses the convenience methods provided by the testing
|
||||
@@ -44,7 +47,7 @@ public class ExampleJobConfigurationTests extends AbstractJobTests {
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
JobExecution jobExecution = launchJob(getUniqueJobParameters());
|
||||
JobExecution jobExecution = jobRunnerUtils.launchJob(jobRunnerUtils.getUniqueJobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
}
|
||||
|
||||
@@ -56,7 +59,7 @@ public class ExampleJobConfigurationTests extends AbstractJobTests {
|
||||
public void testLaunchByJobOperator() throws Exception {
|
||||
|
||||
// assumes the job has a JobIncrementer set
|
||||
long jobExecutionId = jobOperator.startNextInstance(getJob().getName());
|
||||
long jobExecutionId = jobOperator.startNextInstance(jobRunnerUtils.getJob().getName());
|
||||
|
||||
// no need to wait for job completion in this case, the job is launched
|
||||
// synchronously
|
||||
|
||||
13
archetypes/simple-cli/src/test/resources/test-context.xml
Normal file
13
archetypes/simple-cli/src/test/resources/test-context.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?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.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<import resource="classpath*:/launch-context.xml"/>
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<bean class="org.springframework.batch.test.JobRunnerTestUtils"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user