Skip to content

Commit 5e849c6

Browse files
committed
Document the type and name of the surrounding job in JobLauncherTestUtils#launchStep
Resolves #3825
1 parent 37fb3f9 commit 5e849c6

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

spring-batch-test/src/main/java/org/springframework/batch/test/JobLauncherTestUtils.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ protected StepRunner getStepRunner() {
177177
}
178178

179179
/**
180-
* Launch just the specified step in the job. A unique set of JobParameters will
181-
* automatically be generated. An IllegalStateException is thrown if there is no Step
182-
* with the given name.
180+
* Launch just the specified step in a surrounding single-step job of type
181+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. A unique set of JobParameters
182+
* will automatically be generated. An IllegalStateException is thrown if there is no
183+
* Step with the given name.
183184
* @param stepName The name of the step to launch
184185
* @return JobExecution
185186
*/
@@ -188,9 +189,10 @@ public JobExecution launchStep(String stepName) {
188189
}
189190

190191
/**
191-
* Launch just the specified step in the job. A unique set of JobParameters will
192-
* automatically be generated. An IllegalStateException is thrown if there is no Step
193-
* with the given name.
192+
* Launch just the specified step in a surrounding single-step job of type
193+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. A unique set of JobParameters
194+
* will automatically be generated. An IllegalStateException is thrown if there is no
195+
* Step with the given name.
194196
* @param stepName The name of the step to launch
195197
* @param jobExecutionContext An ExecutionContext whose values will be loaded into the
196198
* Job ExecutionContext prior to launching the step.
@@ -201,8 +203,9 @@ public JobExecution launchStep(String stepName, ExecutionContext jobExecutionCon
201203
}
202204

203205
/**
204-
* Launch just the specified step in the job. An IllegalStateException is thrown if
205-
* there is no Step with the given name.
206+
* Launch just the specified step in a surrounding single-step job of type
207+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. An IllegalStateException is
208+
* thrown if there is no Step with the given name.
206209
* @param stepName The name of the step to launch
207210
* @param jobParameters The JobParameters to use during the launch
208211
* @return JobExecution
@@ -212,8 +215,9 @@ public JobExecution launchStep(String stepName, JobParameters jobParameters) {
212215
}
213216

214217
/**
215-
* Launch just the specified step in the job. An IllegalStateException is thrown if
216-
* there is no Step with the given name.
218+
* Launch just the specified step in a surrounding single-step job of type
219+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. An IllegalStateException is
220+
* thrown if there is no Step with the given name.
217221
* @param stepName The name of the step to launch
218222
* @param jobParameters The JobParameters to use during the launch
219223
* @param jobExecutionContext An ExecutionContext whose values will be loaded into the

spring-batch-test/src/main/java/org/springframework/batch/test/StepRunner.java

+22-14
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
import org.springframework.lang.Nullable;
4343

4444
/**
45-
* Utility class for executing steps outside of a {@link Job}. This is useful in end to
46-
* end testing in order to allow for the testing of a step individually without running
47-
* every Step in a job.
45+
* Utility class for executing steps. This is useful in end to end testing in order to
46+
* allow for the testing of a step individually without running every Step in a job.
4847
*
4948
* <ul>
5049
* <li><b>launchStep(Step step)</b>: Launch the step with new parameters each time. (The
@@ -67,6 +66,11 @@
6766
*/
6867
public class StepRunner {
6968

69+
/**
70+
* Name of the single-step job surrounding steps when tested individually
71+
*/
72+
public static final String JOB_NAME = "TestJob";
73+
7074
/** Logger */
7175
protected final Log logger = LogFactory.getLog(getClass());
7276

@@ -80,9 +84,10 @@ public StepRunner(JobLauncher launcher, JobRepository jobRepository) {
8084
}
8185

8286
/**
83-
* Launch just the specified step as its own job. A unique set of JobParameters will
84-
* automatically be generated. An IllegalStateException is thrown if there is no Step
85-
* with the given name.
87+
* Launch just the specified step in a surrounding single-step job of type
88+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. A unique set of JobParameters
89+
* will automatically be generated. An IllegalStateException is thrown if there is no
90+
* Step with the given name.
8691
* @param step The step to launch
8792
* @return JobExecution
8893
*/
@@ -91,9 +96,10 @@ public JobExecution launchStep(Step step) {
9196
}
9297

9398
/**
94-
* Launch just the specified step as its own job. A unique set of JobParameters will
95-
* automatically be generated. An IllegalStateException is thrown if there is no Step
96-
* with the given name.
99+
* Launch just the specified step in a surrounding single-step job of type
100+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. A unique set of JobParameters
101+
* will automatically be generated. An IllegalStateException is thrown if there is no
102+
* Step with the given name.
97103
* @param step The step to launch
98104
* @param jobExecutionContext An ExecutionContext whose values will be loaded into the
99105
* Job ExecutionContext prior to launching the step.
@@ -104,8 +110,9 @@ public JobExecution launchStep(Step step, @Nullable ExecutionContext jobExecutio
104110
}
105111

106112
/**
107-
* Launch just the specified step as its own job. An IllegalStateException is thrown
108-
* if there is no Step with the given name.
113+
* Launch just the specified step in a surrounding single-step job of type
114+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. An IllegalStateException is
115+
* thrown if there is no Step with the given name.
109116
* @param step The step to launch
110117
* @param jobParameters The JobParameters to use during the launch
111118
* @return JobExecution
@@ -115,8 +122,9 @@ public JobExecution launchStep(Step step, JobParameters jobParameters) {
115122
}
116123

117124
/**
118-
* Launch just the specified step as its own job. An IllegalStateException is thrown
119-
* if there is no Step with the given name.
125+
* Launch just the specified step in a surrounding single-step job of type
126+
* {@link SimpleJob} named {@link StepRunner#JOB_NAME}. An IllegalStateException is
127+
* thrown if there is no Step with the given name.
120128
* @param step The step to launch
121129
* @param jobParameters The JobParameters to use during the launch
122130
* @param jobExecutionContext An ExecutionContext whose values will be loaded into the
@@ -129,7 +137,7 @@ public JobExecution launchStep(Step step, JobParameters jobParameters,
129137
// Create a fake job
130138
//
131139
SimpleJob job = new SimpleJob();
132-
job.setName("TestJob");
140+
job.setName(JOB_NAME);
133141
job.setJobRepository(this.jobRepository);
134142

135143
List<Step> stepsToExecute = new ArrayList<>();

0 commit comments

Comments
 (0)