Class JobLauncherTestUtils
- Direct Known Subclasses:
JobOperatorTestUtils
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 a
random number of type long
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
FieldsModifier and TypeFieldDescriptionprotected Job
Deprecated, for removal: This API element is subject to removal in a future version.protected JobLauncher
Deprecated, for removal: This API element is subject to removal in a future version.protected JobRepository
Deprecated, for removal: This API element is subject to removal in a future version.protected final org.apache.commons.logging.Log
Deprecated, for removal: This API element is subject to removal in a future version.Loggerprotected final SecureRandom
Deprecated, for removal: This API element is subject to removal in a future version.protected StepRunner
Deprecated, for removal: This API element is subject to removal in a future version. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptiongetJob()
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.protected StepRunner
Deprecated, for removal: This API element is subject to removal in a future version.Convenient method for subclasses to grab aStepRunner
for running steps by name.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startJob()
.launchJob
(JobParameters jobParameters) Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startJob(JobParameters)
.launchStep
(String stepName) Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startStep(String)
.launchStep
(String stepName, JobParameters jobParameters) Deprecated, for removal: This API element is subject to removal in a future version.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
.launchStep
(String stepName, JobParameters jobParameters, ExecutionContext jobExecutionContext) Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startStep(String, JobParameters, ExecutionContext)
.launchStep
(String stepName, ExecutionContext jobExecutionContext) Deprecated, for removal: This API element is subject to removal in a future version.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
.void
Deprecated, for removal: This API element is subject to removal in a future version.The Job instance that can be manipulated (e.g. launched) in this utility.void
setJobLauncher
(JobLauncher jobLauncher) Deprecated, for removal: This API element is subject to removal in a future version.AJobLauncher
instance that can be used to launch jobs.void
setJobRepository
(JobRepository jobRepository) Deprecated, for removal: This API element is subject to removal in a future version.TheJobRepository
to use for creating newJobExecution
instances.
-
Field Details
-
secureRandom
Deprecated, for removal: This API element is subject to removal in a future version. -
logger
protected final org.apache.commons.logging.Log loggerDeprecated, for removal: This API element is subject to removal in a future version.Logger -
jobLauncher
Deprecated, for removal: This API element is subject to removal in a future version. -
job
Deprecated, for removal: This API element is subject to removal in a future version. -
jobRepository
Deprecated, for removal: This API element is subject to removal in a future version. -
stepRunner
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Constructor Details
-
JobLauncherTestUtils
public JobLauncherTestUtils()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setJob
Deprecated, for removal: This API element is subject to removal in a future version.The Job instance that can be manipulated (e.g. launched) in this utility.- Parameters:
job
- theAbstractJob
to use
-
setJobRepository
Deprecated, for removal: This API element is subject to removal in a future version.TheJobRepository
to use for creating newJobExecution
instances.- Parameters:
jobRepository
- aJobRepository
-
getJobRepository
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the job repository
-
getJob
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the job
-
setJobLauncher
Deprecated, for removal: This API element is subject to removal in a future version.AJobLauncher
instance that can be used to launch jobs.- Parameters:
jobLauncher
- a job launcher
-
getJobLauncher
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the job launcher
-
launchJob
Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startJob()
. Scheduled for removal in 6.2 or later.Launch the entire job, including all steps.- Returns:
- JobExecution, so that the test can validate the exit status
- Throws:
Exception
- thrown if error occurs launching the job.
-
launchJob
@Deprecated(since="6.0", forRemoval=true) public JobExecution launchJob(JobParameters jobParameters) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startJob(JobParameters)
. Scheduled for removal in 6.2 or later.Launch the entire job, including all steps- Parameters:
jobParameters
- instance ofJobParameters
.- Returns:
- JobExecution, so that the test can validate the exit status
- Throws:
Exception
- thrown if error occurs launching the job.
-
getUniqueJobParameters
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- a new JobParameters object containing only a parameter with a random number
of type
long
, to ensure that the job instance will be unique.
-
getUniqueJobParametersBuilder
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- a new JobParametersBuilder object containing only a parameter with a random
number of type
long
, to ensure that the job instance will be unique.
-
getStepRunner
Deprecated, for removal: This API element is subject to removal in a future version.Convenient method for subclasses to grab aStepRunner
for running steps by name.- Returns:
- a
StepRunner
-
launchStep
Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startStep(String)
. Scheduled for removal in 6.2 or later.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
. 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
Deprecated, for removal: This API element is subject to removal in a future version.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
. 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
Deprecated, for removal: This API element is subject to removal in a future version.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
. 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
@Deprecated(since="6.0", forRemoval=true) public JobExecution launchStep(String stepName, JobParameters jobParameters, @Nullable ExecutionContext jobExecutionContext) Deprecated, for removal: This API element is subject to removal in a future version.Since 6.0 in favor ofJobOperatorTestUtils.startStep(String, JobParameters, ExecutionContext)
. Scheduled for removal in 6.2 or later.Launch just the specified step in a surrounding single-step job of typeSimpleJob
namedStepRunner.JOB_NAME
. 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
-
JobOperatorTestUtils
. Scheduled for removal in 6.2 or later.