aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-25 11:29:44 +0300
committerGravatar Vitaly Takmazov2019-04-25 11:29:44 +0300
commit1d873c6f85ca90d1448dd54cbe718d84e83d79ea (patch)
tree49e8c5ececa6b18278303910050568b567869e7b
parent364fb7fad241ab4945ec1069e199a1d6344ae0ad (diff)
mysql test profile
run as SPRING_PROFILES_ACTIVE=mysql ./gradlew check
-rw-r--r--build.gradle1
-rw-r--r--src/main/resources/application.properties1
-rw-r--r--src/main/resources/schema-h2.sql (renamed from src/main/resources/schema.sql)0
-rw-r--r--src/test/java/com/juick/server/configuration/DataSourceAutoConfiguration.java52
-rw-r--r--src/test/resources/application-mysql.yml13
-rw-r--r--src/test/resources/juick-search-schema.sql29
-rw-r--r--src/test/resources/schema-mysql.sql (renamed from src/main/resources/juick.sql)31
7 files changed, 96 insertions, 31 deletions
diff --git a/build.gradle b/build.gradle
index cabfaadd..6d1ff872 100644
--- a/build.gradle
+++ b/build.gradle
@@ -168,6 +168,7 @@ dependencies {
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile('net.sourceforge.htmlunit:htmlunit:2.35.0')
testCompile('org.springframework.security:spring-security-test')
+ testCompile("ch.vorburger.mariaDB4j:mariaDB4j:2.4.0")
testCompile 'io.springfox:springfox-swagger2:2.9.2'
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index ba4d9b9b..af0bee6e 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,3 +1,4 @@
spring.jackson.default-property-inclusion=non_default
spring.jackson.serialization.write-dates-as-timestamps=false
spring.h2.console.enabled=true
+spring.datasource.platform=h2
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema-h2.sql
index 423fc375..423fc375 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema-h2.sql
diff --git a/src/test/java/com/juick/server/configuration/DataSourceAutoConfiguration.java b/src/test/java/com/juick/server/configuration/DataSourceAutoConfiguration.java
new file mode 100644
index 00000000..a01125eb
--- /dev/null
+++ b/src/test/java/com/juick/server/configuration/DataSourceAutoConfiguration.java
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * MariaDB4j
+ * %%
+ * Copyright (C) 2012 - 2018 Yuexiang Gao
+ * %%
+ * 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.
+ * #L%
+ */
+package com.juick.server.configuration;
+
+import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.DependsOn;
+
+import javax.sql.DataSource;
+
+@Configuration
+@ConfigurationProperties("spring.datasource")
+@ConditionalOnProperty(value = "spring.datasource.platform", havingValue = "mysql")
+public class DataSourceAutoConfiguration {
+
+ @Bean
+ public MariaDB4jSpringService mariaDB4j() {
+ return new MariaDB4jSpringService();
+ }
+ @Bean
+ @DependsOn("mariaDB4j")
+ public DataSource dataSource(DataSourceProperties dataSourceProperties) {
+ return DataSourceBuilder.create()
+ .driverClassName(dataSourceProperties.getDriverClassName())
+ .url(dataSourceProperties.getUrl())
+ .username(dataSourceProperties.getUsername())
+ .password(dataSourceProperties.getPassword())
+ .build();
+ }
+} \ No newline at end of file
diff --git a/src/test/resources/application-mysql.yml b/src/test/resources/application-mysql.yml
new file mode 100644
index 00000000..2203714f
--- /dev/null
+++ b/src/test/resources/application-mysql.yml
@@ -0,0 +1,13 @@
+spring:
+ datasource:
+ platform: mysql
+ initialization-mode: always
+ driver-class-name: org.mariadb.jdbc.Driver
+ url: jdbc:mariadb://localhost:${mariaDB4j.port}/test?zeroDateTimeBehavior=convertToNull&useMysqlMetadata=true
+ username: root
+ password:
+ flyway:
+ baseline-on-migrate: true
+
+mariaDB4j:
+ port: 3307 \ No newline at end of file
diff --git a/src/test/resources/juick-search-schema.sql b/src/test/resources/juick-search-schema.sql
new file mode 100644
index 00000000..bcf0fff7
--- /dev/null
+++ b/src/test/resources/juick-search-schema.sql
@@ -0,0 +1,29 @@
+--
+-- Table structure for table `search`
+--
+
+DROP TABLE IF EXISTS `search`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `search` (
+ `id` bigint(20) unsigned NOT NULL,
+ `weight` int(11) NOT NULL,
+ `query` varchar(3072) NOT NULL,
+ `group_id` int(11) DEFAULT NULL,
+ KEY `query` (`query`(768))
+) ENGINE=SPHINX DEFAULT CHARSET=utf8mb4 CONNECTION='sphinx://127.0.0.1:3312/messages';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `sphinx`
+--
+
+DROP TABLE IF EXISTS `sphinx`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sphinx` (
+ `counter_id` tinyint(3) unsigned NOT NULL,
+ `max_id` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`counter_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file
diff --git a/src/main/resources/juick.sql b/src/test/resources/schema-mysql.sql
index 0067389f..d30cd9f7 100644
--- a/src/main/resources/juick.sql
+++ b/src/test/resources/schema-mysql.sql
@@ -2,7 +2,6 @@
--
-- Host: localhost Database: juick
-- ------------------------------------------------------
-use juick;
-- Server version 10.1.26-MariaDB-0+deb9u1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -572,36 +571,6 @@ CREATE TABLE `replies` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
--- Table structure for table `search`
---
-
-DROP TABLE IF EXISTS `search`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `search` (
- `id` bigint(20) unsigned NOT NULL,
- `weight` int(11) NOT NULL,
- `query` varchar(3072) NOT NULL,
- `group_id` int(11) DEFAULT NULL,
- KEY `query` (`query`(768))
-) ENGINE=SPHINX DEFAULT CHARSET=utf8mb4 CONNECTION='sphinx://127.0.0.1:3312/messages';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `sphinx`
---
-
-DROP TABLE IF EXISTS `sphinx`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sphinx` (
- `counter_id` tinyint(3) unsigned NOT NULL,
- `max_id` int(10) unsigned NOT NULL,
- PRIMARY KEY (`counter_id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
-- Table structure for table `subscr_messages`
--