BAEL-4706 - Spring Boot with Spring Batch (#10292)
Co-authored-by: Jonathan Cook <jcook@sciops.esa.int>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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 org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
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.context.annotation.PropertySource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@SpringBatchTest
|
||||
@SpringBootTest
|
||||
@DirtiesContext
|
||||
@PropertySource("classpath:application.properties")
|
||||
@RunWith(SpringRunner.class)
|
||||
public class SpringBootBatchIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Autowired
|
||||
private JobRepositoryTestUtils jobRepositoryTestUtils;
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
jobRepositoryTestUtils.removeJobExecutions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCoffeeList_whenJobExecuted_thenSuccess() throws Exception {
|
||||
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
|
||||
JobInstance jobInstance = jobExecution.getJobInstance();
|
||||
ExitStatus jobExitStatus = jobExecution.getExitStatus();
|
||||
|
||||
assertThat(jobInstance.getJobName(), is("importUserJob"));
|
||||
assertThat(jobExitStatus.getExitCode(), is("COMPLETED"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user