Commit 474ab7f6 authored by Stephane Nicoll's avatar Stephane Nicoll

Adapt tests to deprecations in Spring Batch

parent 28b0f64e
/*
* 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 {
......
/*
* 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();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment