Class JobLauncherTestUtils

java.lang.Object
org.springframework.batch.test.JobLauncherTestUtils
Direct Known Subclasses:
JobOperatorTestUtils

@NullUnmarked @Deprecated(since="6.0", forRemoval=true) public class JobLauncherTestUtils extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
Since 6.0 in favor of JobOperatorTestUtils. Scheduled for removal in 6.2 or later.

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 Steps from a FlowJob or SimpleJob individually. By launching Steps 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 with the name batch.random. 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.springframework.batch.core.job.Job
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected org.springframework.batch.core.launch.JobLauncher
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    protected org.springframework.batch.core.repository.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.
    Logger
    protected 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

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.batch.core.job.Job
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    org.springframework.batch.core.launch.JobLauncher
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    org.springframework.batch.core.repository.JobRepository
    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 a StepRunner for running steps by name.
    org.springframework.batch.core.job.parameters.JobParameters
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    org.springframework.batch.core.job.parameters.JobParametersBuilder
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    org.springframework.batch.core.job.JobExecution
    Deprecated, for removal: This API element is subject to removal in a future version.
    Since 6.0 in favor of JobOperatorTestUtils.startJob().
    org.springframework.batch.core.job.JobExecution
    launchJob(org.springframework.batch.core.job.parameters.JobParameters jobParameters)
    Deprecated, for removal: This API element is subject to removal in a future version.
    org.springframework.batch.core.job.JobExecution
    launchStep(String stepName)
    Deprecated, for removal: This API element is subject to removal in a future version.
    org.springframework.batch.core.job.JobExecution
    launchStep(String stepName, org.springframework.batch.core.job.parameters.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 type SimpleJob named StepRunner.JOB_NAME.
    org.springframework.batch.core.job.JobExecution
    launchStep(String stepName, org.springframework.batch.core.job.parameters.JobParameters jobParameters, @Nullable org.springframework.batch.infrastructure.item.ExecutionContext jobExecutionContext)
    Deprecated, for removal: This API element is subject to removal in a future version.
    org.springframework.batch.core.job.JobExecution
    launchStep(String stepName, org.springframework.batch.infrastructure.item.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 type SimpleJob named StepRunner.JOB_NAME.
    void
    setJob(org.springframework.batch.core.job.Job job)
    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(org.springframework.batch.core.launch.JobLauncher jobLauncher)
    Deprecated, for removal: This API element is subject to removal in a future version.
    A JobLauncher instance that can be used to launch jobs.
    void
    setJobRepository(org.springframework.batch.core.repository.JobRepository jobRepository)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The JobRepository to use for creating new JobExecution instances.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • secureRandom

      protected final SecureRandom secureRandom
      Deprecated, for removal: This API element is subject to removal in a future version.
    • logger

      protected final org.apache.commons.logging.Log logger
      Deprecated, for removal: This API element is subject to removal in a future version.
      Logger
    • jobLauncher

      protected org.springframework.batch.core.launch.JobLauncher jobLauncher
      Deprecated, for removal: This API element is subject to removal in a future version.
    • job

      protected org.springframework.batch.core.job.Job job
      Deprecated, for removal: This API element is subject to removal in a future version.
    • jobRepository

      protected org.springframework.batch.core.repository.JobRepository jobRepository
      Deprecated, for removal: This API element is subject to removal in a future version.
    • stepRunner

      protected StepRunner 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

      public void setJob(org.springframework.batch.core.job.Job job)
      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 - the AbstractJob to use
    • setJobRepository

      public void setJobRepository(org.springframework.batch.core.repository.JobRepository jobRepository)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The JobRepository to use for creating new JobExecution instances.
      Parameters:
      jobRepository - a JobRepository
    • getJobRepository

      public org.springframework.batch.core.repository.JobRepository getJobRepository()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the job repository
    • getJob

      public org.springframework.batch.core.job.Job getJob()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the job
    • setJobLauncher

      public void setJobLauncher(org.springframework.batch.core.launch.JobLauncher jobLauncher)
      Deprecated, for removal: This API element is subject to removal in a future version.
      A JobLauncher instance that can be used to launch jobs.
      Parameters:
      jobLauncher - a job launcher
    • getJobLauncher

      public org.springframework.batch.core.launch.JobLauncher getJobLauncher()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      the job launcher
    • launchJob

      @Deprecated(since="6.0", forRemoval=true) public org.springframework.batch.core.job.JobExecution launchJob() throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 6.0 in favor of JobOperatorTestUtils.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 org.springframework.batch.core.job.JobExecution launchJob(org.springframework.batch.core.job.parameters.JobParameters jobParameters) throws Exception
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 6.0 in favor of JobOperatorTestUtils.startJob(JobParameters). Scheduled for removal in 6.2 or later.
      Launch the entire job, including all steps
      Parameters:
      jobParameters - instance of JobParameters.
      Returns:
      JobExecution, so that the test can validate the exit status
      Throws:
      Exception - thrown if error occurs launching the job.
    • getUniqueJobParameters

      public org.springframework.batch.core.job.parameters.JobParameters getUniqueJobParameters()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      a new JobParameters object containing only one parameter named batch.random with a random number of type long, to ensure that the job instance will be unique.
    • getUniqueJobParametersBuilder

      public org.springframework.batch.core.job.parameters.JobParametersBuilder getUniqueJobParametersBuilder()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      a new JobParameters object containing only one parameter named batch.random with a random number of type long, to ensure that the job instance will be unique.
    • getStepRunner

      protected StepRunner getStepRunner()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Convenient method for subclasses to grab a StepRunner for running steps by name.
      Returns:
      a StepRunner
    • launchStep

      @Deprecated(since="6.0", forRemoval=true) public org.springframework.batch.core.job.JobExecution launchStep(String stepName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 6.0 in favor of JobOperatorTestUtils.startStep(String). Scheduled for removal in 6.2 or later.
      Launch just the specified step in a surrounding single-step job of type SimpleJob named StepRunner.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

      public org.springframework.batch.core.job.JobExecution launchStep(String stepName, org.springframework.batch.infrastructure.item.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 type SimpleJob named StepRunner.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
      jobExecutionContext - An ExecutionContext whose values will be loaded into the Job ExecutionContext prior to launching the step.
      Returns:
      JobExecution
    • launchStep

      public org.springframework.batch.core.job.JobExecution launchStep(String stepName, org.springframework.batch.core.job.parameters.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 type SimpleJob named StepRunner.JOB_NAME. An IllegalStateException is thrown if there is no Step with the given name.
      Parameters:
      stepName - The name of the step to launch
      jobParameters - The JobParameters to use during the launch
      Returns:
      JobExecution
    • launchStep

      @Deprecated(since="6.0", forRemoval=true) public org.springframework.batch.core.job.JobExecution launchStep(String stepName, org.springframework.batch.core.job.parameters.JobParameters jobParameters, @Nullable org.springframework.batch.infrastructure.item.ExecutionContext jobExecutionContext)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Since 6.0 in favor of JobOperatorTestUtils.startStep(String, JobParameters, ExecutionContext). Scheduled for removal in 6.2 or later.
      Launch just the specified step in a surrounding single-step job of type SimpleJob named StepRunner.JOB_NAME. An IllegalStateException is thrown if there is no Step with the given name.
      Parameters:
      stepName - The name of the step to launch
      jobParameters - The JobParameters to use during the launch
      jobExecutionContext - An ExecutionContext whose values will be loaded into the Job ExecutionContext prior to launching the step.
      Returns:
      JobExecution