Package org.springframework.batch.test
Class JobRepositoryTestUtils
java.lang.Object
org.springframework.batch.test.JobRepositoryTestUtils
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
-
Constructor Summary
ConstructorDescriptionDefault constructor.JobRepositoryTestUtils
(JobRepository jobRepository) Create aJobRepositoryTestUtils
with all its mandatory properties. -
Method Summary
Modifier and TypeMethodDescriptioncreateJobExecutions
(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
removeJobExecution
(JobExecution jobExecution) Remove theJobExecution
and its associatedStepExecution
instances from the standard locations used by Spring Batch.void
Remove all theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard locations used by Spring Batch.void
removeJobExecutions
(Collection<JobExecution> jobExecutions) Remove theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard locations used by Spring Batch.void
setJobParametersIncrementer
(JobParametersIncrementer jobParametersIncrementer) void
setJobRepository
(JobRepository jobRepository)
-
Constructor Details
-
JobRepositoryTestUtils
public JobRepositoryTestUtils()Default constructor. -
JobRepositoryTestUtils
Create aJobRepositoryTestUtils
with all its mandatory properties.- Parameters:
jobRepository
- aJobRepository
.
-
-
Method Details
-
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
Remove theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard locations used by Spring Batch.- Parameters:
jobExecutions
- a collection ofJobExecution
-
removeJobExecution
Remove theJobExecution
and its associatedStepExecution
instances from the standard locations used by Spring Batch.- Parameters:
jobExecution
- theJobExecution
to delete
-
removeJobExecutions
public void removeJobExecutions()Remove all theJobExecution
instances, and all associatedJobInstance
andStepExecution
instances from the standard locations used by Spring Batch.
-