From 58c4ae69dedac3f39231541fd31b82f6a03d1f61 Mon Sep 17 00:00:00 2001 From: datagear Date: Wed, 7 Jul 2021 15:04:46 +0800 Subject: [PATCH] =?UTF-8?q?[management]=E6=A8=A1=E5=9D=97=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E6=94=B9=E4=B8=BA=E4=B8=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=A4=96=E9=83=A8MySQL=E7=8E=AF=E5=A2=83=E8=80=8C?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=86=85=E7=BD=AEDerby=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datagear-management/pom.xml | 5 +++ .../impl/ServiceImplTestSupport.java | 33 +++++++++++++++++ .../org/datagear/util/test/DBTestSupport.java | 8 ---- test/sql/test-sql-script-mysql.sql | 37 ------------------- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/datagear-management/pom.xml b/datagear-management/pom.xml index 849674fc..382bc7fa 100644 --- a/datagear-management/pom.xml +++ b/datagear-management/pom.xml @@ -61,6 +61,11 @@ spring-jdbc test + + org.apache.derby + derby + test + diff --git a/datagear-management/src/test/java/org/datagear/management/impl/ServiceImplTestSupport.java b/datagear-management/src/test/java/org/datagear/management/impl/ServiceImplTestSupport.java index 889f5d8f..f41297a5 100644 --- a/datagear-management/src/test/java/org/datagear/management/impl/ServiceImplTestSupport.java +++ b/datagear-management/src/test/java/org/datagear/management/impl/ServiceImplTestSupport.java @@ -7,7 +7,14 @@ package org.datagear.management.impl; +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.apache.commons.dbcp2.BasicDataSource; import org.apache.ibatis.session.SqlSessionFactory; +import org.datagear.management.dbversion.DbVersionManager; import org.datagear.management.util.dialect.MbSqlDialect; import org.datagear.management.util.dialect.MbSqlDialectBuilder; import org.datagear.util.test.DBTestSupport; @@ -23,6 +30,20 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; */ public class ServiceImplTestSupport extends DBTestSupport { + private static final DataSource DATA_SOURCE; + + static + { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); + dataSource.setUrl("jdbc:derby:target/test/derby;create=true"); + + DbVersionManager bean = new DbVersionManager(dataSource); + bean.upgrade(); + + DATA_SOURCE = dataSource; + } + private final SqlSessionFactory sqlSessionFactory; private final MbSqlDialect dialect; @@ -60,4 +81,16 @@ public class ServiceImplTestSupport extends DBTestSupport { return dialect; } + + @Override + protected Connection getConnection() throws SQLException + { + return DATA_SOURCE.getConnection(); + } + + @Override + protected DataSource getDataSource() throws SQLException + { + return DATA_SOURCE; + } } diff --git a/datagear-util/src/main/java/org/datagear/util/test/DBTestSupport.java b/datagear-util/src/main/java/org/datagear/util/test/DBTestSupport.java index 605ce6d3..6cb935e5 100644 --- a/datagear-util/src/main/java/org/datagear/util/test/DBTestSupport.java +++ b/datagear-util/src/main/java/org/datagear/util/test/DBTestSupport.java @@ -57,14 +57,6 @@ public abstract class DBTestSupport JDBC_PROPERTIES.getProperty("jdbc.user"), JDBC_PROPERTIES.getProperty("jdbc.password")); } - protected Connection getConnection(Properties properties) throws SQLException - { - properties.setProperty("user", JDBC_PROPERTIES.getProperty("jdbc.user")); - properties.setProperty("password", JDBC_PROPERTIES.getProperty("jdbc.password")); - - return DriverManager.getConnection(JDBC_PROPERTIES.getProperty("jdbc.url"), properties); - } - protected DataSource getDataSource() throws SQLException { return new DataSource() diff --git a/test/sql/test-sql-script-mysql.sql b/test/sql/test-sql-script-mysql.sql index dd4eff98..67662e4f 100644 --- a/test/sql/test-sql-script-mysql.sql +++ b/test/sql/test-sql-script-mysql.sql @@ -1,34 +1,3 @@ -CREATE TABLE DATAGEAR_USER -( - USER_ID VARCHAR(50) NOT NULL, - USER_NAME VARCHAR(50) NOT NULL, - USER_PASSWORD VARCHAR(200) NOT NULL, - USER_REAL_NAME VARCHAR(100), - USER_EMAIL VARCHAR(200), - USER_IS_ADMIN VARCHAR(20), - USER_CREATE_TIME TIMESTAMP, - PRIMARY KEY (USER_ID), - UNIQUE (USER_NAME) -); - -CREATE TABLE DATAGEAR_ROLE -( - ROLE_ID VARCHAR(50) NOT NULL, - ROLE_NAME VARCHAR(100) NOT NULL, - ROLE_DESCRIPTION VARCHAR(200), - ROLE_ENABLED VARCHAR(10) NOT NULL, - ROLE_CREATE_TIME TIMESTAMP, - PRIMARY KEY (ROLE_ID) -); - -CREATE TABLE DATAGEAR_ROLE_USER -( - RU_ID VARCHAR(50) NOT NULL, - RU_ROLE_ID VARCHAR(50) NOT NULL, - RU_USER_ID VARCHAR(50) NOT NULL, - PRIMARY KEY (RU_ID) -); - CREATE TABLE T_ACCOUNT ( ID INT NOT NULL, @@ -242,9 +211,6 @@ truncate table t_analysis_2; truncate table t_analysis_map; truncate table t_analysis_map_1; truncate table t_time_series; -truncate table datagear_role_user; -truncate table datagear_user; -truncate table datagear_role; */ /* @@ -269,7 +235,4 @@ drop table t_analysis_2; drop table t_analysis_map; drop table t_analysis_map_1; drop table t_time_series; -drop table datagear_role_user; -drop table datagear_user; -drop table datagear_role; */ \ No newline at end of file