org.springframework.batch.test
Class JobLauncherTestUtils

java.lang.Object
  extended by org.springframework.batch.test.JobLauncherTestUtils

public class JobLauncherTestUtils
extends 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 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 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

Field Summary
protected  Log logger
          Logger
 
Constructor Summary
JobLauncherTestUtils()
           
 
Method Summary
 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(String stepName)
          Launch just the specified step in the job.
 JobExecution launchStep(String stepName, ExecutionContext jobExecutionContext)
          Launch just the specified step in the job.
 JobExecution launchStep(String stepName, JobParameters jobParameters)
          Launch just the specified step in the job.
 JobExecution launchStep(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. launched) in this utility.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger

Constructor Detail

JobLauncherTestUtils

public JobLauncherTestUtils()
Method Detail

setJob

public void setJob(Job job)
The Job instance that can be manipulated (e.g. launched) in this utility.

Parameters:
job - the AbstractJob to use

setJobRepository

public void setJobRepository(JobRepository jobRepository)
The JobRepository to use for creating new JobExecution instances.

Parameters:
jobRepository - a JobRepository

getJobRepository

public JobRepository getJobRepository()
Returns:
the job repository

getJob

public Job getJob()
Returns:
the job

setJobLauncher

public void setJobLauncher(JobLauncher jobLauncher)
A JobLauncher instance 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 Exception
Launch the entire job, including all steps.

Returns:
JobExecution, so that the test can validate the exit status
Throws:
Exception

launchJob

public JobExecution launchJob(JobParameters jobParameters)
                       throws Exception
Launch the entire job, including all steps

Parameters:
jobParameters -
Returns:
JobExecution, so that the test can validate the exit status
Throws:
Exception

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 a StepRunner for running steps by name.

Returns:
a StepRunner

launchStep

public JobExecution launchStep(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(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 launch
jobExecutionContext - An ExecutionContext whose values will be loaded into the Job ExecutionContext prior to launching the step.
Returns:
JobExecution

launchStep

public JobExecution launchStep(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 launch
jobParameters - The JobParameters to use during the launch
Returns:
JobExecution

launchStep

public JobExecution launchStep(String stepName,
                               JobParameters jobParameters,
                               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 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


Copyright © 2013 SpringSource. All Rights Reserved.