mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
update to junit5
This commit is contained in:
@@ -7,9 +7,9 @@ import cn.hutool.db.handler.EntityListHandler;
|
||||
import cn.hutool.db.pojo.User;
|
||||
import cn.hutool.db.sql.Condition;
|
||||
import cn.hutool.db.sql.Condition.LikeType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
@@ -27,103 +27,103 @@ public class CRUDTest {
|
||||
@Test
|
||||
public void findIsNullTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", "is null"));
|
||||
Assert.assertEquals(0, results.size());
|
||||
Assertions.assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findIsNullTest2() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", "= null"));
|
||||
Assert.assertEquals(0, results.size());
|
||||
Assertions.assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findIsNullTest3() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", null));
|
||||
Assert.assertEquals(0, results.size());
|
||||
Assertions.assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findBetweenTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", "between '18' and '40'"));
|
||||
Assert.assertEquals(1, results.size());
|
||||
Assertions.assertEquals(1, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByBigIntegerTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", new BigInteger("12")));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByBigDecimalTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("age", new BigDecimal("12")));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findLikeTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("name", "like \"%三%\""));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findLikeTest2() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("name", new Condition("name", "三", LikeType.Contains)));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findLikeTest3() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("name", new Condition("name", null, LikeType.Contains)));
|
||||
Assert.assertEquals(0, results.size());
|
||||
Assertions.assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findInTest() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user").set("id", "in 1,2,3"));
|
||||
Console.log(results);
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findInTest2() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user")
|
||||
.set("id", new Condition("id", new long[]{1, 2, 3})));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findInTest3() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user")
|
||||
.set("id", new long[]{1, 2, 3}));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findInTest4() {
|
||||
final List<Entity> results = db.findAll(Entity.of("user")
|
||||
.set("id", new String[]{"1", "2", "3"}));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllTest() {
|
||||
final List<Entity> results = db.findAll("user");
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assertions.assertEquals(4, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
final List<Entity> find = db.find(ListUtil.of("name AS name2"), Entity.of("user"), new EntityListHandler());
|
||||
Assert.assertFalse(find.isEmpty());
|
||||
Assertions.assertFalse(find.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findActiveTest() {
|
||||
final ActiveEntity entity = new ActiveEntity(db, "user");
|
||||
entity.setFieldNames("name AS name2").load();
|
||||
Assert.assertEquals("user", entity.getTableName());
|
||||
Assert.assertFalse(entity.isEmpty());
|
||||
Assertions.assertEquals("user", entity.getTableName());
|
||||
Assertions.assertFalse(entity.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,30 +131,30 @@ public class CRUDTest {
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void crudTest() {
|
||||
|
||||
// 增
|
||||
final Long id = db.insertForGeneratedKey(Entity.of("user").set("name", "unitTestUser").set("age", 66));
|
||||
Assert.assertTrue(id > 0);
|
||||
Assertions.assertTrue(id > 0);
|
||||
final Entity result = db.get("user", "name", "unitTestUser");
|
||||
Assert.assertSame(66, result.getInt("age"));
|
||||
Assertions.assertSame(66, result.getInt("age"));
|
||||
|
||||
// 改
|
||||
final int update = db.update(Entity.of().set("age", 88), Entity.of("user").set("name", "unitTestUser"));
|
||||
Assert.assertTrue(update > 0);
|
||||
Assertions.assertTrue(update > 0);
|
||||
final Entity result2 = db.get("user", "name", "unitTestUser");
|
||||
Assert.assertSame(88, result2.getInt("age"));
|
||||
Assertions.assertSame(88, result2.getInt("age"));
|
||||
|
||||
// 删
|
||||
final int del = db.del("user", "name", "unitTestUser");
|
||||
Assert.assertTrue(del > 0);
|
||||
Assertions.assertTrue(del > 0);
|
||||
final Entity result3 = db.get("user", "name", "unitTestUser");
|
||||
Assert.assertNull(result3);
|
||||
Assertions.assertNull(result3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertBatchTest() {
|
||||
final User user1 = new User();
|
||||
user1.setName("张三");
|
||||
@@ -180,7 +180,7 @@ public class CRUDTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertBatchOneTest() {
|
||||
final User user1 = new User();
|
||||
user1.setName("张三");
|
||||
@@ -200,11 +200,11 @@ public class CRUDTest {
|
||||
public void selectInTest() {
|
||||
final List<Entity> results = db.query("select * from user where id in (:ids)",
|
||||
MapUtil.of("ids", new int[]{1, 2, 3}));
|
||||
Assert.assertEquals(2, results.size());
|
||||
Assertions.assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void findWithDotTest(){
|
||||
db.find(Entity.of("user").set("WTUR.Other.Rg.S.WTName", "value"));
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.db.handler.EntityListHandler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,12 +16,12 @@ import java.util.List;
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@Ignore
|
||||
@Disabled
|
||||
public class ConcurentTest {
|
||||
|
||||
private Db db;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
db = Db.of("test");
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ package cn.hutool.db;
|
||||
import cn.hutool.db.handler.EntityListHandler;
|
||||
import cn.hutool.db.sql.Condition;
|
||||
import cn.hutool.log.StaticLog;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -22,13 +22,13 @@ public class DbTest {
|
||||
@Test
|
||||
public void queryTest() {
|
||||
final List<Entity> find = Db.of().query("select * from user where age = ?", 18);
|
||||
Assert.assertEquals("王五", find.get(0).get("name"));
|
||||
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
final List<Entity> find = Db.of().find(Entity.of("user").set("age", 18));
|
||||
Assert.assertEquals("王五", find.get(0).get("name"));
|
||||
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -36,10 +36,10 @@ public class DbTest {
|
||||
// 测试数据库中一共4条数据,第0页有3条,第1页有1条
|
||||
final List<Entity> page0 = Db.of().page(Entity.of("user"),
|
||||
Page.of(0, 3));
|
||||
Assert.assertEquals(3, page0.size());
|
||||
Assertions.assertEquals(3, page0.size());
|
||||
|
||||
final List<Entity> page1 = Db.of().page(Entity.of("user"), Page.of(1, 3));
|
||||
Assert.assertEquals(1, page1.size());
|
||||
Assertions.assertEquals(1, page1.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,11 +48,11 @@ public class DbTest {
|
||||
// 测试数据库中一共4条数据,第0页有3条,第1页有1条
|
||||
final List<Entity> page0 = Db.of().page(
|
||||
sql, Page.of(0, 3));
|
||||
Assert.assertEquals(3, page0.size());
|
||||
Assertions.assertEquals(3, page0.size());
|
||||
|
||||
final List<Entity> page1 = Db.of().page(
|
||||
sql, Page.of(1, 3));
|
||||
Assert.assertEquals(1, page1.size());
|
||||
Assertions.assertEquals(1, page1.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +65,7 @@ public class DbTest {
|
||||
Entity.of().set("age", 12)
|
||||
.set("names", new String[]{"张三", "王五"})
|
||||
);
|
||||
Assert.assertEquals(1, page0.size());
|
||||
Assertions.assertEquals(1, page0.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,42 +74,42 @@ public class DbTest {
|
||||
final PageResult<Entity> result = Db.of().page(
|
||||
sql, Page.of(0, 3), "张三");
|
||||
|
||||
Assert.assertEquals(2, result.getTotal());
|
||||
Assert.assertEquals(1, result.getTotalPage());
|
||||
Assert.assertEquals(2, result.size());
|
||||
Assertions.assertEquals(2, result.getTotal());
|
||||
Assertions.assertEquals(1, result.getTotalPage());
|
||||
Assertions.assertEquals(2, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countTest() {
|
||||
final long count = Db.of().count("select * from user");
|
||||
Assert.assertEquals(4, count);
|
||||
Assertions.assertEquals(4, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countByQueryTest() {
|
||||
final long count = Db.of().count(Entity.of("user"));
|
||||
Assert.assertEquals(4, count);
|
||||
Assertions.assertEquals(4, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countTest2() {
|
||||
final long count = Db.of().count("select * from user order by name DESC");
|
||||
Assert.assertEquals(4, count);
|
||||
Assertions.assertEquals(4, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findLikeTest() {
|
||||
// 方式1
|
||||
List<Entity> find = Db.of().find(Entity.of("user").set("name", "like 王%"));
|
||||
Assert.assertEquals("王五", find.get(0).get("name"));
|
||||
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||
|
||||
// 方式2
|
||||
find = Db.of().findLike("user", "name", "王", Condition.LikeType.StartWith);
|
||||
Assert.assertEquals("王五", find.get(0).get("name"));
|
||||
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||
|
||||
// 方式3
|
||||
find = Db.of().query("select * from user where name like ?", "王%");
|
||||
Assert.assertEquals("王五", find.get(0).get("name"));
|
||||
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,11 +121,11 @@ public class DbTest {
|
||||
for (final Entity entity : find) {
|
||||
StaticLog.debug("{}", entity);
|
||||
}
|
||||
Assert.assertEquals("unitTestUser", find.get(0).get("name"));
|
||||
Assertions.assertEquals("unitTestUser", find.get(0).get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void txTest() throws SQLException {
|
||||
Db.of().tx(db -> {
|
||||
db.insert(Entity.of("user").set("name", "unitTestuser2"));
|
||||
@@ -135,7 +135,7 @@ public class DbTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void queryFetchTest() {
|
||||
// https://gitee.com/dromara/hutool/issues/I4JXWN
|
||||
Db.of().query((conn->{
|
||||
@@ -149,7 +149,7 @@ public class DbTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void findWithDotTest() {
|
||||
// 当字段带有点时,导致被拆分分别wrap了,因此此时关闭自动包装即可
|
||||
Db.of().disableWrapper().find(Entity.of("user").set("a.b", "1"));
|
||||
|
@@ -1,9 +1,8 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,7 +16,7 @@ public class DerbyTest {
|
||||
|
||||
private static final String DS_GROUP_NAME = "derby";
|
||||
|
||||
@BeforeClass
|
||||
//@BeforeAll
|
||||
public static void init() {
|
||||
final Db db = Db.of(DS_GROUP_NAME);
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
@@ -29,16 +28,16 @@ public class DerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void queryTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void findTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).find(Entity.of("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,8 @@ import cn.hutool.db.ds.hikari.HikariDSFactory;
|
||||
import cn.hutool.db.ds.pooled.PooledDSFactory;
|
||||
import cn.hutool.db.ds.tomcat.TomcatDSFactory;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
@@ -30,7 +30,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +39,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -49,7 +49,7 @@ public class DsTest {
|
||||
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +76,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,8 +93,8 @@ public class DsTest {
|
||||
// https://gitee.com/dromara/hutool/issues/I4T7XZ
|
||||
DSUtil.setGlobalDSFactory(new C3p0DSFactory());
|
||||
final ComboPooledDataSource ds = (ComboPooledDataSource) ((DSWrapper) DSUtil.getDS("mysql")).getRaw();
|
||||
Assert.assertEquals("root", ds.getUser());
|
||||
Assert.assertEquals("123456", ds.getPassword());
|
||||
Assertions.assertEquals("root", ds.getUser());
|
||||
Assertions.assertEquals("123456", ds.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,6 +103,6 @@ public class DsTest {
|
||||
final DataSource ds = DSUtil.getDS("test");
|
||||
final Db db = Db.of(ds);
|
||||
final List<Entity> all = db.findAll("user");
|
||||
Assert.assertTrue(CollUtil.isNotEmpty(all));
|
||||
Assertions.assertTrue(CollUtil.isNotEmpty(all));
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.db.pojo.User;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Entity测试
|
||||
@@ -19,8 +19,8 @@ public class EntityTest {
|
||||
user.setName("test");
|
||||
|
||||
final Entity entity = Entity.of("testTable").parseBean(user);
|
||||
Assert.assertEquals(Integer.valueOf(1), entity.getInt("id"));
|
||||
Assert.assertEquals("test", entity.getStr("name"));
|
||||
Assertions.assertEquals(Integer.valueOf(1), entity.getInt("id"));
|
||||
Assertions.assertEquals("test", entity.getStr("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -30,9 +30,9 @@ public class EntityTest {
|
||||
user.setName("test");
|
||||
|
||||
final Entity entity = Entity.of().parseBean(user);
|
||||
Assert.assertEquals(Integer.valueOf(1), entity.getInt("id"));
|
||||
Assert.assertEquals("test", entity.getStr("name"));
|
||||
Assert.assertEquals("user", entity.getTableName());
|
||||
Assertions.assertEquals(Integer.valueOf(1), entity.getInt("id"));
|
||||
Assertions.assertEquals("test", entity.getStr("name"));
|
||||
Assertions.assertEquals("user", entity.getTableName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,9 +42,9 @@ public class EntityTest {
|
||||
|
||||
final Entity entity = Entity.of().parseBean(user, false, true);
|
||||
|
||||
Assert.assertFalse(entity.containsKey("id"));
|
||||
Assert.assertEquals("test", entity.getStr("name"));
|
||||
Assert.assertEquals("user", entity.getTableName());
|
||||
Assertions.assertFalse(entity.containsKey("id"));
|
||||
Assertions.assertEquals("test", entity.getStr("name"));
|
||||
Assertions.assertEquals("user", entity.getTableName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +52,7 @@ public class EntityTest {
|
||||
final Entity entity = Entity.of().set("ID", 2).set("NAME", "testName");
|
||||
final User user = entity.toBeanIgnoreCase(User.class);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(2), user.getId());
|
||||
Assert.assertEquals("testName", user.getName());
|
||||
Assertions.assertEquals(Integer.valueOf(2), user.getId());
|
||||
Assertions.assertEquals("testName", user.getName());
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.db.pojo.User;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class FindBeanTest {
|
||||
|
||||
Db db;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
db = Db.of("test");
|
||||
}
|
||||
@@ -26,9 +26,9 @@ public class FindBeanTest {
|
||||
public void findAllBeanTest() {
|
||||
final List<User> results = db.findAll(Entity.of("user"), User.class);
|
||||
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assert.assertEquals(Integer.valueOf(1), results.get(0).getId());
|
||||
Assert.assertEquals("张三", results.get(0).getName());
|
||||
Assertions.assertEquals(4, results.size());
|
||||
Assertions.assertEquals(Integer.valueOf(1), results.get(0).getId());
|
||||
Assertions.assertEquals("张三", results.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -36,32 +36,32 @@ public class FindBeanTest {
|
||||
public void findAllListTest() {
|
||||
final List<List> results = db.findAll(Entity.of("user"), List.class);
|
||||
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assert.assertEquals(1, results.get(0).get(0));
|
||||
Assert.assertEquals("张三", results.get(0).get(1));
|
||||
Assertions.assertEquals(4, results.size());
|
||||
Assertions.assertEquals(1, results.get(0).get(0));
|
||||
Assertions.assertEquals("张三", results.get(0).get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllArrayTest() {
|
||||
final List<Object[]> results = db.findAll(Entity.of("user"), Object[].class);
|
||||
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assert.assertEquals(1, results.get(0)[0]);
|
||||
Assert.assertEquals("张三", results.get(0)[1]);
|
||||
Assertions.assertEquals(4, results.size());
|
||||
Assertions.assertEquals(1, results.get(0)[0]);
|
||||
Assertions.assertEquals("张三", results.get(0)[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllStringTest() {
|
||||
final List<String> results = db.findAll(Entity.of("user"), String.class);
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assertions.assertEquals(4, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllStringArrayTest() {
|
||||
final List<String[]> results = db.findAll(Entity.of("user"), String[].class);
|
||||
|
||||
Assert.assertEquals(4, results.size());
|
||||
Assert.assertEquals("1", results.get(0)[0]);
|
||||
Assert.assertEquals("张三", results.get(0)[1]);
|
||||
Assertions.assertEquals(4, results.size());
|
||||
Assertions.assertEquals("1", results.get(0)[0]);
|
||||
Assertions.assertEquals("张三", results.get(0)[1]);
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@ package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.map.CaseInsensitiveMap;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -19,7 +19,7 @@ public class H2Test {
|
||||
|
||||
private static final String DS_GROUP_NAME = "h2";
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
final Db db = Db.of(DS_GROUP_NAME);
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
@@ -33,13 +33,13 @@ public class H2Test {
|
||||
@Test
|
||||
public void queryTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).find(Entity.of("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,17 +47,17 @@ public class H2Test {
|
||||
final Db db=Db.of(DS_GROUP_NAME);
|
||||
db.upsert(Entity.of("test").set("a",1).set("b",111),"a");
|
||||
final Entity a1=db.get("test","a",1);
|
||||
Assert.assertEquals(Long.valueOf(111),a1.getLong("b"));
|
||||
Assertions.assertEquals(Long.valueOf(111),a1.getLong("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pageTest() {
|
||||
String sql = "select * from test where a = @a and b = :b";
|
||||
Map<String, Object> paramMap = MapUtil.builder(new CaseInsensitiveMap<String, Object>())
|
||||
final String sql = "select * from test where a = @a and b = :b";
|
||||
final Map<String, Object> paramMap = MapUtil.builder(new CaseInsensitiveMap<String, Object>())
|
||||
.put("A", 3)
|
||||
.put("b", 31)
|
||||
.build();
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).page(sql, Page.of(0, 3), paramMap);
|
||||
Assert.assertEquals(1, query.size());
|
||||
Assertions.assertEquals(1, query.size());
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class HsqldbTest {
|
||||
|
||||
private static final String DS_GROUP_NAME = "hsqldb";
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void init() {
|
||||
final Db db = Db.of(DS_GROUP_NAME);
|
||||
db.execute("CREATE TABLE test(a INTEGER, b BIGINT)");
|
||||
@@ -29,12 +29,12 @@ public class HsqldbTest {
|
||||
@Test
|
||||
public void connTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).query("select * from test");
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
final List<Entity> query = Db.of(DS_GROUP_NAME).find(Entity.of("test"));
|
||||
Assert.assertEquals(4, query.size());
|
||||
Assertions.assertEquals(4, query.size());
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@@ -15,15 +14,14 @@ import java.util.List;
|
||||
* @author looly
|
||||
*/
|
||||
public class MySQLTest {
|
||||
@BeforeClass
|
||||
@Ignore
|
||||
//@BeforeAll
|
||||
public static void createTable() {
|
||||
final Db db = Db.of("mysql");
|
||||
db.executeBatch("drop table if exists testuser", "CREATE TABLE if not exists `testuser` ( `id` int(11) NOT NULL, `account` varchar(255) DEFAULT NULL, `pass` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertTest() {
|
||||
for (int id = 100; id < 200; id++) {
|
||||
Db.of("mysql").insert(Entity.of("user")//
|
||||
@@ -41,22 +39,24 @@ public class MySQLTest {
|
||||
*
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
@Test(expected = SQLException.class)
|
||||
@Ignore
|
||||
@Test
|
||||
@Disabled
|
||||
public void txTest() throws SQLException {
|
||||
Db.of("mysql").tx(db -> {
|
||||
final int update = db.update(Entity.of("user").set("text", "描述100"), Entity.of().set("id", 100));
|
||||
db.update(Entity.of("user").set("text", "描述101"), Entity.of().set("id", 101));
|
||||
if (1 == update) {
|
||||
// 手动指定异常,然后测试回滚触发
|
||||
throw new RuntimeException("Error");
|
||||
}
|
||||
db.update(Entity.of("user").set("text", "描述102"), Entity.of().set("id", 102));
|
||||
Assertions.assertThrows(SQLException.class, ()->{
|
||||
Db.of("mysql").tx(db -> {
|
||||
final int update = db.update(Entity.of("user").set("text", "描述100"), Entity.of().set("id", 100));
|
||||
db.update(Entity.of("user").set("text", "描述101"), Entity.of().set("id", 101));
|
||||
if (1 == update) {
|
||||
// 手动指定异常,然后测试回滚触发
|
||||
throw new RuntimeException("Error");
|
||||
}
|
||||
db.update(Entity.of("user").set("text", "描述102"), Entity.of().set("id", 102));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void pageTest() {
|
||||
final PageResult<Entity> result = Db.of("mysql").page(Entity.of("user"), new Page(2, 10));
|
||||
for (final Entity entity : result) {
|
||||
@@ -65,20 +65,20 @@ public class MySQLTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void getTimeStampTest() {
|
||||
final List<Entity> all = Db.of("mysql").findAll("test");
|
||||
Console.log(all);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void upsertTest() {
|
||||
final Db db = Db.of("mysql");
|
||||
db.insert(Entity.of("testuser").set("id", 1).set("account", "ice").set("pass", "123456"));
|
||||
db.upsert(Entity.of("testuser").set("id", 1).set("account", "icefairy").set("pass", "a123456"));
|
||||
final Entity user = db.get(Entity.of("testuser").set("id", 1));
|
||||
System.out.println("user======="+user.getStr("account")+"___"+user.getStr("pass"));
|
||||
Assert.assertEquals(user.getStr("account"), "icefairy");
|
||||
Assertions.assertEquals(user.getStr("account"), "icefairy");
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,8 @@ package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.db.sql.NamedSql;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -23,9 +23,9 @@ public class NamedSqlTest {
|
||||
|
||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
//未指定参数原样输出
|
||||
Assert.assertEquals("select * from table where id=@id and name = ? and nickName = ?", namedSql.getSql());
|
||||
Assert.assertEquals("张三", namedSql.getParams()[0]);
|
||||
Assert.assertEquals("小豆豆", namedSql.getParams()[1]);
|
||||
Assertions.assertEquals("select * from table where id=@id and name = ? and nickName = ?", namedSql.getSql());
|
||||
Assertions.assertEquals("张三", namedSql.getParams()[0]);
|
||||
Assertions.assertEquals("小豆豆", namedSql.getParams()[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -40,11 +40,11 @@ public class NamedSqlTest {
|
||||
.build();
|
||||
|
||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql());
|
||||
Assertions.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql());
|
||||
//指定了null参数的依旧替换,参数值为null
|
||||
Assert.assertNull(namedSql.getParams()[0]);
|
||||
Assert.assertEquals("张三", namedSql.getParams()[1]);
|
||||
Assert.assertEquals("小豆豆", namedSql.getParams()[2]);
|
||||
Assertions.assertNull(namedSql.getParams()[0]);
|
||||
Assertions.assertEquals("张三", namedSql.getParams()[1]);
|
||||
Assertions.assertEquals("小豆豆", namedSql.getParams()[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +57,7 @@ public class NamedSqlTest {
|
||||
.build();
|
||||
|
||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals(sql, namedSql.getSql());
|
||||
Assertions.assertEquals(sql, namedSql.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +70,7 @@ public class NamedSqlTest {
|
||||
.build();
|
||||
|
||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals(sql, namedSql.getSql());
|
||||
Assertions.assertEquals(sql, namedSql.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,10 +79,10 @@ public class NamedSqlTest {
|
||||
final HashMap<String, Object> paramMap = MapUtil.of("ids", new int[]{1, 2, 3});
|
||||
|
||||
final NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals("select * from user where id in (?,?,?)", namedSql.getSql());
|
||||
Assert.assertEquals(1, namedSql.getParams()[0]);
|
||||
Assert.assertEquals(2, namedSql.getParams()[1]);
|
||||
Assert.assertEquals(3, namedSql.getParams()[2]);
|
||||
Assertions.assertEquals("select * from user where id in (?,?,?)", namedSql.getSql());
|
||||
Assertions.assertEquals(1, namedSql.getParams()[0]);
|
||||
Assertions.assertEquals(2, namedSql.getParams()[1]);
|
||||
Assertions.assertEquals(3, namedSql.getParams()[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,10 +93,10 @@ public class NamedSqlTest {
|
||||
final String sql = "select * from user where name = @name1 and age = @age1";
|
||||
|
||||
List<Entity> query = Db.of().query(sql, paramMap);
|
||||
Assert.assertEquals(1, query.size());
|
||||
Assertions.assertEquals(1, query.size());
|
||||
|
||||
// 采用传统方式查询是否能识别Map类型参数
|
||||
query = Db.of().query(sql, new Object[]{paramMap});
|
||||
Assert.assertEquals(1, query.size());
|
||||
Assertions.assertEquals(1, query.size());
|
||||
}
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.db.sql.Query;
|
||||
import cn.hutool.db.sql.SqlBuilder;
|
||||
import cn.hutool.db.sql.SqlUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Oracle操作单元测试
|
||||
@@ -34,11 +34,11 @@ public class OracleTest {
|
||||
final String ok = "SELECT * FROM "//
|
||||
+ "( SELECT row_.*, rownum rownum_ from ( SELECT * FROM PMCPERFORMANCEINFO WHERE yearPI = ? ) row_ "//
|
||||
+ "where rownum <= 10) table_alias where table_alias.rownum_ >= 0";//
|
||||
Assert.assertEquals(ok, builder.toString());
|
||||
Assertions.assertEquals(ok, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertTest() {
|
||||
for (int id = 100; id < 200; id++) {
|
||||
Db.of("orcl").insert(Entity.of("T_USER")//
|
||||
@@ -51,7 +51,7 @@ public class OracleTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void pageTest() {
|
||||
final PageResult<Entity> result = Db.of("orcl").page(Entity.of("T_USER"), new Page(2, 10));
|
||||
for (final Entity entity : result) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PageResultTest {
|
||||
|
||||
@@ -9,6 +9,6 @@ public class PageResultTest {
|
||||
public void isLastTest(){
|
||||
// 每页2条,共10条,总共5页,第一页是0,最后一页应该是4
|
||||
final PageResult<String> result = new PageResult<>(4, 2, 10);
|
||||
Assert.assertTrue(result.isLast());
|
||||
Assertions.assertTrue(result.isLast());
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.db.sql.Order;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PageTest {
|
||||
|
||||
@@ -10,8 +10,8 @@ public class PageTest {
|
||||
public void addOrderTest() {
|
||||
final Page page = new Page();
|
||||
page.addOrder(new Order("aaa"));
|
||||
Assert.assertEquals(page.getOrders().length, 1);
|
||||
Assertions.assertEquals(page.getOrders().length, 1);
|
||||
page.addOrder(new Order("aaa"));
|
||||
Assert.assertEquals(page.getOrders().length, 2);
|
||||
Assertions.assertEquals(page.getOrders().length, 2);
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@ package cn.hutool.db;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.file.FileUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -12,7 +12,7 @@ import java.sql.SQLException;
|
||||
public class PicTransferTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void findTest() {
|
||||
Db.of().find(
|
||||
ListUtil.view("NAME", "TYPE", "GROUP", "PIC"),
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* PostgreSQL 单元测试
|
||||
@@ -13,7 +13,7 @@ import org.junit.Test;
|
||||
public class PostgreTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertTest() {
|
||||
for (int id = 100; id < 200; id++) {
|
||||
Db.of("postgre").insert(Entity.of("user")//
|
||||
@@ -24,7 +24,7 @@ public class PostgreTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void pageTest() {
|
||||
final PageResult<Entity> result = Db.of("postgre").page(Entity.of("user"), new Page(2, 10));
|
||||
for (final Entity entity : result) {
|
||||
@@ -33,7 +33,7 @@ public class PostgreTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void upsertTest() {
|
||||
final Db db = Db.of("postgre");
|
||||
db.executeBatch("drop table if exists ctest",
|
||||
@@ -41,6 +41,6 @@ public class PostgreTest {
|
||||
db.insert(Entity.of("ctest").set("id", 1).set("t1", "111").set("t2", "222").set("t3", "333"));
|
||||
db.upsert(Entity.of("ctest").set("id", 1).set("t1", "new111").set("t2", "new222").set("t3", "bew333"),"id");
|
||||
final Entity et=db.get(Entity.of("ctest").set("id", 1));
|
||||
Assert.assertEquals("new111",et.getStr("t1"));
|
||||
Assertions.assertEquals("new111",et.getStr("t1"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 事务性数据库操作单元测试
|
||||
@@ -11,7 +11,7 @@ import org.junit.Test;
|
||||
public class SessionTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void transTest() {
|
||||
final Session session = Session.of("test");
|
||||
session.beginTransaction();
|
||||
@@ -20,7 +20,7 @@ public class SessionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void txTest() {
|
||||
Session.of("test").tx(session -> session.update(Entity.of().set("age", 78), Entity.of("user").set("name", "unitTestUser")));
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* SQL Server操作单元测试
|
||||
@@ -13,13 +13,13 @@ import org.junit.Test;
|
||||
public class SqlServerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void createTableTest() {
|
||||
Db.of("sqlserver").execute("create table T_USER(ID bigint, name varchar(255))");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void insertTest() {
|
||||
for (int id = 100; id < 200; id++) {
|
||||
Db.of("sqlserver").insert(Entity.of("T_USER")//
|
||||
@@ -30,7 +30,7 @@ public class SqlServerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void pageTest() {
|
||||
final PageResult<Entity> result = Db.of("sqlserver").page(Entity.of("T_USER"), new Page(2, 10));
|
||||
for (final Entity entity : result) {
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UpdateTest {
|
||||
|
||||
Db db;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
db = Db.of("test");
|
||||
}
|
||||
@@ -19,13 +19,13 @@ public class UpdateTest {
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void updateTest() {
|
||||
|
||||
// 改
|
||||
final int update = db.update(Entity.of("user").set("age", 88), Entity.of().set("name", "unitTestUser"));
|
||||
Assert.assertTrue(update > 0);
|
||||
Assertions.assertTrue(update > 0);
|
||||
final Entity result2 = db.get("user", "name", "unitTestUser");
|
||||
Assert.assertSame(88, result2.getInt("age"));
|
||||
Assertions.assertSame(88, result2.getInt("age"));
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db.dialect;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,7 +41,7 @@ public class DialectFactoryTest {
|
||||
map.put("mariadb",DRIVER_MARIADB);
|
||||
|
||||
|
||||
map.forEach((k,v) -> Assert.assertEquals(v,
|
||||
map.forEach((k,v) -> Assertions.assertEquals(v,
|
||||
DialectFactory.identifyDriver(k+ RandomUtil.randomString(2),null) ));
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db.dialect;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DriverUtilTest {
|
||||
|
||||
@@ -9,6 +9,6 @@ public class DriverUtilTest {
|
||||
public void identifyDriverTest(){
|
||||
final String url = "jdbc:h2:file:./db/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL";
|
||||
final String driver = DriverUtil.identifyDriver(url); // driver 返回 mysql 的 driver
|
||||
Assert.assertEquals("org.h2.Driver", driver);
|
||||
Assertions.assertEquals("org.h2.Driver", driver);
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db.ds;
|
||||
|
||||
import cn.hutool.db.ds.simple.SimpleDataSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class DataSourceWrapperTest {
|
||||
|
||||
@@ -12,7 +12,7 @@ public class DataSourceWrapperTest {
|
||||
final DSWrapper wrapper = new DSWrapper(simpleDataSource, "test.driver");
|
||||
|
||||
final DSWrapper clone = wrapper.clone();
|
||||
Assert.assertEquals("test.driver", clone.getDriver());
|
||||
Assert.assertEquals(simpleDataSource, clone.getRaw());
|
||||
Assertions.assertEquals("test.driver", clone.getDriver());
|
||||
Assertions.assertEquals(simpleDataSource, clone.getRaw());
|
||||
}
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@ import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.text.split.SplitUtil;
|
||||
import cn.hutool.db.ds.DSUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
@@ -22,24 +22,24 @@ public class MetaUtilTest {
|
||||
@Test
|
||||
public void getTablesTest() {
|
||||
final List<String> tables = MetaUtil.getTables(ds);
|
||||
Assert.assertEquals("user", tables.get(0));
|
||||
Assertions.assertEquals("user", tables.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableMetaTest() {
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user");
|
||||
Assert.assertEquals(SetUtil.of("id"), table.getPkNames());
|
||||
Assertions.assertEquals(SetUtil.of("id"), table.getPkNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnNamesTest() {
|
||||
final String[] names = MetaUtil.getColumnNames(ds, "user");
|
||||
Assert.assertArrayEquals(SplitUtil.splitToArray("id,name,age,birthday,gender", StrUtil.COMMA), names);
|
||||
Assertions.assertArrayEquals(SplitUtil.splitToArray("id,name,age,birthday,gender", StrUtil.COMMA), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableIndexInfoTest() {
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user_1");
|
||||
Assert.assertEquals(table.getIndexInfoList().size(), 2);
|
||||
Assertions.assertEquals(table.getIndexInfoList().size(), 2);
|
||||
}
|
||||
}
|
||||
|
@@ -1,60 +1,18 @@
|
||||
package cn.hutool.db.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 测试用POJO,与测试数据库中的user表对应
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private int age;
|
||||
private String birthday;
|
||||
private boolean gender;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(final int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(final String birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public boolean isGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(final boolean gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [id=" + id + ", name=" + name + ", age=" + age + ", birthday=" + birthday + ", gender=" + gender + "]";
|
||||
}
|
||||
}
|
||||
|
16
hutool-db/src/test/java/cn/hutool/db/pojo/package-info.java
Normal file
16
hutool-db/src/test/java/cn/hutool/db/pojo/package-info.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 测试pojo
|
||||
*/
|
||||
package cn.hutool.db.pojo;
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ConditionBuilderTest {
|
||||
|
||||
@@ -14,8 +14,8 @@ public class ConditionBuilderTest {
|
||||
|
||||
final ConditionBuilder builder = ConditionBuilder.of(c1, c2, c3);
|
||||
final String sql = builder.build();
|
||||
Assert.assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql);
|
||||
Assert.assertEquals(1, builder.getParamValues().size());
|
||||
Assert.assertEquals("%aaa", builder.getParamValues().get(0));
|
||||
Assertions.assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql);
|
||||
Assertions.assertEquals(1, builder.getParamValues().size());
|
||||
Assertions.assertEquals("%aaa", builder.getParamValues().get(0));
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ConditionGroupTest {
|
||||
@Test
|
||||
@@ -22,7 +22,7 @@ public class ConditionGroupTest {
|
||||
|
||||
final ConditionBuilder conditionBuilder = ConditionBuilder.of(cg2, condition4);
|
||||
|
||||
Assert.assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build());
|
||||
Assert.assertEquals(ListUtil.view("A", "B", "C", "D"), conditionBuilder.getParamValues());
|
||||
Assertions.assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build());
|
||||
Assertions.assertEquals(ListUtil.view("A", "B", "C", "D"), conditionBuilder.getParamValues());
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -10,62 +10,62 @@ public class ConditionTest {
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final Condition conditionNull = new Condition("user", null);
|
||||
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
||||
Assertions.assertEquals("user IS NULL", conditionNull.toString());
|
||||
|
||||
final Condition conditionNotNull = new Condition("user", "!= null");
|
||||
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
||||
Assertions.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
||||
|
||||
final Condition condition2 = new Condition("user", "= zhangsan");
|
||||
Assert.assertEquals("user = ?", condition2.toString());
|
||||
Assertions.assertEquals("user = ?", condition2.toString());
|
||||
|
||||
final Condition conditionLike = new Condition("user", "like %aaa");
|
||||
Assert.assertEquals("user LIKE ?", conditionLike.toString());
|
||||
Assertions.assertEquals("user LIKE ?", conditionLike.toString());
|
||||
|
||||
final Condition conditionIn = new Condition("user", "in 1,2,3");
|
||||
Assert.assertEquals("user IN (?,?,?)", conditionIn.toString());
|
||||
Assertions.assertEquals("user IN (?,?,?)", conditionIn.toString());
|
||||
|
||||
final Condition conditionBetween = new Condition("user", "between 12 and 13");
|
||||
Assert.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
|
||||
Assertions.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringNoPlaceHolderTest() {
|
||||
final Condition conditionNull = new Condition("user", null);
|
||||
conditionNull.setPlaceHolder(false);
|
||||
Assert.assertEquals("user IS NULL", conditionNull.toString());
|
||||
Assertions.assertEquals("user IS NULL", conditionNull.toString());
|
||||
|
||||
final Condition conditionNotNull = new Condition("user", "!= null");
|
||||
conditionNotNull.setPlaceHolder(false);
|
||||
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
||||
Assertions.assertEquals("user IS NOT NULL", conditionNotNull.toString());
|
||||
|
||||
final Condition conditionEquals = new Condition("user", "= zhangsan");
|
||||
conditionEquals.setPlaceHolder(false);
|
||||
Assert.assertEquals("user = zhangsan", conditionEquals.toString());
|
||||
Assertions.assertEquals("user = zhangsan", conditionEquals.toString());
|
||||
|
||||
final Condition conditionLike = new Condition("user", "like %aaa");
|
||||
conditionLike.setPlaceHolder(false);
|
||||
Assert.assertEquals("user LIKE '%aaa'", conditionLike.toString());
|
||||
Assertions.assertEquals("user LIKE '%aaa'", conditionLike.toString());
|
||||
|
||||
final Condition conditionIn = new Condition("user", "in 1,2,3");
|
||||
conditionIn.setPlaceHolder(false);
|
||||
Assert.assertEquals("user IN (1,2,3)", conditionIn.toString());
|
||||
Assertions.assertEquals("user IN (1,2,3)", conditionIn.toString());
|
||||
|
||||
final Condition conditionBetween = new Condition("user", "between 12 and 13");
|
||||
conditionBetween.setPlaceHolder(false);
|
||||
Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
|
||||
Assertions.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest(){
|
||||
final Condition age = Condition.parse("age", "< 10");
|
||||
Assert.assertEquals("age < ?", age.toString());
|
||||
Assertions.assertEquals("age < ?", age.toString());
|
||||
// issue I38LTM
|
||||
Assert.assertSame(BigDecimal.class, age.getValue().getClass());
|
||||
Assertions.assertSame(BigDecimal.class, age.getValue().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInTest(){
|
||||
final Condition age = Condition.parse("age", "in 1,2,3");
|
||||
Assert.assertEquals("age IN (?,?,?)", age.toString());
|
||||
Assertions.assertEquals("age IN (?,?,?)", age.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,23 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SqlBuilderTest {
|
||||
|
||||
@Test
|
||||
public void queryNullTest() {
|
||||
final SqlBuilder builder = SqlBuilder.of().select().from("user").where(new Condition("name", "= null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build());
|
||||
Assertions.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build());
|
||||
|
||||
final SqlBuilder builder2 = SqlBuilder.of().select().from("user").where(new Condition("name", "is null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
|
||||
Assertions.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
|
||||
|
||||
final SqlBuilder builder3 = SqlBuilder.of().select().from("user").where(new Condition("name", "!= null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
|
||||
Assertions.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
|
||||
|
||||
final SqlBuilder builder4 = SqlBuilder.of().select().from("user").where(new Condition("name", "is not null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
|
||||
Assertions.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -29,7 +29,7 @@ public class SqlBuilderTest {
|
||||
new Condition("username", "abc", Condition.LikeType.Contains)
|
||||
).orderBy(new Order("id"));
|
||||
|
||||
Assert.assertEquals("SELECT id,username FROM user INNER JOIN role ON user.id = role.user_id WHERE age >= ? AND username LIKE ? ORDER BY id", builder.build());
|
||||
Assertions.assertEquals("SELECT id,username FROM user INNER JOIN role ON user.id = role.user_id WHERE age >= ? AND username LIKE ? ORDER BY id", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,6 +42,6 @@ public class SqlBuilderTest {
|
||||
sqlBuilder.from("user");
|
||||
sqlBuilder.where(conditionEquals);
|
||||
final String s1 = sqlBuilder.build();
|
||||
Assert.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1);
|
||||
Assertions.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SqlFormatterTest {
|
||||
|
||||
|
Reference in New Issue
Block a user