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

Original pull request: #57.
This commit is contained in:
Chr1st0ph
2018-04-10 17:17:20 +02:00
committed by Jens Schauder
parent dba9d3f4ee
commit d4b2eca43a
12 changed files with 121 additions and 1 deletions

View File

@@ -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;");
}
}

View File

@@ -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);

View File

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

View File

@@ -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));

View File

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

View File

@@ -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));

View File

@@ -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))

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);