From 4238f4421900dcc31bcbf543164c332f199b1186 Mon Sep 17 00:00:00 2001 From: tlang Date: Tue, 26 May 2020 08:17:47 +0200 Subject: [PATCH] DATAJDBC-256 - First step toward running integration tests with Oracle. Original pull request: #223, #232. --- pom.xml | 18 ++++++ spring-data-jdbc/pom.xml | 15 +++++ .../MariaDBDataSourceConfiguration.java | 2 - .../testing/MySqlDataSourceConfiguration.java | 2 - .../OracleDataSourceConfiguration.java | 60 +++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java diff --git a/pom.xml b/pom.xml index 84bf6105..7471461f 100644 --- a/pom.xml +++ b/pom.xml @@ -190,6 +190,24 @@ + + oracle-test + test + + test + + + + **/*IntegrationTests.java + + + **/*HsqlIntegrationTests.java + + + orcacle + + + diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index 899656e2..6ebeb3c5 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -200,6 +200,14 @@ test + + com.oracle.database.jdbc + ojdbc8 + 19.6.0.0 + test + + + de.schauderhaft.degraph degraph-check @@ -243,6 +251,13 @@ test + + org.testcontainers + oracle-xe + test + + + diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java index 31d6f985..ae624a90 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java @@ -22,12 +22,10 @@ import javax.annotation.PostConstruct; import javax.sql.DataSource; import org.mariadb.jdbc.MariaDbDataSource; - import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.io.ByteArrayResource; import org.springframework.jdbc.datasource.init.ScriptUtils; - import org.testcontainers.containers.MariaDBContainer; /** diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceConfiguration.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceConfiguration.java index 2aef78ff..d1a4c273 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceConfiguration.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceConfiguration.java @@ -25,7 +25,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.core.io.ByteArrayResource; import org.springframework.jdbc.datasource.init.ScriptUtils; - import org.testcontainers.containers.MySQLContainer; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; @@ -42,7 +41,6 @@ import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; @Configuration @Profile("mysql") class MySqlDataSourceConfiguration extends DataSourceConfiguration { - private static MySQLContainer MYSQL_CONTAINER; /* diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java new file mode 100644 index 00000000..2895533a --- /dev/null +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright 2017-2020 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.data.jdbc.testing; + +import javax.sql.DataSource; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.testcontainers.containers.OracleContainer; + +/** + * {@link DataSource} setup for Oracle Database XE. Starts a docker container with a Oracle database. + * + * @see Oracle + * Docker Image + * @see Testcontainers Oracle + * @author Thomas Lang + * @author Jens Schauder + */ +@Configuration +@Profile("oracle") +public class OracleDataSourceConfiguration extends DataSourceConfiguration { + + private static OracleContainer ORACLE_CONTAINER; + + /* + * (non-Javadoc) + * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource() + */ + @Override + protected DataSource createDataSource() { + + if (ORACLE_CONTAINER == null) { + + OracleContainer container = new OracleContainer("name_of_your_oracle_xe_image"); + container.start(); + + ORACLE_CONTAINER = container; + } + + return new DriverManagerDataSource(ORACLE_CONTAINER.getJdbcUrl(), ORACLE_CONTAINER.getUsername(), + ORACLE_CONTAINER.getPassword()); + } + +}