Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.springframework.batch.core.job.JobInstance;
import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.job.parameters.JobParametersBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.StepExecution;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.batch.core.launch.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.infrastructure.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -43,21 +42,17 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Repository tests using JDBC DAOs (rather than mocks).
* Abstract repository tests using DAOs (rather than mocks).
*
* @author Robert Kasanicky
* @author Dimitrios Liapis
* @author Mahmoud Ben Hassine
* @author Yanming Zhou
*/
// TODO rename to JdbcJobRepositoryIntegrationTests and update to new domain model
// TODO should add a mongodb similar test suite
@Disabled
@SpringJUnitConfig(locations = "/org/springframework/batch/core/repository/dao/jdbc/sql-dao-test.xml")
class SimpleJobRepositoryIntegrationTests {
abstract class AbstractJobRepositoryIntegrationTests {

@Autowired
private SimpleJobRepository jobRepository;
private JobRepository jobRepository;

private final JobSupport job = new JobSupport("SimpleJobRepositoryIntegrationTestsJob");

Expand All @@ -67,9 +62,8 @@ class SimpleJobRepositoryIntegrationTests {
* Create two job executions for same job+parameters tuple. Check both executions
* belong to the same job instance and job.
*/
@Transactional
@Test
void testCreateAndFind() throws Exception {
void testCreateAndFind() {

job.setRestartable(true);

Expand All @@ -81,7 +75,7 @@ void testCreateAndFind() throws Exception {
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
JobExecution firstExecution = jobRepository.createJobExecution(jobInstance, jobParameters, executionContext);
firstExecution.setStartTime(LocalDateTime.now());
assertNotNull(firstExecution.getLastUpdated());
assertNull(firstExecution.getLastUpdated());

assertEquals(job.getName(), firstExecution.getJobInstance().getJobName());

Expand All @@ -99,9 +93,8 @@ void testCreateAndFind() throws Exception {
* Create two job executions for same job+parameters tuple. Check both executions
* belong to the same job instance and job.
*/
@Transactional
@Test
void testCreateAndFindWithNoStartDate() throws Exception {
void testCreateAndFindWithNoStartDate() {
job.setRestartable(true);

JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
Expand All @@ -123,7 +116,6 @@ void testCreateAndFindWithNoStartDate() throws Exception {
* Save multiple StepExecutions for the same step and check the returned count and
* last execution are correct.
*/
@Transactional
@Test
void testGetStepExecutionCountAndLastStepExecution() throws Exception {
job.setRestartable(true);
Expand Down Expand Up @@ -161,9 +153,8 @@ void testGetStepExecutionCountAndLastStepExecution() throws Exception {
/*
* Save execution context and retrieve it.
*/
@Transactional
@Test
void testSaveExecutionContext() throws Exception {
void testSaveExecutionContext() {
ExecutionContext ctx = new ExecutionContext(Map.of("crashedPosition", 7));
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
JobExecution jobExec = jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext());
Expand All @@ -188,9 +179,9 @@ void testSaveExecutionContext() throws Exception {
* If JobExecution is already running, exception will be thrown in attempt to create
* new execution.
*/
@Transactional
@Test
void testOnlyOneJobExecutionAllowedRunning() throws Exception {
@Disabled("JobExecutionAlreadyRunningException is not thrown at repository level")
void testOnlyOneJobExecutionAllowedRunning() {
job.setRestartable(true);
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
JobExecution jobExecution = jobRepository.createJobExecution(jobInstance, jobParameters,
Expand All @@ -204,7 +195,6 @@ void testOnlyOneJobExecutionAllowedRunning() throws Exception {
() -> jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext()));
}

@Transactional
@Test
void testGetLastJobExecution() throws Exception {
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
Expand All @@ -225,9 +215,8 @@ void testGetLastJobExecution() throws Exception {
* Create two job executions for the same job+parameters tuple. Should ignore
* non-identifying job parameters when identifying the job instance.
*/
@Transactional
@Test
void testReExecuteWithSameJobParameters() throws Exception {
void testReExecuteWithSameJobParameters() {
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo", false).toJobParameters();
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
JobExecution jobExecution1 = jobRepository.createJobExecution(jobInstance, jobParameters,
Expand All @@ -245,9 +234,9 @@ void testReExecuteWithSameJobParameters() throws Exception {
* When a job execution is running, JobExecutionAlreadyRunningException should be
* thrown if trying to create any other ones with same job parameters.
*/
@Transactional
@Test
void testReExecuteWithSameJobParametersWhenRunning() throws Exception {
@Disabled("JobExecutionAlreadyRunningException is not thrown at repository level")
void testReExecuteWithSameJobParametersWhenRunning() {
JobParameters jobParameters = new JobParametersBuilder().addString("stringKey", "stringValue")
.toJobParameters();

Expand All @@ -272,9 +261,8 @@ void testReExecuteWithSameJobParametersWhenRunning() throws Exception {
() -> jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext()));
}

@Transactional
@Test
void testDeleteJobInstance() throws Exception {
void testDeleteJobInstance() {
var jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
var jobExecution = jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2008-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.repository.support;

import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import javax.sql.DataSource;
import java.sql.Connection;

/**
* Repository tests using JDBC DAOs (rather than mocks).
*
* @author Yanming Zhou
**/
@SpringJUnitConfig(locations = "/org/springframework/batch/core/repository/dao/jdbc/sql-dao-test.xml")
public class JdbcJobRepositoryIntegrationTests extends AbstractJobRepositoryIntegrationTests {

@Autowired
private DataSource dataSource;

@BeforeEach
public void setUp() throws Exception {
try (Connection connection = dataSource.getConnection()) {
ScriptUtils.executeSqlScript(connection,
new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-drop-hsqldb.sql"));
ScriptUtils.executeSqlScript(connection,
new FileSystemResource("src/main/resources/org/springframework/batch/core/schema-hsqldb.sql"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

/**
* Repository tests using MongoDB DAOs (rather than mocks).
*
* @author Mahmoud Ben Hassine
* @author Yanming Zhou
*/
@DirtiesContext
@Testcontainers(disabledWithoutDocker = true)
@SpringJUnitConfig(MongoDBIntegrationTestConfiguration.class)
public class MongoDBJobRepositoryIntegrationTests {
public class MongoDBJobRepositoryIntegrationTests extends AbstractJobRepositoryIntegrationTests {

@Autowired
private MongoTemplate mongoTemplate;
Expand Down