|
| 1 | +/* |
| 2 | + * Copyright 2026-present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.batch.core.repository.support; |
| 17 | + |
| 18 | +import java.sql.Connection; |
| 19 | + |
| 20 | +import javax.sql.DataSource; |
| 21 | + |
| 22 | +import org.apache.commons.dbcp2.BasicDataSource; |
| 23 | +import org.junit.jupiter.api.AfterEach; |
| 24 | +import org.junit.jupiter.api.BeforeEach; |
| 25 | + |
| 26 | +import org.springframework.batch.core.configuration.annotation.EnableJdbcJobRepository; |
| 27 | +import org.springframework.beans.factory.annotation.Autowired; |
| 28 | +import org.springframework.context.annotation.Bean; |
| 29 | +import org.springframework.context.annotation.Configuration; |
| 30 | +import org.springframework.core.io.FileSystemResource; |
| 31 | +import org.springframework.jdbc.datasource.init.ScriptUtils; |
| 32 | +import org.springframework.jdbc.support.JdbcTransactionManager; |
| 33 | +import org.springframework.test.annotation.DirtiesContext; |
| 34 | +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; |
| 35 | + |
| 36 | +/** |
| 37 | + * Repository tests using JDBC DAOs and legacy schema. |
| 38 | + * |
| 39 | + * @author Thomas Risberg |
| 40 | + * @author Mahmoud Ben Hassine |
| 41 | + **/ |
| 42 | +@SpringJUnitConfig |
| 43 | +@DirtiesContext |
| 44 | +public class JdbcJobRepositoryLegacySchemaIntegrationTests extends AbstractJobRepositoryIntegrationTests { |
| 45 | + |
| 46 | + @Autowired |
| 47 | + private DataSource dataSource; |
| 48 | + |
| 49 | + @BeforeEach |
| 50 | + public void setUp() throws Exception { |
| 51 | + try (Connection connection = dataSource.getConnection()) { |
| 52 | + ScriptUtils.executeSqlScript(connection, |
| 53 | + new FileSystemResource("src/test/resources/schema-hsqldb-legacy.sql")); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @AfterEach |
| 58 | + public void cleanUp() throws Exception { |
| 59 | + try (Connection connection = dataSource.getConnection()) { |
| 60 | + ScriptUtils.executeSqlScript(connection, |
| 61 | + new FileSystemResource("src/test/resources/schema-drop-hsqldb-legacy.sql")); |
| 62 | + } |
| 63 | + System.clearProperty("spring.batch.jdbc.schema.legacy"); |
| 64 | + } |
| 65 | + |
| 66 | + @Configuration |
| 67 | + @EnableJdbcJobRepository |
| 68 | + static class JdbcJobRepositoryLegacyTestConfiguration { |
| 69 | + |
| 70 | + @Bean |
| 71 | + public DataSource dataSource() { |
| 72 | + BasicDataSource dataSource = new BasicDataSource(); |
| 73 | + dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); |
| 74 | + dataSource.setUrl("jdbc:hsqldb:mem:test;sql.enforce_strict_size=true;hsqldb.tx=mvcc"); |
| 75 | + dataSource.setUsername("sa"); |
| 76 | + dataSource.setPassword(""); |
| 77 | + return dataSource; |
| 78 | + } |
| 79 | + |
| 80 | + @Bean |
| 81 | + public JdbcTransactionManager transactionManager(DataSource dataSource) { |
| 82 | + return new JdbcTransactionManager(dataSource); |
| 83 | + } |
| 84 | + |
| 85 | + @Bean |
| 86 | + public JdbcJobRepositoryFactoryBean jobRepository(DataSource dataSource, |
| 87 | + JdbcTransactionManager transactionManager) throws Exception { |
| 88 | + System.setProperty("spring.batch.jdbc.schema.legacy", "true"); |
| 89 | + JdbcJobRepositoryFactoryBean jobRepositoryFactoryBean = new JdbcJobRepositoryFactoryBean(); |
| 90 | + jobRepositoryFactoryBean.setDataSource(dataSource); |
| 91 | + jobRepositoryFactoryBean.setTransactionManager(transactionManager); |
| 92 | + return jobRepositoryFactoryBean; |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments