|
26 | 26 | import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
|
27 | 27 | import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
28 | 28 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
| 29 | +import org.springframework.batch.core.job.Job; |
| 30 | +import org.springframework.batch.core.job.builder.JobBuilder; |
| 31 | +import org.springframework.batch.core.step.builder.StepBuilder; |
| 32 | +import org.springframework.batch.core.configuration.JobRegistry; |
| 33 | +import org.springframework.batch.core.configuration.support.MapJobRegistry; |
| 34 | +import org.springframework.batch.core.repository.JobRepository; |
| 35 | +import org.springframework.boot.batch.autoconfigure.BatchProperties; |
| 36 | +import org.springframework.batch.repeat.RepeatStatus; |
| 37 | +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; |
| 38 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
29 | 39 | import org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner;
|
30 | 40 | import org.springframework.cloud.task.batch.listener.TaskBatchExecutionListenerTests;
|
| 41 | +import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration; |
| 42 | +import org.springframework.context.annotation.Bean; |
| 43 | +import org.springframework.context.annotation.Configuration; |
| 44 | +import org.springframework.batch.support.transaction.ResourcelessTransactionManager; |
| 45 | +import org.springframework.transaction.PlatformTransactionManager; |
31 | 46 | import org.springframework.test.util.ReflectionTestUtils;
|
32 | 47 |
|
33 | 48 | import static org.assertj.core.api.Assertions.assertThat;
|
34 | 49 |
|
35 | 50 | /**
|
36 | 51 | * @author Glenn Renfro
|
37 | 52 | */
|
38 |
| -@Disabled("Tests can not fined TaskRepository") |
39 | 53 | public class TaskJobLauncherAutoConfigurationTests {
|
40 | 54 |
|
41 | 55 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
42 |
| - .withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class)) |
43 |
| - .withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class, |
44 |
| - PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class); |
| 56 | + .withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class, |
| 57 | + PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class, |
| 58 | + SimpleTaskAutoConfiguration.class)) |
| 59 | + .withUserConfiguration(TestJobConfiguration.class); |
45 | 60 |
|
46 | 61 | @Test
|
47 | 62 | public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
|
@@ -92,9 +107,41 @@ private void validateJobNames(AssertableApplicationContext context, String jobNa
|
92 | 107 | @Test
|
93 | 108 | public void testAutoBuiltDataSourceWithTaskJobLauncherCLRDisabled() {
|
94 | 109 | this.contextRunner.run(context -> {
|
95 |
| - assertThat(context).hasSingleBean(JobLauncherApplicationRunner.class); |
| 110 | + // assertThat(context).hasSingleBean(JobLauncherApplicationRunner.class); |
96 | 111 | assertThat(context).doesNotHaveBean(TaskJobLauncherApplicationRunner.class);
|
97 | 112 | });
|
98 | 113 | }
|
99 | 114 |
|
| 115 | + @Configuration |
| 116 | + @EnableAutoConfiguration |
| 117 | + @EnableBatchProcessing |
| 118 | + static class TestJobConfiguration { |
| 119 | + |
| 120 | + @Bean |
| 121 | + public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) { |
| 122 | + return new JobBuilder("job", jobRepository) |
| 123 | + .start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> { |
| 124 | + System.out.println("Executed"); |
| 125 | + return RepeatStatus.FINISHED; |
| 126 | + }, transactionManager).build()) |
| 127 | + .build(); |
| 128 | + } |
| 129 | + |
| 130 | + @Bean |
| 131 | + PlatformTransactionManager transactionManager() { |
| 132 | + return new ResourcelessTransactionManager(); |
| 133 | + } |
| 134 | + |
| 135 | + @Bean |
| 136 | + JobRegistry jobRegistry() { |
| 137 | + return new MapJobRegistry(); |
| 138 | + } |
| 139 | + |
| 140 | + @Bean |
| 141 | + BatchProperties batchProperties() { |
| 142 | + return new BatchProperties(); |
| 143 | + } |
| 144 | + |
| 145 | + } |
| 146 | + |
100 | 147 | }
|
0 commit comments