From 2cc0be4a0c31b7bc190e7244145552cc3a0927b0 Mon Sep 17 00:00:00 2001 From: jinwoo-Bae Date: Sat, 18 Feb 2023 01:37:49 +0900 Subject: [PATCH] Replace usage of deprecated jobOperator#start method with newer version Related to #4303 --- .../support/SimpleJobOperatorTests.java | 19 +++++++++++++++---- .../sample/JobOperatorFunctionalTests.java | 7 +++++-- .../sample/launch/RemoteLauncherTests.java | 11 +++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java index c8fe49f83..d6f7481f7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJobOperatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.configuration.support.MapJobRegistry; import org.springframework.batch.core.converter.DefaultJobParametersConverter; +import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.job.AbstractJob; import org.springframework.batch.core.job.JobSupport; @@ -69,6 +70,7 @@ import static org.mockito.Mockito.when; * @author Dave Syer * @author Will Schipp * @author Mahmoud Ben Hassine + * @author Jinwoo Bae * */ class SimpleJobOperatorTests { @@ -83,9 +85,13 @@ class SimpleJobOperatorTests { private JobParameters jobParameters; + private JobParametersConverter jobParametersConverter; + @BeforeEach void setUp() throws Exception { + jobParametersConverter = new DefaultJobParametersConverter(); + job = new JobSupport("foo") { @Nullable @Override @@ -162,18 +168,23 @@ class SimpleJobOperatorTests { @Test void testStartNewInstanceSunnyDay() throws Exception { - jobParameters = new JobParameters(); + Properties parameters = new Properties(); + parameters.setProperty("a", "b"); + JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters); + jobRepository.isJobInstanceExists("foo", jobParameters); - Long value = jobOperator.start("foo", "a=b"); + Long value = jobOperator.start("foo", parameters); assertEquals(999, value.longValue()); } @Test void testStartNewInstanceAlreadyExists() { + Properties properties = new Properties(); + properties.setProperty("a", "b"); jobParameters = new JobParameters(); when(jobRepository.isJobInstanceExists("foo", jobParameters)).thenReturn(true); jobRepository.isJobInstanceExists("foo", jobParameters); - assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", "a=b")); + assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", properties)); } @Test diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java index 3e1bb3f07..53b5688f4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/JobOperatorFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2022 the original author or authors. + * Copyright 2008-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.batch.sample; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.apache.commons.logging.Log; @@ -61,8 +62,10 @@ class JobOperatorFunctionalTests { @Test void testStartStopResumeJob() throws Exception { String params = "jobOperatorTestParam=7,java.lang.Long,true"; + Properties properties = new Properties(); + properties.setProperty("jobOperatorTestParam", "7,java.lang.Long,true"); - long executionId = operator.start(job.getName(), params); + long executionId = operator.start(job.getName(), properties); assertEquals(params, operator.getParameters(executionId)); stopAndCheckStatus(executionId); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java index 4bd7c18e1..74fcbf2c2 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,11 +31,13 @@ import javax.management.MalformedObjectNameException; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Properties; import static org.junit.jupiter.api.Assertions.*; /** * @author Dave Syer + * @author Jinwoo Bae * */ class RemoteLauncherTests { @@ -61,11 +63,12 @@ class RemoteLauncherTests { @Test void testLaunchBadJob() throws Exception { + Properties properties = new Properties(); + properties.setProperty("time", String.valueOf(new Date().getTime())); assertEquals(0, errors.size()); assertTrue(isConnected()); - Exception exception = assertThrows(RuntimeException.class, - () -> launcher.start("foo", "time=" + (new Date().getTime()))); + Exception exception = assertThrows(RuntimeException.class, () -> launcher.start("foo", properties)); String message = exception.getMessage(); assertTrue(message.contains("NoSuchJobException"), "Wrong message: " + message); } @@ -84,7 +87,7 @@ class RemoteLauncherTests { assertTrue(isConnected()); assertTrue(launcher.getJobNames().contains("loopJob")); - long executionId = launcher.start("loopJob", ""); + long executionId = launcher.start("loopJob", new Properties()); // sleep long enough to avoid race conditions (serializable tx isolation // doesn't work with HSQL)