From 474ab7f69c68b9643f08ff9b6df895204ac3690b Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 16 Sep 2020 15:22:32 +0200 Subject: [PATCH] Adapt tests to deprecations in Spring Batch --- .../batch/BatchAutoConfigurationTests.java | 53 +------------------ .../JobLauncherApplicationRunnerTests.java | 10 ++-- 2 files changed, 6 insertions(+), 57 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index 3258f3d3c0..a00dfca3d0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -35,13 +35,9 @@ import org.springframework.batch.core.configuration.annotation.BatchConfigurer; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor; import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; import org.springframework.batch.core.job.AbstractJob; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.DefaultApplicationArguments; @@ -105,15 +101,6 @@ class BatchAutoConfigurationTests { .run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class)); } - @Test - void testCustomConfigurationWithNoDatabase() { - this.contextRunner.withUserConfiguration(TestCustomConfiguration.class).run((context) -> { - assertThat(context).hasSingleBean(JobLauncher.class); - JobExplorer explorer = context.getBean(JobExplorer.class); - assertThat(explorer.getJobInstances("job", 0, 100)).isEmpty(); - }); - } - @Test void testNoBatchConfiguration() { this.contextRunner.withUserConfiguration(EmptyConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -319,44 +306,6 @@ class BatchAutoConfigurationTests { } - @EnableBatchProcessing - @TestAutoConfigurationPackage(City.class) - static class TestCustomConfiguration implements BatchConfigurer { - - private JobRepository jobRepository; - - private MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); - - @Override - public JobRepository getJobRepository() throws Exception { - if (this.jobRepository == null) { - this.factory.afterPropertiesSet(); - this.jobRepository = this.factory.getObject(); - } - return this.jobRepository; - } - - @Override - public PlatformTransactionManager getTransactionManager() { - return new ResourcelessTransactionManager(); - } - - @Override - public JobLauncher getJobLauncher() { - SimpleJobLauncher launcher = new SimpleJobLauncher(); - launcher.setJobRepository(this.jobRepository); - return launcher; - } - - @Override - public JobExplorer getJobExplorer() throws Exception { - MapJobExplorerFactoryBean explorer = new MapJobExplorerFactoryBean(this.factory); - explorer.afterPropertiesSet(); - return explorer.getObject(); - } - - } - @Configuration(proxyBeanMethods = false) @EnableBatchProcessing static class NamedJobConfigurationWithRegisteredJob { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java index 2fd44b4408..385b86b3ac 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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,13 +31,11 @@ import org.springframework.batch.core.configuration.annotation.EnableBatchProces import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -201,13 +199,14 @@ class JobLauncherApplicationRunnerTests { @Configuration(proxyBeanMethods = false) @EnableBatchProcessing + @SuppressWarnings("deprecation") static class BatchConfiguration implements BatchConfigurer { private ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager(); private JobRepository jobRepository; - private MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean( + private org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean jobRepositoryFactory = new org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean( this.transactionManager); BatchConfiguration() throws Exception { @@ -238,7 +237,8 @@ class JobLauncherApplicationRunnerTests { @Override public JobExplorer getJobExplorer() throws Exception { - return new MapJobExplorerFactoryBean(this.jobRepositoryFactory).getObject(); + return new org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean( + this.jobRepositoryFactory).getObject(); } }