[management]模块单元测试改为不依赖外部MySQL环境而新建内置Derby测试库

This commit is contained in:
datagear 2021-07-07 15:04:46 +08:00
parent 2c33f59b43
commit 58c4ae69de
4 changed files with 38 additions and 45 deletions

View File

@ -61,6 +61,11 @@
<artifactId>spring-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

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

View File

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

View File

@ -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;
*/