org.springframework.batch.test
Class JobRepositoryTestUtils

java.lang.Object
  extended by org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
      extended by org.springframework.batch.test.JobRepositoryTestUtils
All Implemented Interfaces:
InitializingBean

public class JobRepositoryTestUtils
extends AbstractJdbcBatchMetadataDao
implements 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

Field Summary
 
Fields inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
DEFAULT_EXIT_MESSAGE_LENGTH, DEFAULT_TABLE_PREFIX
 
Constructor Summary
JobRepositoryTestUtils()
          Default constructor.
JobRepositoryTestUtils(JobRepository jobRepository, DataSource dataSource)
          Create a JobRepositoryTestUtils with all its mandatory properties.
 
Method Summary
 void afterPropertiesSet()
           
 List<JobExecution> createJobExecutions(int count)
          Use the JobRepository to create some JobExecution instances each with a single step execution.
 List<JobExecution> createJobExecutions(String jobName, String[] stepNames, int count)
          Use the JobRepository to create some JobExecution instances each with the given job name and each having step executions with the given step names.
 void removeJobExecutions()
          Remove all the JobExecution instances, and all associated JobInstance and StepExecution instances from the standard RDBMS locations used by Spring Batch.
 void removeJobExecutions(Collection<JobExecution> list)
          Remove the JobExecution instances, and all associated JobInstance and StepExecution instances from the standard RDBMS locations used by Spring Batch.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JobRepositoryTestUtils

public JobRepositoryTestUtils()
Default constructor.


JobRepositoryTestUtils

public JobRepositoryTestUtils(JobRepository jobRepository,
                              DataSource dataSource)
Create a JobRepositoryTestUtils with all its mandatory properties.

Parameters:
jobRepository - a JobRepository backed by a database
dataSource - a DataSource
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractJdbcBatchMetadataDao
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

setDataSource

public final void setDataSource(DataSource dataSource)

setJobParametersIncrementer

public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer)
Parameters:
jobParametersIncrementer - the jobParametersIncrementer to set

setJobRepository

public void setJobRepository(JobRepository jobRepository)
Parameters:
jobRepository - the jobRepository to set

createJobExecutions

public List<JobExecution> createJobExecutions(String jobName,
                                              String[] stepNames,
                                              int count)
                                       throws JobExecutionAlreadyRunningException,
                                              JobRestartException,
                                              JobInstanceAlreadyCompleteException
Use the JobRepository to create some JobExecution instances each with the given job name and each having step executions with the given step names.

Parameters:
jobName - the name of the job
stepNames - the names of the step executions
count - the required number of instances of JobExecution to create
Returns:
a collection of JobExecution
Throws:
Exception - if there is a problem in the JobRepository
JobExecutionAlreadyRunningException
JobRestartException
JobInstanceAlreadyCompleteException

createJobExecutions

public List<JobExecution> createJobExecutions(int count)
                                       throws JobExecutionAlreadyRunningException,
                                              JobRestartException,
                                              JobInstanceAlreadyCompleteException
Use the JobRepository to create some JobExecution instances each with a single step execution.

Parameters:
count - the required number of instances of JobExecution to create
Returns:
a collection of JobExecution
Throws:
Exception - if there is a problem in the JobRepository
JobExecutionAlreadyRunningException
JobRestartException
JobInstanceAlreadyCompleteException

removeJobExecutions

public void removeJobExecutions(Collection<JobExecution> list)
                         throws DataAccessException
Remove the JobExecution instances, and all associated JobInstance and StepExecution instances from the standard RDBMS locations used by Spring Batch.

Parameters:
list - a list of JobExecution
Throws:
DataAccessException - if there is a problem

removeJobExecutions

public void removeJobExecutions()
                         throws DataAccessException
Remove all the JobExecution instances, and all associated JobInstance and StepExecution instances from the standard RDBMS locations used by Spring Batch.

Parameters:
list - a list of JobExecution
Throws:
DataAccessException - if there is a problem


Copyright © 2013 SpringSource. All Rights Reserved.