add h2 and derby test

This commit is contained in:
Looly
2020-04-23 13:50:59 +08:00
parent e8c0a75e7f
commit 01ac0f94dc
7 changed files with 125 additions and 21 deletions

View File

@@ -0,0 +1,50 @@
package cn.hutool.db;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import java.sql.SQLException;
import java.util.List;
/**
* Derby数据库单元测试
*
* @author looly
*
*/
public class DerbyTest {
private static final String DS_GROUP_NAME = "derby";
@BeforeClass
public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
try{
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
}catch (SQLException e){
// 数据库已存在
return;
}
db.insert(Entity.create("test").set("a", 1).set("b", 11));
db.insert(Entity.create("test").set("a", 2).set("b", 21));
db.insert(Entity.create("test").set("a", 3).set("b", 31));
db.insert(Entity.create("test").set("a", 4).set("b", 41));
}
@Test
@Ignore
public void queryTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
}
@Test
@Ignore
public void findTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
Assert.assertEquals(4, query.size());
}
}

View File

@@ -0,0 +1,42 @@
package cn.hutool.db;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.SQLException;
import java.util.List;
/**
* H2数据库单元测试
*
* @author looly
*
*/
public class H2Test {
private static final String DS_GROUP_NAME = "h2";
@BeforeClass
public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
db.insert(Entity.create("test").set("a", 1).set("b", 11));
db.insert(Entity.create("test").set("a", 2).set("b", 21));
db.insert(Entity.create("test").set("a", 3).set("b", 31));
db.insert(Entity.create("test").set("a", 4).set("b", 41));
}
@Test
public void queryTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
}
@Test
public void findTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
Assert.assertEquals(4, query.size());
}
}

View File

@@ -1,15 +1,12 @@
package cn.hutool.db;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.SQLException;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
/**
* HSQLDB数据库单元测试
*
@@ -20,8 +17,8 @@ public class HsqldbTest {
private static final String DS_GROUP_NAME = "hsqldb";
@Before
public void init() throws SQLException {
@BeforeClass
public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
db.insert(Entity.create("test").set("a", 1).set("b", 11));
@@ -35,4 +32,10 @@ public class HsqldbTest {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
}
@Test
public void findTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
Assert.assertEquals(4, query.size());
}
}

View File

@@ -28,7 +28,17 @@ url = jdbc:sqlite:test.db
[hsqldb]
url = jdbc:hsqldb:mem:mem_hutool
user = SA
pass =
pass =
# 测试用HSQLDB数据库
[h2]
url = jdbc:h2:mem:h2_hutool
user = sa
pass =
# 测试用HSQLDB数据库
[derby]
url = jdbc:derby:.derby/test_db;create=true
# 测试用Oracle数据库
[orcl]