|
31 | 31 | import com.fasterxml.jackson.annotation.JsonTypeInfo; |
32 | 32 | import org.junit.jupiter.api.Test; |
33 | 33 |
|
| 34 | +import org.springframework.batch.core.job.parameters.JobParameter; |
| 35 | +import org.springframework.batch.core.job.parameters.JobParameters; |
| 36 | +import org.springframework.batch.core.job.parameters.JobParametersBuilder; |
34 | 37 | import org.springframework.batch.core.repository.ExecutionContextSerializer; |
35 | 38 |
|
36 | 39 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
37 | 40 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 41 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
38 | 42 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
39 | 43 | import static org.junit.jupiter.api.Assertions.assertThrows; |
40 | 44 | import static org.junit.jupiter.api.Assertions.assertTrue; |
|
43 | 47 | * @author Marten Deinum |
44 | 48 | * @author Michael Minella |
45 | 49 | * @author Mahmoud Ben Hassine |
| 50 | + * @author Yanming Zhou |
46 | 51 | */ |
| 52 | +@SuppressWarnings("removal") |
47 | 53 | class Jackson2ExecutionContextStringSerializerTests extends AbstractExecutionContextSerializerTests { |
48 | 54 |
|
49 | 55 | private final ExecutionContextSerializer serializer = new Jackson2ExecutionContextStringSerializer( |
@@ -174,6 +180,7 @@ public static class UnmappedDomesticNumber extends UnmappedPhoneNumber { |
174 | 180 | } |
175 | 181 |
|
176 | 182 | @Test |
| 183 | + @SuppressWarnings("unchecked") |
177 | 184 | void arrayAsListSerializationTest() throws IOException { |
178 | 185 | // given |
179 | 186 | List<String> list = Arrays.asList("foo", "bar"); |
@@ -232,4 +239,34 @@ void testJavaTimeLocalDateSerialization() throws IOException { |
232 | 239 | assertEquals(now, deserializedNow); |
233 | 240 | } |
234 | 241 |
|
| 242 | + @Test |
| 243 | + void testJobParametersSerialization() throws IOException { |
| 244 | + // given |
| 245 | + Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer(); |
| 246 | + LocalDate now = LocalDate.now(); |
| 247 | + JobParameters jobParameters = new JobParametersBuilder() |
| 248 | + .addJobParameter("date", LocalDate.now(), LocalDate.class) |
| 249 | + .addJobParameter("foo", "bar", String.class, false) |
| 250 | + .toJobParameters(); |
| 251 | + Map<String, Object> map = new HashMap<>(); |
| 252 | + map.put("jobParameters", jobParameters); |
| 253 | + |
| 254 | + // when |
| 255 | + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| 256 | + serializer.serialize(map, outputStream); |
| 257 | + InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); |
| 258 | + Map<String, Object> deserializedContext = serializer.deserialize(inputStream); |
| 259 | + |
| 260 | + // then |
| 261 | + JobParameters deserializedJobParameters = (JobParameters) deserializedContext.get("jobParameters"); |
| 262 | + JobParameter<?> dateJobParameter = deserializedJobParameters.getParameter("date"); |
| 263 | + assertNotNull(dateJobParameter); |
| 264 | + assertEquals(now, dateJobParameter.value()); |
| 265 | + assertTrue(dateJobParameter.identifying()); |
| 266 | + JobParameter<?> fooJobParameter = deserializedJobParameters.getParameter("foo"); |
| 267 | + assertNotNull(fooJobParameter); |
| 268 | + assertEquals("bar", fooJobParameter.value()); |
| 269 | + assertFalse(fooJobParameter.identifying()); |
| 270 | + } |
| 271 | + |
235 | 272 | } |
0 commit comments