Implement default methods in SimpleJobRepository

Resolves #4229
This commit is contained in:
Mahmoud Ben Hassine
2022-11-16 15:34:08 +01:00
parent 05bbd3f7ea
commit 930bb0243c
5 changed files with 67 additions and 15 deletions

View File

@@ -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"));
}
}

View File

@@ -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

View File

@@ -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