Class JobLauncherTestUtils
- java.lang.Object
- org.springframework.batch.test.JobLauncherTestUtils
public class JobLauncherTestUtils extends java.lang.ObjectUtility class for testing batch jobs. It provides methods for launching an entire
AbstractJob, allowing for end to end testing of individual steps, without having to run every step in the job. Any test classes using this utility can set up an instance in theApplicationContextas part of the Spring test framework.This class also provides the ability to run
Steps from aFlowJoborSimpleJobindividually. By launchingSteps within aJobon their own, end to end testing of individual steps can be performed without having to run every step in the job.It should be noted that using any of the methods that don't contain
JobParametersin their signature, will result in one being created with the current system time as a parameter. This will ensure restartability when no parameters are provided.- Since:
- 2.1
- Author:
- Lucas Ward, Dan Garrette, Dave Syer, Mahmoud Ben Hassine
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.logging.LogloggerLogger
Constructor Summary
Constructors Constructor Description JobLauncherTestUtils()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JobgetJob()JobLaunchergetJobLauncher()JobRepositorygetJobRepository()protected StepRunnergetStepRunner()Convenient method for subclasses to grab aStepRunnerfor running steps by name.JobParametersgetUniqueJobParameters()JobExecutionlaunchJob()Launch the entire job, including all steps.JobExecutionlaunchJob(JobParameters jobParameters)Launch the entire job, including all stepsJobExecutionlaunchStep(java.lang.String stepName)Launch just the specified step in the job.JobExecutionlaunchStep(java.lang.String stepName, JobParameters jobParameters)Launch just the specified step in the job.JobExecutionlaunchStep(java.lang.String stepName, JobParameters jobParameters, ExecutionContext jobExecutionContext)Launch just the specified step in the job.JobExecutionlaunchStep(java.lang.String stepName, ExecutionContext jobExecutionContext)Launch just the specified step in the job.voidsetJob(Job job)The Job instance that can be manipulated (e.g.voidsetJobLauncher(JobLauncher jobLauncher)AJobLauncherinstance that can be used to launch jobs.voidsetJobRepository(JobRepository jobRepository)TheJobRepositoryto use for creating newJobExecutioninstances.
Method Detail
setJob
@Autowired public void setJob(Job job)
The Job instance that can be manipulated (e.g. launched) in this utility.- Parameters:
job- theAbstractJobto use
setJobRepository
@Autowired public void setJobRepository(JobRepository jobRepository)
TheJobRepositoryto use for creating newJobExecutioninstances.- Parameters:
jobRepository- aJobRepository
getJobRepository
public JobRepository getJobRepository()
- Returns:
- the job repository
getJob
public Job getJob()
- Returns:
- the job
setJobLauncher
@Autowired public void setJobLauncher(JobLauncher jobLauncher)
AJobLauncherinstance that can be used to launch jobs.- Parameters:
jobLauncher- a job launcher
getJobLauncher
public JobLauncher getJobLauncher()
- Returns:
- the job launcher
launchJob
public JobExecution launchJob() throws java.lang.Exception
Launch the entire job, including all steps.- Returns:
- JobExecution, so that the test can validate the exit status
- Throws:
java.lang.Exception- thrown if error occurs launching the job.
launchJob
public JobExecution launchJob(JobParameters jobParameters) throws java.lang.Exception
Launch the entire job, including all steps- Parameters:
jobParameters- instance ofJobParameters.- Returns:
- JobExecution, so that the test can validate the exit status
- Throws:
java.lang.Exception- thrown if error occurs launching the job.
getUniqueJobParameters
public JobParameters getUniqueJobParameters()
- Returns:
- a new JobParameters object containing only a parameter for the current timestamp, to ensure that the job instance will be unique.
getStepRunner
protected StepRunner getStepRunner()
Convenient method for subclasses to grab aStepRunnerfor running steps by name.- Returns:
- a
StepRunner
launchStep
public JobExecution launchStep(java.lang.String stepName)
Launch just the specified step in the job. A unique set of JobParameters will automatically be generated. An IllegalStateException is thrown if there is no Step with the given name.- Parameters:
stepName- The name of the step to launch- Returns:
- JobExecution
launchStep
public JobExecution launchStep(java.lang.String stepName, ExecutionContext jobExecutionContext)
Launch just the specified step in the job. A unique set of JobParameters will automatically be generated. An IllegalStateException is thrown if there is no Step with the given name.- Parameters:
stepName- The name of the step to launchjobExecutionContext- An ExecutionContext whose values will be loaded into the Job ExecutionContext prior to launching the step.- Returns:
- JobExecution
launchStep
public JobExecution launchStep(java.lang.String stepName, JobParameters jobParameters)
Launch just the specified step in the job. An IllegalStateException is thrown if there is no Step with the given name.- Parameters:
stepName- The name of the step to launchjobParameters- The JobParameters to use during the launch- Returns:
- JobExecution
launchStep
public JobExecution launchStep(java.lang.String stepName, JobParameters jobParameters, @Nullable ExecutionContext jobExecutionContext)
Launch just the specified step in the job. An IllegalStateException is thrown if there is no Step with the given name.- Parameters:
stepName- The name of the step to launchjobParameters- The JobParameters to use during the launchjobExecutionContext- An ExecutionContext whose values will be loaded into the Job ExecutionContext prior to launching the step.- Returns:
- JobExecution