use of org.springframework.batch.core.repository.JobRepository in project spring-boot by spring-projects.
the class BatchAutoConfigurationTests method testUsingJpa.
@Test
public void testUsingJpa() throws Exception {
this.context = new AnnotationConfigApplicationContext();
// The order is very important here: DataSource -> Hibernate -> Batch
this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class, TransactionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
PlatformTransactionManager transactionManager = this.context.getBean(PlatformTransactionManager.class);
// It's a lazy proxy, but it does render its target if you ask for toString():
assertThat(transactionManager.toString().contains("JpaTransactionManager")).isTrue();
assertThat(this.context.getBean(EntityManagerFactory.class)).isNotNull();
// Ensure the JobRepository can be used (no problem with isolation level)
assertThat(this.context.getBean(JobRepository.class).getLastJobExecution("job", new JobParameters())).isNull();
}
use of org.springframework.batch.core.repository.JobRepository in project spring-boot by spring-projects.
the class BatchAutoConfigurationTests method testDefinesAndLaunchesNamedJob.
@Test
public void testDefinesAndLaunchesNamedJob() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.batch.job.names:discreteRegisteredJob");
this.context.register(NamedJobConfigurationWithRegisteredJob.class, EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class, TransactionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
JobRepository repository = this.context.getBean(JobRepository.class);
assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
this.context.getBean(JobLauncherCommandLineRunner.class).run();
assertThat(repository.getLastJobExecution("discreteRegisteredJob", new JobParameters())).isNotNull();
}
use of org.springframework.batch.core.repository.JobRepository in project spring-boot by spring-projects.
the class BatchAutoConfigurationTests method testRenamePrefix.
@Test
public void testRenamePrefix() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.name:batchtest", "spring.batch.schema:classpath:batch/custom-schema-hsql.sql", "spring.batch.tablePrefix:PREFIX_");
this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, BatchAutoConfiguration.class, TransactionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
assertThat(this.context.getBean(BatchProperties.class).getInitializer().isEnabled()).isTrue();
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)).queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
JobExplorer jobExplorer = this.context.getBean(JobExplorer.class);
assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
JobRepository jobRepository = this.context.getBean(JobRepository.class);
assertThat(jobRepository.getLastJobExecution("test", new JobParameters())).isNull();
}
use of org.springframework.batch.core.repository.JobRepository in project spring-boot by spring-projects.
the class JobLauncherCommandLineRunnerTests method init.
@Before
public void init() throws Exception {
this.context.register(BatchConfiguration.class);
this.context.refresh();
JobRepository jobRepository = this.context.getBean(JobRepository.class);
this.jobLauncher = this.context.getBean(JobLauncher.class);
this.jobs = new JobBuilderFactory(jobRepository);
PlatformTransactionManager transactionManager = this.context.getBean(PlatformTransactionManager.class);
this.steps = new StepBuilderFactory(jobRepository, transactionManager);
this.step = this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return null;
}
}).build();
this.job = this.jobs.get("job").start(this.step).build();
this.jobExplorer = this.context.getBean(JobExplorer.class);
this.runner = new JobLauncherCommandLineRunner(this.jobLauncher, this.jobExplorer);
this.context.getBean(BatchConfiguration.class).clear();
}
Aggregations