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 removing
JobExecution
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
ConstructorsConstructorDescriptionDefault constructor.JobRepositoryTestUtils
(JobRepository jobRepository, DataSource dataSource) Create aJobRepositoryTestUtils
with all its mandatory properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createJobExecutions
(int count) Use theJobRepository
to create someJobExecution
instances each with a single step execution.createJobExecutions
(String jobName, 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
Remove all theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.void
Remove theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard RDBMS locations used by Spring Batch.final void
setDataSource
(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 Details
-
JobRepositoryTestUtils
public JobRepositoryTestUtils()Default constructor. -
JobRepositoryTestUtils
Create aJobRepositoryTestUtils
with all its mandatory properties.- Parameters:
jobRepository
- aJobRepository
backed by a databasedataSource
- aDataSource
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Overrides:
afterPropertiesSet
in classAbstractJdbcBatchMetadataDao
- Throws:
Exception
- See Also:
-
InitializingBean.afterPropertiesSet()
-
setDataSource
-
setJobParametersIncrementer
- Parameters:
jobParametersIncrementer
- the jobParametersIncrementer to set
-
setJobRepository
- Parameters:
jobRepository
- the jobRepository to set
-
createJobExecutions
public List<JobExecution> createJobExecutions(String jobName, 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 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(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.DataAccessExceptionRemove 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
-