public class JobLauncherTestUtils
extends java.lang.Object
Utility 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 the ApplicationContext
as part
of the Spring test framework.
This class also provides the ability to run Step
s from a
FlowJob
or SimpleJob
individually. By launching Step
s
within a Job
on 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
JobParameters
in 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.
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
logger
Logger
|
Constructor and Description |
---|
JobLauncherTestUtils() |
Modifier and Type | Method and Description |
---|---|
Job |
getJob() |
JobLauncher |
getJobLauncher() |
JobRepository |
getJobRepository() |
protected StepRunner |
getStepRunner()
Convenient method for subclasses to grab a
StepRunner for running
steps by name. |
JobParameters |
getUniqueJobParameters() |
JobExecution |
launchJob()
Launch the entire job, including all steps.
|
JobExecution |
launchJob(JobParameters jobParameters)
Launch the entire job, including all steps
|
JobExecution |
launchStep(java.lang.String stepName)
Launch just the specified step in the job.
|
JobExecution |
launchStep(java.lang.String stepName,
ExecutionContext jobExecutionContext)
Launch just the specified step in the job.
|
JobExecution |
launchStep(java.lang.String stepName,
JobParameters jobParameters)
Launch just the specified step in the job.
|
JobExecution |
launchStep(java.lang.String stepName,
JobParameters jobParameters,
ExecutionContext jobExecutionContext)
Launch just the specified step in the job.
|
void |
setJob(Job job)
The Job instance that can be manipulated (e.g.
|
void |
setJobLauncher(JobLauncher jobLauncher)
A
JobLauncher instance that can be used to launch jobs. |
void |
setJobRepository(JobRepository jobRepository)
The
JobRepository to use for creating new JobExecution
instances. |
@Autowired public void setJob(Job job)
job
- the AbstractJob
to use@Autowired public void setJobRepository(JobRepository jobRepository)
JobRepository
to use for creating new JobExecution
instances.jobRepository
- a JobRepository
public JobRepository getJobRepository()
public Job getJob()
@Autowired public void setJobLauncher(JobLauncher jobLauncher)
JobLauncher
instance that can be used to launch jobs.jobLauncher
- a job launcherpublic JobLauncher getJobLauncher()
public JobExecution launchJob() throws java.lang.Exception
java.lang.Exception
- thrown if error occurs launching the job.public JobExecution launchJob(JobParameters jobParameters) throws java.lang.Exception
jobParameters
- instance of JobParameters
.java.lang.Exception
- thrown if error occurs launching the job.public JobParameters getUniqueJobParameters()
protected StepRunner getStepRunner()
StepRunner
for running
steps by name.StepRunner
public JobExecution launchStep(java.lang.String stepName)
stepName
- The name of the step to launchpublic JobExecution launchStep(java.lang.String stepName, ExecutionContext jobExecutionContext)
stepName
- The name of the step to launchjobExecutionContext
- An ExecutionContext whose values will be
loaded into the Job ExecutionContext prior to launching the step.public JobExecution launchStep(java.lang.String stepName, JobParameters jobParameters)
stepName
- The name of the step to launchjobParameters
- The JobParameters to use during the launchpublic JobExecution launchStep(java.lang.String stepName, JobParameters jobParameters, ExecutionContext jobExecutionContext)
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.