Package org.springframework.batch.test
Class JobRepositoryTestUtils
- java.lang.Object
- org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
- org.springframework.batch.test.JobRepositoryTestUtils
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
public class JobRepositoryTestUtils extends AbstractJdbcBatchMetadataDao implements org.springframework.beans.factory.InitializingBean
Convenience class for creating and removingJobExecution
instances from a database. Typical usage in test case would be to create instances before a transaction, save the result, and then use it to remove them after the transaction.- Author:
- Dave Syer, Mahmoud Ben Hassine
Field Summary
Fields inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
DEFAULT_EXIT_MESSAGE_LENGTH, DEFAULT_TABLE_PREFIX
Constructor Summary
Constructors Constructor Description JobRepositoryTestUtils()
Default constructor.JobRepositoryTestUtils(JobRepository jobRepository, javax.sql.DataSource dataSource)
Create aJobRepositoryTestUtils
with all its mandatory properties.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
java.util.List<JobExecution>
createJobExecutions(int count)
Use theJobRepository
to create someJobExecution
instances each with a single step execution.java.util.List<JobExecution>
createJobExecutions(java.lang.String jobName, java.lang.String[] stepNames, int count)
Use theJobRepository
to create someJobExecution
instances each with the given job name and each having step executions with the given step names.void
removeJobExecutions()
Remove all theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.void
removeJobExecutions(java.util.Collection<JobExecution> list)
Remove theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.void
setDataSource(javax.sql.DataSource dataSource)
void
setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
void
setJobRepository(JobRepository jobRepository)
Methods inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
getClobTypeToUse, getJdbcTemplate, getQuery, getTablePrefix, setClobTypeToUse, setJdbcTemplate, setTablePrefix
Constructor Detail
JobRepositoryTestUtils
public JobRepositoryTestUtils()
Default constructor.
JobRepositoryTestUtils
public JobRepositoryTestUtils(JobRepository jobRepository, javax.sql.DataSource dataSource)
Create aJobRepositoryTestUtils
with all its mandatory properties.- Parameters:
jobRepository
- aJobRepository
backed by a databasedataSource
- aDataSource
Method Detail
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Overrides:
afterPropertiesSet
in classAbstractJdbcBatchMetadataDao
- Throws:
java.lang.Exception
- See Also:
InitializingBean.afterPropertiesSet()
setDataSource
@Autowired public final void setDataSource(javax.sql.DataSource dataSource)
setJobParametersIncrementer
public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
- Parameters:
jobParametersIncrementer
- the jobParametersIncrementer to set
setJobRepository
@Autowired public void setJobRepository(JobRepository jobRepository)
- Parameters:
jobRepository
- the jobRepository to set
createJobExecutions
public java.util.List<JobExecution> createJobExecutions(java.lang.String jobName, java.lang.String[] stepNames, int count) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException
Use theJobRepository
to create someJobExecution
instances each with the given job name and each having step executions with the given step names.- Parameters:
jobName
- the name of the jobstepNames
- the names of the step executionscount
- the required number of instances ofJobExecution
to create- Returns:
- a collection of
JobExecution
- Throws:
JobExecutionAlreadyRunningException
- thrown if Job is already running.JobRestartException
- thrown if Job is not restartable.JobInstanceAlreadyCompleteException
- thrown if Job Instance is already complete.
createJobExecutions
public java.util.List<JobExecution> createJobExecutions(int count) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException
Use theJobRepository
to create someJobExecution
instances each with a single step execution.- Parameters:
count
- the required number of instances ofJobExecution
to create- Returns:
- a collection of
JobExecution
- Throws:
JobExecutionAlreadyRunningException
- thrown if Job is already running.JobRestartException
- thrown if Job is not restartable.JobInstanceAlreadyCompleteException
- thrown if Job Instance is already complete.
removeJobExecutions
public void removeJobExecutions(java.util.Collection<JobExecution> list) throws org.springframework.dao.DataAccessException
Remove theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.- Parameters:
list
- a list ofJobExecution
- Throws:
org.springframework.dao.DataAccessException
- if there is a problem
removeJobExecutions
public void removeJobExecutions() throws org.springframework.dao.DataAccessException
Remove all theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.- Throws:
org.springframework.dao.DataAccessException
- if there is a problem