Browse Source

DATAJDBC-196 - Integration-test-support for MariaDB.

Original pull request: #57.
pull/58/merge
Chr1st0ph 8 years ago committed by Jens Schauder
parent
commit
d4b2eca43a
  1. 3
      README.adoc
  2. 33
      pom.xml
  3. 68
      src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java
  4. 5
      src/test/resources/org.springframework.data.jdbc.core/JdbcEntityTemplateIntegrationTests-mariadb.sql
  5. 1
      src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-mariadb.sql
  6. 2
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mariadb.sql
  7. 1
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql
  8. 2
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql
  9. 1
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql
  10. 2
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-mariadb.sql
  11. 2
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-mariadb.sql
  12. 2
      src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-mariadb.sql

3
README.adoc

@ -353,6 +353,7 @@ Currently the following _databasetypes_ are available: @@ -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: @@ -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

33
pom.xml

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
<mybatis-spring.version>1.3.2</mybatis-spring.version>
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
<postgresql.version>42.0.0</postgresql.version>
<mariadb-java-client.version>2.2.3</mariadb-java-client.version>
<testcontainers.version>1.6.0</testcontainers.version>
</properties>
@ -121,6 +122,24 @@ @@ -121,6 +122,24 @@
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>mariadb-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>mariadb</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
@ -209,6 +228,13 @@ @@ -209,6 +228,13 @@
<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>de.schauderhaft.degraph</groupId>
<artifactId>degraph-check</artifactId>
@ -230,6 +256,13 @@ @@ -230,6 +256,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

68
src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java

@ -0,0 +1,68 @@ @@ -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;");
}
}

5
src/test/resources/org.springframework.data.jdbc.core/JdbcEntityTemplateIntegrationTests-mariadb.sql

@ -0,0 +1,5 @@ @@ -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);

1
src/test/resources/org.springframework.data.jdbc.repository.config/EnableJdbcRepositoriesIntegrationTests-mariadb.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE DummyEntity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)

2
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mariadb.sql

@ -0,0 +1,2 @@ @@ -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));

1
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql

@ -0,0 +1 @@ @@ -0,0 +1 @@
CREATE TABLE dummyentity (idProp BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));

2
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryManipulateDbActionsIntegrationTests-mariadb.sql

@ -0,0 +1,2 @@ @@ -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));

1
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryPropertyConversionIntegrationTests-mariadb.sql

@ -0,0 +1 @@ @@ -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))

2
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsIntegrationTests-mariadb.sql

@ -0,0 +1,2 @@ @@ -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);

2
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithListsIntegrationTests-mariadb.sql

@ -0,0 +1,2 @@ @@ -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);

2
src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithMapsIntegrationTests-mariadb.sql

@ -0,0 +1,2 @@ @@ -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);
Loading…
Cancel
Save