@@ -87,6 +87,21 @@ public class SimpleJobRepository implements JobRepository {
|
||||
this.ecDao = ecDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getJobNames() {
|
||||
return this.jobInstanceDao.getJobNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobInstance> findJobInstancesByName(String jobName, int start, int count) {
|
||||
return this.jobInstanceDao.findJobInstancesByName(jobName, start, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobExecution> findJobExecutions(JobInstance jobInstance) {
|
||||
return this.jobExecutionDao.findJobExecutions(jobInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJobInstanceExists(String jobName, JobParameters jobParameters) {
|
||||
return jobInstanceDao.getJobInstance(jobName, jobParameters) != null;
|
||||
|
||||
@@ -130,6 +130,38 @@ class SimpleJobRepositoryTests {
|
||||
jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetJobNames() {
|
||||
// when
|
||||
this.jobRepository.getJobNames();
|
||||
|
||||
// then
|
||||
verify(this.jobInstanceDao).getJobNames();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindJobInstancesByName() {
|
||||
// given
|
||||
String jobName = "job";
|
||||
int start = 1;
|
||||
int count = 10;
|
||||
|
||||
// when
|
||||
this.jobRepository.findJobInstancesByName(jobName, start, count);
|
||||
|
||||
// then
|
||||
verify(this.jobInstanceDao).findJobInstancesByName(jobName, start, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindJobExecutions() {
|
||||
// when
|
||||
this.jobRepository.findJobExecutions(this.jobInstance);
|
||||
|
||||
// then
|
||||
verify(this.jobExecutionDao).findJobExecutions(this.jobInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveOrUpdateInvalidJobExecution() {
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,6 +23,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
@@ -37,6 +35,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
@@ -133,4 +133,18 @@ class JobRepositoryTestUtilsTests {
|
||||
assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveJobExecutions() throws Exception {
|
||||
// given
|
||||
utils = new JobRepositoryTestUtils(jobRepository);
|
||||
utils.createJobExecutions("foo", new String[] {}, 2);
|
||||
assertEquals(2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION"));
|
||||
|
||||
// when
|
||||
utils.removeJobExecutions();
|
||||
|
||||
// then
|
||||
assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
package org.springframework.batch.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -69,11 +69,6 @@ public class SpringBatchTestJUnit4Tests {
|
||||
@Autowired
|
||||
private ItemReader<String> jobScopedItemReader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.jobRepositoryTestUtils.removeJobExecutions();
|
||||
}
|
||||
|
||||
public StepExecution getStepExecution() {
|
||||
StepExecution execution = MetaDataInstanceFactory.createStepExecution();
|
||||
execution.getExecutionContext().putString("input.data", "foo,bar");
|
||||
@@ -103,6 +98,7 @@ public class SpringBatchTestJUnit4Tests {
|
||||
@Test
|
||||
public void testJob() throws Exception {
|
||||
// when
|
||||
this.jobRepositoryTestUtils.removeJobExecutions();
|
||||
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
|
||||
|
||||
// then
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Arrays;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
@@ -70,11 +69,6 @@ public class SpringBatchTestJUnit5Tests {
|
||||
@Autowired
|
||||
private ItemReader<String> jobScopedItemReader;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.jobRepositoryTestUtils.removeJobExecutions();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStepScopedItemReader() throws Exception {
|
||||
assertEquals("foo", this.stepScopedItemReader.read());
|
||||
@@ -92,6 +86,7 @@ public class SpringBatchTestJUnit5Tests {
|
||||
@Test
|
||||
void testJob() throws Exception {
|
||||
// given
|
||||
this.jobRepositoryTestUtils.removeJobExecutions();
|
||||
JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters();
|
||||
|
||||
// when
|
||||
|
||||
Reference in New Issue
Block a user