2222import org .springframework .batch .core .job .JobInstance ;
2323import org .springframework .batch .core .job .parameters .JobParameters ;
2424import org .springframework .batch .core .job .parameters .JobParametersBuilder ;
25+ import org .springframework .batch .core .repository .JobRepository ;
2526import org .springframework .batch .core .step .Step ;
2627import org .springframework .batch .core .step .StepExecution ;
2728import org .springframework .batch .core .job .JobSupport ;
2829import org .springframework .batch .core .launch .JobExecutionAlreadyRunningException ;
2930import org .springframework .batch .core .step .StepSupport ;
3031import org .springframework .batch .infrastructure .item .ExecutionContext ;
3132import org .springframework .beans .factory .annotation .Autowired ;
32- import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
33- import org .springframework .transaction .annotation .Transactional ;
3433
3534import java .time .LocalDateTime ;
3635import java .time .temporal .ChronoUnit ;
4342import static org .junit .jupiter .api .Assertions .assertThrows ;
4443
4544/**
46- * Repository tests using JDBC DAOs (rather than mocks).
45+ * Abstract repository tests using DAOs (rather than mocks).
4746 *
4847 * @author Robert Kasanicky
4948 * @author Dimitrios Liapis
5049 * @author Mahmoud Ben Hassine
5150 * @author Yanming Zhou
5251 */
53- // TODO rename to JdbcJobRepositoryIntegrationTests and update to new domain model
54- // TODO should add a mongodb similar test suite
55- @ SpringJUnitConfig (locations = "/org/springframework/batch/core/repository/dao/jdbc/sql-dao-test.xml" )
56- class SimpleJobRepositoryIntegrationTests {
52+ abstract class AbstractJobRepositoryIntegrationTests {
5753
5854 @ Autowired
59- private SimpleJobRepository jobRepository ;
55+ private JobRepository jobRepository ;
6056
6157 private final JobSupport job = new JobSupport ("SimpleJobRepositoryIntegrationTestsJob" );
6258
@@ -66,9 +62,8 @@ class SimpleJobRepositoryIntegrationTests {
6662 * Create two job executions for same job+parameters tuple. Check both executions
6763 * belong to the same job instance and job.
6864 */
69- @ Transactional
7065 @ Test
71- void testCreateAndFind () throws Exception {
66+ void testCreateAndFind () {
7267
7368 job .setRestartable (true );
7469
@@ -98,9 +93,8 @@ void testCreateAndFind() throws Exception {
9893 * Create two job executions for same job+parameters tuple. Check both executions
9994 * belong to the same job instance and job.
10095 */
101- @ Transactional
10296 @ Test
103- void testCreateAndFindWithNoStartDate () throws Exception {
97+ void testCreateAndFindWithNoStartDate () {
10498 job .setRestartable (true );
10599
106100 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
@@ -122,7 +116,6 @@ void testCreateAndFindWithNoStartDate() throws Exception {
122116 * Save multiple StepExecutions for the same step and check the returned count and
123117 * last execution are correct.
124118 */
125- @ Transactional
126119 @ Test
127120 void testGetStepExecutionCountAndLastStepExecution () throws Exception {
128121 job .setRestartable (true );
@@ -160,9 +153,8 @@ void testGetStepExecutionCountAndLastStepExecution() throws Exception {
160153 /*
161154 * Save execution context and retrieve it.
162155 */
163- @ Transactional
164156 @ Test
165- void testSaveExecutionContext () throws Exception {
157+ void testSaveExecutionContext () {
166158 ExecutionContext ctx = new ExecutionContext (Map .of ("crashedPosition" , 7 ));
167159 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
168160 JobExecution jobExec = jobRepository .createJobExecution (jobInstance , jobParameters , new ExecutionContext ());
@@ -187,10 +179,9 @@ void testSaveExecutionContext() throws Exception {
187179 * If JobExecution is already running, exception will be thrown in attempt to create
188180 * new execution.
189181 */
190- @ Transactional
191182 @ Test
192183 @ Disabled ("JobExecutionAlreadyRunningException is not thrown at repository level" )
193- void testOnlyOneJobExecutionAllowedRunning () throws Exception {
184+ void testOnlyOneJobExecutionAllowedRunning () {
194185 job .setRestartable (true );
195186 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
196187 JobExecution jobExecution = jobRepository .createJobExecution (jobInstance , jobParameters ,
@@ -204,7 +195,6 @@ void testOnlyOneJobExecutionAllowedRunning() throws Exception {
204195 () -> jobRepository .createJobExecution (jobInstance , jobParameters , new ExecutionContext ()));
205196 }
206197
207- @ Transactional
208198 @ Test
209199 void testGetLastJobExecution () throws Exception {
210200 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
@@ -225,9 +215,8 @@ void testGetLastJobExecution() throws Exception {
225215 * Create two job executions for the same job+parameters tuple. Should ignore
226216 * non-identifying job parameters when identifying the job instance.
227217 */
228- @ Transactional
229218 @ Test
230- void testReExecuteWithSameJobParameters () throws Exception {
219+ void testReExecuteWithSameJobParameters () {
231220 JobParameters jobParameters = new JobParametersBuilder ().addString ("name" , "foo" , false ).toJobParameters ();
232221 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
233222 JobExecution jobExecution1 = jobRepository .createJobExecution (jobInstance , jobParameters ,
@@ -245,10 +234,9 @@ void testReExecuteWithSameJobParameters() throws Exception {
245234 * When a job execution is running, JobExecutionAlreadyRunningException should be
246235 * thrown if trying to create any other ones with same job parameters.
247236 */
248- @ Transactional
249237 @ Test
250238 @ Disabled ("JobExecutionAlreadyRunningException is not thrown at repository level" )
251- void testReExecuteWithSameJobParametersWhenRunning () throws Exception {
239+ void testReExecuteWithSameJobParametersWhenRunning () {
252240 JobParameters jobParameters = new JobParametersBuilder ().addString ("stringKey" , "stringValue" )
253241 .toJobParameters ();
254242
@@ -273,9 +261,8 @@ void testReExecuteWithSameJobParametersWhenRunning() throws Exception {
273261 () -> jobRepository .createJobExecution (jobInstance , jobParameters , new ExecutionContext ()));
274262 }
275263
276- @ Transactional
277264 @ Test
278- void testDeleteJobInstance () throws Exception {
265+ void testDeleteJobInstance () {
279266 var jobParameters = new JobParametersBuilder ().addString ("foo" , "bar" ).toJobParameters ();
280267 JobInstance jobInstance = jobRepository .createJobInstance (job .getName (), jobParameters );
281268 var jobExecution = jobRepository .createJobExecution (jobInstance , jobParameters , new ExecutionContext ());
0 commit comments