Skip to content

Commit d4b2eca

Browse files
Chr1st0phschauder
authored andcommitted
DATAJDBC-196 - Integration-test-support for MariaDB.
Original pull request: #57.
1 parent dba9d3f commit d4b2eca

12 files changed

+121
-1
lines changed

README.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ Currently the following _databasetypes_ are available:
353353
* hsql (default, does not require a running database)
354354
* mysql
355355
* postgres
356+
* mariadb
356357

357358
=== Run tests with all databases
358359

@@ -361,7 +362,7 @@ Currently the following _databasetypes_ are available:
361362
mvn test -Pall-dbs
362363
----
363364

364-
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.
365+
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.
365366

366367
== Contributing to Spring Data JDBC
367368

pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<mybatis-spring.version>1.3.2</mybatis-spring.version>
3333
<mysql-connector-java.version>5.1.41</mysql-connector-java.version>
3434
<postgresql.version>42.0.0</postgresql.version>
35+
<mariadb-java-client.version>2.2.3</mariadb-java-client.version>
3536
<testcontainers.version>1.6.0</testcontainers.version>
3637

3738
</properties>
@@ -121,6 +122,24 @@
121122
</systemPropertyVariables>
122123
</configuration>
123124
</execution>
125+
<execution>
126+
<id>mariadb-test</id>
127+
<phase>test</phase>
128+
<goals>
129+
<goal>test</goal>
130+
</goals>
131+
<configuration>
132+
<includes>
133+
<include>**/*IntegrationTests.java</include>
134+
</includes>
135+
<excludes>
136+
<exclude>**/*HsqlIntegrationTests.java</exclude>
137+
</excludes>
138+
<systemPropertyVariables>
139+
<spring.profiles.active>mariadb</spring.profiles.active>
140+
</systemPropertyVariables>
141+
</configuration>
142+
</execution>
124143
</executions>
125144
</plugin>
126145
</plugins>
@@ -209,6 +228,13 @@
209228
<scope>test</scope>
210229
</dependency>
211230

231+
<dependency>
232+
<groupId>org.mariadb.jdbc</groupId>
233+
<artifactId>mariadb-java-client</artifactId>
234+
<version>${mariadb-java-client.version}</version>
235+
<scope>test</scope>
236+
</dependency>
237+
212238
<dependency>
213239
<groupId>de.schauderhaft.degraph</groupId>
214240
<artifactId>degraph-check</artifactId>
@@ -230,6 +256,13 @@
230256
<scope>test</scope>
231257
</dependency>
232258

259+
<dependency>
260+
<groupId>org.testcontainers</groupId>
261+
<artifactId>mariadb</artifactId>
262+
<version>${testcontainers.version}</version>
263+
<scope>test</scope>
264+
</dependency>
265+
233266
</dependencies>
234267

235268
<build>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2017-2018 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+
* http://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.data.jdbc.testing;
17+
18+
import java.sql.SQLException;
19+
20+
import javax.annotation.PostConstruct;
21+
import javax.script.ScriptException;
22+
import javax.sql.DataSource;
23+
24+
import org.mariadb.jdbc.MariaDbDataSource;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.annotation.Profile;
27+
import org.testcontainers.containers.MariaDBContainer;
28+
import org.testcontainers.jdbc.ext.ScriptUtils;
29+
30+
/**
31+
* {@link DataSource} setup for MariaDB.
32+
*
33+
* Starts a Docker-container with a MariaDB database, and sets up database "test".
34+
35+
* @author Christoph Preißner
36+
*/
37+
@Configuration
38+
@Profile("mariadb")
39+
class MariaDBDataSourceConfiguration extends DataSourceConfiguration {
40+
41+
private static final MariaDBContainer MARIADB_CONTAINER = new MariaDBContainer().withConfigurationOverride("");
42+
43+
static {
44+
MARIADB_CONTAINER.start();
45+
}
46+
47+
/*
48+
* (non-Javadoc)
49+
* @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource()
50+
*/
51+
@Override
52+
protected DataSource createDataSource() {
53+
try {
54+
MariaDbDataSource dataSource = new MariaDbDataSource();
55+
dataSource.setUrl(MARIADB_CONTAINER.getJdbcUrl());
56+
dataSource.setUser(MARIADB_CONTAINER.getUsername());
57+
dataSource.setPassword(MARIADB_CONTAINER.getPassword());
58+
return dataSource;
59+
} catch(SQLException sqlex) {
60+
throw new RuntimeException(sqlex);
61+
}
62+
}
63+
64+
@PostConstruct
65+
public void initDatabase() throws SQLException, ScriptException {
66+
ScriptUtils.executeSqlScript(createDataSource().getConnection(), null, "DROP DATABASE test;CREATE DATABASE test;");
67+
}
68+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE LEGOSET ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(30));
2+
CREATE TABLE MANUAL ( id BIGINT AUTO_INCREMENT PRIMARY KEY, LEGOSET BIGINT, CONTENT VARCHAR(2000));
3+
4+
ALTER TABLE MANUAL ADD FOREIGN KEY (LEGOSET)
5+
REFERENCES LEGOSET(id);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE DummyEntity ( id BIGINT AUTO_INCREMENT PRIMARY KEY)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE ReadOnlyIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
2+
CREATE TABLE PrimitiveIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE dummyentity (idProp BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100), DELETED CHAR(1), log BIGINT);
2+
CREATE TABLE log ( id BIGINT, TEXT VARCHAR(100));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE dummyentity ( id BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
2+
CREATE TABLE element (id BIGINT AUTO_INCREMENT PRIMARY KEY, content VARCHAR(100), dummyentity BIGINT);

0 commit comments

Comments
 (0)