Skip to content

Commit 2cc0be4

Browse files
baezzysfmbenhassine
authored andcommitted
Replace usage of deprecated jobOperator#start method with newer version
Related to #4303
1 parent b76993c commit 2cc0be4

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import org.springframework.batch.core.configuration.JobRegistry;
4040
import org.springframework.batch.core.configuration.support.MapJobRegistry;
4141
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
42+
import org.springframework.batch.core.converter.JobParametersConverter;
4243
import org.springframework.batch.core.explore.JobExplorer;
4344
import org.springframework.batch.core.job.AbstractJob;
4445
import org.springframework.batch.core.job.JobSupport;
@@ -69,6 +70,7 @@
6970
* @author Dave Syer
7071
* @author Will Schipp
7172
* @author Mahmoud Ben Hassine
73+
* @author Jinwoo Bae
7274
*
7375
*/
7476
class SimpleJobOperatorTests {
@@ -83,9 +85,13 @@ class SimpleJobOperatorTests {
8385

8486
private JobParameters jobParameters;
8587

88+
private JobParametersConverter jobParametersConverter;
89+
8690
@BeforeEach
8791
void setUp() throws Exception {
8892

93+
jobParametersConverter = new DefaultJobParametersConverter();
94+
8995
job = new JobSupport("foo") {
9096
@Nullable
9197
@Override
@@ -162,18 +168,23 @@ void testStartNextInstanceSunnyDay() throws Exception {
162168

163169
@Test
164170
void testStartNewInstanceSunnyDay() throws Exception {
165-
jobParameters = new JobParameters();
171+
Properties parameters = new Properties();
172+
parameters.setProperty("a", "b");
173+
JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters);
174+
166175
jobRepository.isJobInstanceExists("foo", jobParameters);
167-
Long value = jobOperator.start("foo", "a=b");
176+
Long value = jobOperator.start("foo", parameters);
168177
assertEquals(999, value.longValue());
169178
}
170179

171180
@Test
172181
void testStartNewInstanceAlreadyExists() {
182+
Properties properties = new Properties();
183+
properties.setProperty("a", "b");
173184
jobParameters = new JobParameters();
174185
when(jobRepository.isJobInstanceExists("foo", jobParameters)).thenReturn(true);
175186
jobRepository.isJobInstanceExists("foo", jobParameters);
176-
assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", "a=b"));
187+
assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", properties));
177188
}
178189

179190
@Test

spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2022 the original author or authors.
2+
* Copyright 2008-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import java.util.List;
1919
import java.util.Map;
20+
import java.util.Properties;
2021
import java.util.Set;
2122

2223
import org.apache.commons.logging.Log;
@@ -61,8 +62,10 @@ void setUp() throws Exception {
6162
@Test
6263
void testStartStopResumeJob() throws Exception {
6364
String params = "jobOperatorTestParam=7,java.lang.Long,true";
65+
Properties properties = new Properties();
66+
properties.setProperty("jobOperatorTestParam", "7,java.lang.Long,true");
6467

65-
long executionId = operator.start(job.getName(), params);
68+
long executionId = operator.start(job.getName(), properties);
6669
assertEquals(params, operator.getParameters(executionId));
6770
stopAndCheckStatus(executionId);
6871

spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,11 +31,13 @@
3131
import java.util.ArrayList;
3232
import java.util.Date;
3333
import java.util.List;
34+
import java.util.Properties;
3435

3536
import static org.junit.jupiter.api.Assertions.*;
3637

3738
/**
3839
* @author Dave Syer
40+
* @author Jinwoo Bae
3941
*
4042
*/
4143
class RemoteLauncherTests {
@@ -61,11 +63,12 @@ void testConnect() throws Exception {
6163

6264
@Test
6365
void testLaunchBadJob() throws Exception {
66+
Properties properties = new Properties();
67+
properties.setProperty("time", String.valueOf(new Date().getTime()));
6468
assertEquals(0, errors.size());
6569
assertTrue(isConnected());
6670

67-
Exception exception = assertThrows(RuntimeException.class,
68-
() -> launcher.start("foo", "time=" + (new Date().getTime())));
71+
Exception exception = assertThrows(RuntimeException.class, () -> launcher.start("foo", properties));
6972
String message = exception.getMessage();
7073
assertTrue(message.contains("NoSuchJobException"), "Wrong message: " + message);
7174
}
@@ -84,7 +87,7 @@ void testPauseJob() throws Exception {
8487
assertTrue(isConnected());
8588
assertTrue(launcher.getJobNames().contains("loopJob"));
8689

87-
long executionId = launcher.start("loopJob", "");
90+
long executionId = launcher.start("loopJob", new Properties());
8891

8992
// sleep long enough to avoid race conditions (serializable tx isolation
9093
// doesn't work with HSQL)

0 commit comments

Comments
 (0)