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 aJobRepositoryTestUtilswith all its mandatory properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateJobExecutions(int count) Use theJobRepositoryto create someJobExecutioninstances each with a single step execution.createJobExecutions(String jobName, String[] stepNames, int count) Use theJobRepositoryto create someJobExecutioninstances each with the given job name and each having step executions with the given step names.voidRemove all theJobExecutioninstances, and all associatedJobInstanceandStepExecutioninstances from the standard RDBMS locations used by Spring Batch.voidRemove theJobExecutioninstances, and all associatedJobInstanceandStepExecutioninstances from the standard RDBMS locations used by Spring Batch.final voidsetDataSource(DataSource dataSource) voidsetJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer) voidsetJobRepository(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 aJobRepositoryTestUtilswith all its mandatory properties.- Parameters:
jobRepository- aJobRepositorybacked by a databasedataSource- aDataSource
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin 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 theJobRepositoryto create someJobExecutioninstances 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 ofJobExecutionto 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 theJobRepositoryto create someJobExecutioninstances each with a single step execution.- Parameters:
count- the required number of instances ofJobExecutionto 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 theJobExecutioninstances, and all associatedJobInstanceandStepExecutioninstances 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 theJobExecutioninstances, and all associatedJobInstanceandStepExecutioninstances from the standard RDBMS locations used by Spring Batch.- Throws:
org.springframework.dao.DataAccessException- if there is a problem
-