JAVA-18609 GitHub Issue: Spring Batch - JobBuilderFactory and StepBui… (#13618)
* JAVA-18609 GitHub Issue: Spring Batch - JobBuilderFactory and StepBuilderFactory are deprecated --------- Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
+15
-12
@@ -1,11 +1,10 @@
|
||||
package com.baeldung.batch;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
@@ -13,16 +12,17 @@ import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.batch.test.JobRepositoryTestUtils;
|
||||
import org.springframework.batch.test.context.SpringBatchTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
@SpringBatchTest
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
@SpringJUnitConfig(BatchConfiguration.class)
|
||||
@PropertySource("classpath:application.properties")
|
||||
@RunWith(SpringRunner.class)
|
||||
@EnableAutoConfiguration
|
||||
public class SpringBootBatchIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -31,7 +31,10 @@ public class SpringBootBatchIntegrationTest {
|
||||
@Autowired
|
||||
private JobRepositoryTestUtils jobRepositoryTestUtils;
|
||||
|
||||
@After
|
||||
@MockBean
|
||||
private JobCompletionNotificationListener jobCompletionNotificationListener;
|
||||
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
jobRepositoryTestUtils.removeJobExecutions();
|
||||
}
|
||||
@@ -42,8 +45,8 @@ public class SpringBootBatchIntegrationTest {
|
||||
JobInstance jobInstance = jobExecution.getJobInstance();
|
||||
ExitStatus jobExitStatus = jobExecution.getExitStatus();
|
||||
|
||||
assertThat(jobInstance.getJobName(), is("importUserJob"));
|
||||
assertThat(jobExitStatus.getExitCode(), is("COMPLETED"));
|
||||
assertEquals("importUserJob", jobInstance.getJobName());
|
||||
assertEquals("COMPLETED", jobExitStatus.getExitCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-19
@@ -1,28 +1,20 @@
|
||||
package com.baeldung.batchscheduler;
|
||||
|
||||
import com.baeldung.batchscheduler.SpringBatchScheduler;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.test.context.SpringBatchTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@SpringBatchTest
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
@PropertySource("classpath:application.properties")
|
||||
@RunWith(SpringRunner.class)
|
||||
public class SpringBatchSchedulerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -31,37 +23,36 @@ public class SpringBatchSchedulerIntegrationTest {
|
||||
@Test
|
||||
public void stopJobsWhenSchedulerDisabled() {
|
||||
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
|
||||
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
await().untilAsserted(() -> assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get()));
|
||||
schedulerBean.stop();
|
||||
await().atLeast(3, SECONDS);
|
||||
|
||||
Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get());
|
||||
assertEquals(2, schedulerBean.getBatchRunCounter().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopJobSchedulerWhenSchedulerDestroyed() throws Exception {
|
||||
public void stopJobSchedulerWhenSchedulerDestroyed() {
|
||||
ScheduledAnnotationBeanPostProcessor bean = context.getBean(ScheduledAnnotationBeanPostProcessor.class);
|
||||
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
|
||||
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
await().untilAsserted(() -> assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get()));
|
||||
bean.postProcessBeforeDestruction(schedulerBean, "SpringBatchScheduler");
|
||||
await().atLeast(3, SECONDS);
|
||||
|
||||
Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopJobSchedulerWhenFutureTasksCancelled() throws Exception {
|
||||
public void stopJobSchedulerWhenFutureTasksCancelled() {
|
||||
SpringBatchScheduler schedulerBean = context.getBean(SpringBatchScheduler.class);
|
||||
await().untilAsserted(() -> Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
await().untilAsserted(() -> assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get()));
|
||||
schedulerBean.cancelFutureSchedulerTasks();
|
||||
await().atLeast(3, SECONDS);
|
||||
|
||||
Assert.assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
assertEquals(2, schedulerBean.getBatchRunCounter()
|
||||
.get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user