Add integration tests for PagingQueryProvider
Adds testcontainers based tests for DB2, MySQL, MariaDB, Postgres, Sql Server and Oracle Database, as well as standard tests for HSQL and SQLite.
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
8f1b24a462
commit
b831a7d792
@@ -347,6 +347,84 @@
|
||||
<version>${derby.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>${mysql-connector-j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mysql</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>oracle-xe</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.oracle.database.jdbc</groupId>
|
||||
<artifactId>ojdbc10</artifactId>
|
||||
<version>${oracle.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>${mariadb-java-client.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mariadb</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ibm.db2</groupId>
|
||||
<artifactId>jcc</artifactId>
|
||||
<version>${db2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>db2</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mssqlserver</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>${sqlserver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
abstract class AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
private final AbstractSqlPagingQueryProvider queryProvider;
|
||||
|
||||
AbstractPagingQueryProviderIntegrationTests(DataSource dataSource, AbstractSqlPagingQueryProvider queryProvider) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.queryProvider = queryProvider;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithoutGrouping() {
|
||||
queryProvider.setSelectClause("ID, STRING");
|
||||
queryProvider.setFromClause("TEST_TABLE");
|
||||
Map<String, Order> sortKeys = new HashMap<>();
|
||||
sortKeys.put("ID", Order.ASCENDING);
|
||||
queryProvider.setSortKeys(sortKeys);
|
||||
|
||||
List<Item> firstPage = jdbcTemplate.query(queryProvider.generateFirstPageQuery(2), MAPPER);
|
||||
assertEquals(List.of(new Item(1, "Spring"), new Item(2, "Batch")), firstPage);
|
||||
|
||||
List<Item> secondPage = jdbcTemplate.query(queryProvider.generateRemainingPagesQuery(2), MAPPER, 2);
|
||||
assertEquals(List.of(new Item(3, "Infrastructure")), secondPage);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithGrouping() {
|
||||
queryProvider.setSelectClause("STRING");
|
||||
queryProvider.setFromClause("GROUPING_TEST_TABLE");
|
||||
queryProvider.setGroupClause("STRING");
|
||||
Map<String, Order> sortKeys = new HashMap<>();
|
||||
sortKeys.put("STRING", Order.ASCENDING);
|
||||
queryProvider.setSortKeys(sortKeys);
|
||||
|
||||
List<String> firstPage = jdbcTemplate.queryForList(queryProvider.generateFirstPageQuery(2), String.class);
|
||||
assertEquals(List.of("Batch", "Infrastructure"), firstPage);
|
||||
|
||||
List<String> secondPage = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(2), String.class,
|
||||
"Infrastructure");
|
||||
assertEquals(List.of("Spring"), secondPage);
|
||||
}
|
||||
|
||||
private record Item(Integer id, String string) {
|
||||
}
|
||||
|
||||
private static final RowMapper<Item> MAPPER = (rs, rowNum) -> new Item(rs.getInt("id"), rs.getString("string"));
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.ibm.db2.jcc.DB2SimpleDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.Db2Container;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class Db2PagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName DB2_IMAGE = DockerImageName.parse("ibmcom/db2:11.5.5.1");
|
||||
|
||||
@Container
|
||||
public static Db2Container db2 = new Db2Container(DB2_IMAGE).acceptLicense();
|
||||
|
||||
Db2PagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new Db2PagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
DB2SimpleDataSource dataSource = new DB2SimpleDataSource();
|
||||
dataSource.setDatabaseName(db2.getDatabaseName());
|
||||
dataSource.setUser(db2.getUsername());
|
||||
dataSource.setPassword(db2.getPassword());
|
||||
dataSource.setDriverType(4);
|
||||
dataSource.setServerName(db2.getHost());
|
||||
dataSource.setPortNumber(db2.getMappedPort(Db2Container.DB2_PORT));
|
||||
dataSource.setSslConnection(false);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,84 +15,36 @@
|
||||
*/
|
||||
package org.springframework.batch.item.database.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
class DerbyPagingQueryProviderIntegrationTests {
|
||||
@SpringJUnitConfig
|
||||
class DerbyPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
private static EmbeddedDatabase embeddedDatabase;
|
||||
|
||||
private static JdbcTemplate jdbcTemplate;
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
embeddedDatabase = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
|
||||
.addScript("/org/springframework/batch/item/database/support/query-provider-fixture.sql")
|
||||
.generateUniqueName(true)
|
||||
.build();
|
||||
jdbcTemplate = new JdbcTemplate(embeddedDatabase);
|
||||
DerbyPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new DerbyPagingQueryProvider());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void tearDown() {
|
||||
if (embeddedDatabase != null) {
|
||||
embeddedDatabase.shutdown();
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
|
||||
.addScript("/org/springframework/batch/item/database/support/query-provider-fixture.sql")
|
||||
.generateUniqueName(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithoutGrouping() {
|
||||
var queryProvider = new DerbyPagingQueryProvider();
|
||||
queryProvider.setSelectClause("ID, STRING");
|
||||
queryProvider.setFromClause("TEST_TABLE");
|
||||
Map<String, Order> sortKeys = new HashMap<>();
|
||||
sortKeys.put("ID", Order.ASCENDING);
|
||||
queryProvider.setSortKeys(sortKeys);
|
||||
|
||||
List<Item> firstPage = jdbcTemplate.query(queryProvider.generateFirstPageQuery(2), MAPPER);
|
||||
assertEquals(List.of(new Item(1, "Spring"), new Item(2, "Batch")), firstPage);
|
||||
|
||||
List<Item> secondPage = jdbcTemplate.query(queryProvider.generateRemainingPagesQuery(2), MAPPER, 2);
|
||||
assertEquals(List.of(new Item(3, "Infrastructure")), secondPage);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithGrouping() {
|
||||
var queryProvider = new DerbyPagingQueryProvider();
|
||||
queryProvider.setSelectClause("STRING");
|
||||
queryProvider.setFromClause("GROUPING_TEST_TABLE");
|
||||
queryProvider.setGroupClause("STRING");
|
||||
Map<String, Order> sortKeys = new HashMap<>();
|
||||
sortKeys.put("STRING", Order.ASCENDING);
|
||||
queryProvider.setSortKeys(sortKeys);
|
||||
|
||||
List<String> firstPage = jdbcTemplate.queryForList(queryProvider.generateFirstPageQuery(2), String.class);
|
||||
assertEquals(List.of("Batch", "Infrastructure"), firstPage);
|
||||
|
||||
List<String> secondPage = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(2), String.class,
|
||||
"Infrastructure");
|
||||
assertEquals(List.of("Spring"), secondPage);
|
||||
}
|
||||
|
||||
private record Item(Integer id, String string) {
|
||||
}
|
||||
|
||||
private static final RowMapper<Item> MAPPER = (rs, rowNum) -> new Item(rs.getInt("id"), rs.getString("string"));
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
class HsqlPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
HsqlPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new HsqlPagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
|
||||
.addScript("/org/springframework/batch/item/database/support/query-provider-fixture.sql")
|
||||
.generateUniqueName(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.MariaDBContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class MariaDBPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName MARIADB_IMAGE = DockerImageName.parse("mariadb:10.9.3");
|
||||
|
||||
@Container
|
||||
public static MariaDBContainer<?> mariaDBContainer = new MariaDBContainer<>(MARIADB_IMAGE);
|
||||
|
||||
MariaDBPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new MySqlPagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
MariaDbDataSource datasource = new MariaDbDataSource();
|
||||
datasource.setUrl(mariaDBContainer.getJdbcUrl());
|
||||
datasource.setUser(mariaDBContainer.getUsername());
|
||||
datasource.setPassword(mariaDBContainer.getPassword());
|
||||
return datasource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.MySQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class MySqlPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName MYSQL_IMAGE = DockerImageName.parse("mysql:8.0.31");
|
||||
|
||||
@Container
|
||||
public static MySQLContainer<?> mysql = new MySQLContainer<>(MYSQL_IMAGE);
|
||||
|
||||
MySqlPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new MySqlPagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
MysqlDataSource datasource = new MysqlDataSource();
|
||||
datasource.setURL(mysql.getJdbcUrl());
|
||||
datasource.setUser(mysql.getUsername());
|
||||
datasource.setPassword(mysql.getPassword());
|
||||
datasource.setUseSSL(false);
|
||||
return datasource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import oracle.jdbc.pool.OracleDataSource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.OracleContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* Official Docker images for Oracle are not publicly available. Oracle support is tested
|
||||
* semi-manually for the moment: 1. Build a docker image for oracle/database:11.2.0.2-xe:
|
||||
* <a href=
|
||||
* "https://github.com/oracle/docker-images/tree/main/OracleDatabase/SingleInstance#running-oracle-database-11gr2-express-edition-in-a-container">...</a>
|
||||
* 2. Run the test `testJobExecution`
|
||||
*
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
@Disabled("Official Docker images for Oracle are not publicly available")
|
||||
class OraclePagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName ORACLE_IMAGE = DockerImageName.parse("oracle/database:11.2.0.2-xe");
|
||||
|
||||
@Container
|
||||
public static OracleContainer oracle = new OracleContainer(ORACLE_IMAGE);
|
||||
|
||||
OraclePagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new OraclePagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
OracleDataSource oracleDataSource = new OracleDataSource();
|
||||
oracleDataSource.setUser(oracle.getUsername());
|
||||
oracleDataSource.setPassword(oracle.getPassword());
|
||||
oracleDataSource.setDatabaseName(oracle.getDatabaseName());
|
||||
oracleDataSource.setServerName(oracle.getHost());
|
||||
oracleDataSource.setPortNumber(oracle.getOraclePort());
|
||||
return oracleDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.postgresql.ds.PGSimpleDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class PostgresPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName POSTGRESQL_IMAGE = DockerImageName.parse("postgres:13.3");
|
||||
|
||||
@Container
|
||||
public static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRESQL_IMAGE);
|
||||
|
||||
PostgresPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new PostgresPagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
PGSimpleDataSource datasource = new PGSimpleDataSource();
|
||||
datasource.setURL(postgres.getJdbcUrl());
|
||||
datasource.setUser(postgres.getUsername());
|
||||
datasource.setPassword(postgres.getPassword());
|
||||
return datasource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.testcontainers.containers.MSSQLServerContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class SqlServerPagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
// TODO find the best way to externalize and manage image versions
|
||||
private static final DockerImageName SQLSERVER_IMAGE = DockerImageName
|
||||
.parse("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04");
|
||||
|
||||
@Container
|
||||
public static MSSQLServerContainer<?> sqlserver = new MSSQLServerContainer<>(SQLSERVER_IMAGE).acceptLicense();
|
||||
|
||||
SqlServerPagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new SqlServerPagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
SQLServerDataSource dataSource = new SQLServerDataSource();
|
||||
dataSource.setUser(sqlserver.getUsername());
|
||||
dataSource.setPassword(sqlserver.getPassword());
|
||||
dataSource.setURL(sqlserver.getJdbcUrl());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2024 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.item.database.support;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.sqlite.SQLiteDataSource;
|
||||
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
|
||||
|
||||
/**
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@Sql(scripts = "query-provider-fixture.sql", executionPhase = BEFORE_TEST_CLASS)
|
||||
class SqlitePagingQueryProviderIntegrationTests extends AbstractPagingQueryProviderIntegrationTests {
|
||||
|
||||
@TempDir
|
||||
private static Path TEMP_DIR;
|
||||
|
||||
SqlitePagingQueryProviderIntegrationTests(@Autowired DataSource dataSource) {
|
||||
super(dataSource, new SqlitePagingQueryProvider());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws Exception {
|
||||
SQLiteDataSource dataSource = new SQLiteDataSource();
|
||||
dataSource.setUrl("jdbc:sqlite:" + TEMP_DIR.resolve("spring-batch.sqlite"));
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user