50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
|
|
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"));
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|