|
28 | 28 | import org.springframework.batch.core.JobKeyGenerator;
|
29 | 29 | import org.springframework.batch.core.configuration.JobRegistry;
|
30 | 30 | import org.springframework.batch.core.configuration.support.JobRegistrySmartInitializingSingleton;
|
| 31 | +import org.springframework.batch.core.converter.DefaultJobParametersConverter; |
| 32 | +import org.springframework.batch.core.converter.JobParametersConverter; |
| 33 | +import org.springframework.batch.core.converter.JsonJobParametersConverter; |
31 | 34 | import org.springframework.batch.core.explore.JobExplorer;
|
32 | 35 | import org.springframework.batch.core.launch.JobLauncher;
|
33 | 36 | import org.springframework.batch.core.launch.JobOperator;
|
@@ -204,6 +207,31 @@ public void testCustomJobKeyGeneratorConfiguration() {
|
204 | 207 | jobKeyGenerator.getClass());
|
205 | 208 | }
|
206 | 209 |
|
| 210 | + @Test |
| 211 | + @DisplayName("When no JobParametersConverter is provided the default implementation should be used") |
| 212 | + public void testDefaultJobParametersConverterConfiguration() { |
| 213 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JobConfiguration.class); |
| 214 | + |
| 215 | + JobOperator jobOperator = context.getBean(JobOperator.class); |
| 216 | + JobParametersConverter jobParametersConverter = (JobParametersConverter) ReflectionTestUtils |
| 217 | + .getField(jobOperator, "jobParametersConverter"); |
| 218 | + |
| 219 | + Assertions.assertEquals(DefaultJobParametersConverter.class, jobParametersConverter.getClass()); |
| 220 | + } |
| 221 | + |
| 222 | + @Test |
| 223 | + @DisplayName("When a custom JobParametersConverter implementation is found then it should be used") |
| 224 | + public void testCustomJobParametersConverterConfiguration() { |
| 225 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( |
| 226 | + CustomJobParametersConverterConfiguration.class); |
| 227 | + |
| 228 | + JobOperator jobOperator = context.getBean(JobOperator.class); |
| 229 | + JobParametersConverter jobParametersConverter = (JobParametersConverter) ReflectionTestUtils |
| 230 | + .getField(jobOperator, "jobParametersConverter"); |
| 231 | + |
| 232 | + Assertions.assertEquals(JsonJobParametersConverter.class, jobParametersConverter.getClass()); |
| 233 | + } |
| 234 | + |
207 | 235 | @Configuration
|
208 | 236 | @EnableBatchProcessing
|
209 | 237 | public static class JobConfigurationWithoutDataSource {
|
@@ -328,6 +356,30 @@ public String generateKey(Object source) {
|
328 | 356 |
|
329 | 357 | }
|
330 | 358 |
|
| 359 | + @Configuration |
| 360 | + @EnableBatchProcessing |
| 361 | + public static class CustomJobParametersConverterConfiguration { |
| 362 | + |
| 363 | + @Bean |
| 364 | + public DataSource dataSource() { |
| 365 | + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL) |
| 366 | + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") |
| 367 | + .generateUniqueName(true) |
| 368 | + .build(); |
| 369 | + } |
| 370 | + |
| 371 | + @Bean |
| 372 | + public JdbcTransactionManager transactionManager(DataSource dataSource) { |
| 373 | + return new JdbcTransactionManager(dataSource); |
| 374 | + } |
| 375 | + |
| 376 | + @Bean |
| 377 | + public JobParametersConverter jobParametersConverter() { |
| 378 | + return new JsonJobParametersConverter(); |
| 379 | + } |
| 380 | + |
| 381 | + } |
| 382 | + |
331 | 383 | private PlatformTransactionManager getTransactionManagerSetOnJobRepository(JobRepository jobRepository) {
|
332 | 384 | Advised target = (Advised) jobRepository; // proxy created by
|
333 | 385 | // AbstractJobRepositoryFactoryBean
|
|
0 commit comments