Skip to content

Commit 474ab7f

Browse files
committed
Adapt tests to deprecations in Spring Batch
1 parent 28b0f64 commit 474ab7f

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -35,13 +35,9 @@
3535
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
3636
import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor;
3737
import org.springframework.batch.core.explore.JobExplorer;
38-
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
3938
import org.springframework.batch.core.job.AbstractJob;
4039
import org.springframework.batch.core.launch.JobLauncher;
41-
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
4240
import org.springframework.batch.core.repository.JobRepository;
43-
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
44-
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
4541
import org.springframework.beans.factory.annotation.Autowired;
4642
import org.springframework.boot.CommandLineRunner;
4743
import org.springframework.boot.DefaultApplicationArguments;
@@ -105,15 +101,6 @@ void whenThereIsAnEntityManagerFactoryButNoDataSourceAutoConfigurationBacksOff()
105101
.run((context) -> assertThat(context).doesNotHaveBean(BatchConfigurer.class));
106102
}
107103

108-
@Test
109-
void testCustomConfigurationWithNoDatabase() {
110-
this.contextRunner.withUserConfiguration(TestCustomConfiguration.class).run((context) -> {
111-
assertThat(context).hasSingleBean(JobLauncher.class);
112-
JobExplorer explorer = context.getBean(JobExplorer.class);
113-
assertThat(explorer.getJobInstances("job", 0, 100)).isEmpty();
114-
});
115-
}
116-
117104
@Test
118105
void testNoBatchConfiguration() {
119106
this.contextRunner.withUserConfiguration(EmptyConfiguration.class, EmbeddedDataSourceConfiguration.class)
@@ -319,44 +306,6 @@ EntityManagerFactory entityManagerFactory() {
319306

320307
}
321308

322-
@EnableBatchProcessing
323-
@TestAutoConfigurationPackage(City.class)
324-
static class TestCustomConfiguration implements BatchConfigurer {
325-
326-
private JobRepository jobRepository;
327-
328-
private MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
329-
330-
@Override
331-
public JobRepository getJobRepository() throws Exception {
332-
if (this.jobRepository == null) {
333-
this.factory.afterPropertiesSet();
334-
this.jobRepository = this.factory.getObject();
335-
}
336-
return this.jobRepository;
337-
}
338-
339-
@Override
340-
public PlatformTransactionManager getTransactionManager() {
341-
return new ResourcelessTransactionManager();
342-
}
343-
344-
@Override
345-
public JobLauncher getJobLauncher() {
346-
SimpleJobLauncher launcher = new SimpleJobLauncher();
347-
launcher.setJobRepository(this.jobRepository);
348-
return launcher;
349-
}
350-
351-
@Override
352-
public JobExplorer getJobExplorer() throws Exception {
353-
MapJobExplorerFactoryBean explorer = new MapJobExplorerFactoryBean(this.factory);
354-
explorer.afterPropertiesSet();
355-
return explorer.getObject();
356-
}
357-
358-
}
359-
360309
@Configuration(proxyBeanMethods = false)
361310
@EnableBatchProcessing
362311
static class NamedJobConfigurationWithRegisteredJob {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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,13 +31,11 @@
3131
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
3232
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
3333
import org.springframework.batch.core.explore.JobExplorer;
34-
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
3534
import org.springframework.batch.core.launch.JobLauncher;
3635
import org.springframework.batch.core.launch.support.RunIdIncrementer;
3736
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
3837
import org.springframework.batch.core.repository.JobRepository;
3938
import org.springframework.batch.core.repository.JobRestartException;
40-
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
4139
import org.springframework.batch.core.step.tasklet.Tasklet;
4240
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
4341
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -201,13 +199,14 @@ private Tasklet throwingTasklet() {
201199

202200
@Configuration(proxyBeanMethods = false)
203201
@EnableBatchProcessing
202+
@SuppressWarnings("deprecation")
204203
static class BatchConfiguration implements BatchConfigurer {
205204

206205
private ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
207206

208207
private JobRepository jobRepository;
209208

210-
private MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(
209+
private org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean jobRepositoryFactory = new org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean(
211210
this.transactionManager);
212211

213212
BatchConfiguration() throws Exception {
@@ -238,7 +237,8 @@ public JobLauncher getJobLauncher() {
238237

239238
@Override
240239
public JobExplorer getJobExplorer() throws Exception {
241-
return new MapJobExplorerFactoryBean(this.jobRepositoryFactory).getObject();
240+
return new org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean(
241+
this.jobRepositoryFactory).getObject();
242242
}
243243

244244
}

0 commit comments

Comments
 (0)