diff --git a/README.adoc b/README.adoc index 3fa1610a5..8b6d6acd8 100644 --- a/README.adoc +++ b/README.adoc @@ -353,6 +353,7 @@ Currently the following _databasetypes_ are available: * hsql (default, does not require a running database) * mysql * postgres +* mariadb === Run tests with all databases @@ -361,7 +362,7 @@ Currently the following _databasetypes_ are available: mvn test -Pall-dbs ---- -This will execute the unit tests, and all the integration tests with all the databases we currently support for testing. The databases must be running. +This will execute the unit tests, and all the integration tests with all the databases we currently support for testing. Running the integration-tests depends on Docker. == Contributing to Spring Data JDBC diff --git a/pom.xml b/pom.xml index 90a775b67..5f0698b03 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ 1.3.2 5.1.41 42.0.0 + 2.2.3 1.6.0 @@ -121,6 +122,24 @@ + + mariadb-test + test + + test + + + + **/*IntegrationTests.java + + + **/*HsqlIntegrationTests.java + + + mariadb + + + @@ -209,6 +228,13 @@ test + + org.mariadb.jdbc + mariadb-java-client + ${mariadb-java-client.version} + test + + de.schauderhaft.degraph degraph-check @@ -230,6 +256,13 @@ test + + org.testcontainers + mariadb + ${testcontainers.version} + test + + diff --git a/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java b/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java new file mode 100644 index 000000000..604982704 --- /dev/null +++ b/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java @@ -0,0 +1,68 @@ +/* + * Copyright 2017-2018 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 + * + * http://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 java.sql.SQLException; + +import javax.annotation.PostConstruct; +import javax.script.ScriptException; +import javax.sql.DataSource; + +import org.mariadb.jdbc.MariaDbDataSource; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.testcontainers.containers.MariaDBContainer; +import org.testcontainers.jdbc.ext.ScriptUtils; + +/** + * {@link DataSource} setup for MariaDB. + * + * Starts a Docker-container with a MariaDB database, and sets up database "test". + + * @author Christoph Preißner + */ +@Configuration +@Profile("mariadb") +class MariaDBDataSourceConfiguration extends DataSourceConfiguration { + + private static final MariaDBContainer MARIADB_CONTAINER = new MariaDBContainer().withConfigurationOverride(""); + + static { + MARIADB_CONTAINER.start(); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource() + */ + @Override + protected DataSource createDataSource() { + try { + MariaDbDataSource dataSource = new MariaDbDataSource(); + dataSource.setUrl(MARIADB_CONTAINER.getJdbcUrl()); + dataSource.setUser(MARIADB_CONTAINER.getUsername()); + dataSource.setPassword(MARIADB_CONTAINER.getPassword()); + return dataSource; + } catch(SQLException sqlex) { + throw new RuntimeException(sqlex); + } + } + + @PostConstruct + public void initDatabase() throws SQLException, ScriptException { + ScriptUtils.executeSqlScript(createDataSource().getConnection(), null, "DROP DATABASE test;CREATE DATABASE test;"); + } +} diff --git a/src/test/resources/org.springframework.data.jdbc.core/JdbcEntityTemplateIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.core/JdbcEntityTemplateIntegrationTests-mariadb.sql new file mode 100644 index 000000000..a3a849054 --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.core/JdbcEntityTemplateIntegrationTests-mariadb.sql @@ -0,0 +1,5 @@ +CREATE TABLE LEGOSET ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(30)); +CREATE TABLE MANUAL ( id BIGINT AUTO_INCREMENT PRIMARY KEY, LEGOSET BIGINT, CONTENT VARCHAR(2000)); + +ALTER TABLE MANUAL ADD FOREIGN KEY (LEGOSET) +REFERENCES LEGOSET(id); diff --git a/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-mariadb.sql new file mode 100644 index 000000000..808c99e6e --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-mariadb.sql @@ -0,0 +1 @@ +CREATE TABLE DummyEntity ( id BIGINT AUTO_INCREMENT PRIMARY KEY) \ No newline at end of file diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mariadb.sql new file mode 100644 index 000000000..b02242b2c --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mariadb.sql @@ -0,0 +1,2 @@ +CREATE TABLE ReadOnlyIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE PrimitiveIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql new file mode 100644 index 000000000..89763ecdb --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql @@ -0,0 +1 @@ +CREATE TABLE dummyentity (idProp BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql new file mode 100644 index 000000000..9b52d44da --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql @@ -0,0 +1,2 @@ +CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT); +CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100)); diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql new file mode 100644 index 000000000..91f0b575d --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql @@ -0,0 +1 @@ +CREATE TABLE ENTITYWITHCOLUMNSREQUIRINGCONVERSIONS ( idTimestamp DATETIME PRIMARY KEY, bool boolean, SOMEENUM VARCHAR(100), bigDecimal DECIMAL(65), bigInteger DECIMAL(20), date DATETIME, localDateTime DATETIME, zonedDateTime VARCHAR(30)) diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-mariadb.sql new file mode 100644 index 000000000..0e0a7e562 --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-mariadb.sql @@ -0,0 +1,2 @@ +CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT AUTO_INCREMENT PRIMARY KEY, content VARCHAR(100), dummyentity BIGINT); diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-mariadb.sql new file mode 100644 index 000000000..7dad33bd2 --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-mariadb.sql @@ -0,0 +1,2 @@ +CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT AUTO_INCREMENT PRIMARY KEY, content VARCHAR(100), DummyEntity_key BIGINT,dummyentity BIGINT); diff --git a/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-mariadb.sql b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-mariadb.sql new file mode 100644 index 000000000..f30df0af7 --- /dev/null +++ b/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-mariadb.sql @@ -0,0 +1,2 @@ +CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100)); +CREATE TABLE element (id BIGINT AUTO_INCREMENT PRIMARY KEY, content VARCHAR(100), DummyEntity_key VARCHAR(100),dummyentity BIGINT);