单元测试由Junit4变更为Junit5

This commit is contained in:
Looly
2024-08-09 14:32:30 +08:00
parent 155c43a6a3
commit c7e0bc5d9f
568 changed files with 7794 additions and 7671 deletions

View File

@@ -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 static 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;
@@ -28,96 +28,96 @@ public class CRUDTest {
@Test
public void findIsNullTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", "is null"));
Assert.assertEquals(0, results.size());
assertEquals(0, results.size());
}
@Test
public void findIsNullTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", "= null"));
Assert.assertEquals(0, results.size());
assertEquals(0, results.size());
}
@Test
public void findIsNullTest3() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", null));
Assert.assertEquals(0, results.size());
assertEquals(0, results.size());
}
@Test
public void findBetweenTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", "between '18' and '40'"));
Assert.assertEquals(1, results.size());
assertEquals(1, results.size());
}
@Test
public void findByBigIntegerTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", new BigInteger("12")));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findByBigDecimalTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", new BigDecimal("12")));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findLikeTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("name", "like \"%三%\""));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findLikeTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("name", new Condition("name", "", LikeType.Contains)));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findLikeTest3() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("name", new Condition("name", null, LikeType.Contains)));
Assert.assertEquals(0, results.size());
assertEquals(0, results.size());
}
@Test
public void findInTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("id", "in 1,2,3"));
Console.log(results);
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findInTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user")
.set("id", new Condition("id", new long[]{1, 2, 3})));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findInTest3() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user")
.set("id", new long[]{1, 2, 3}));
Assert.assertEquals(2, results.size());
assertEquals(2, results.size());
}
@Test
public void findAllTest() throws SQLException {
List<Entity> results = db.findAll("user");
Assert.assertEquals(4, results.size());
assertEquals(4, results.size());
}
@Test
public void findTest() throws SQLException {
List<Entity> find = db.find(CollUtil.newArrayList("name AS name2"), Entity.create("user"), EntityListHandler.create());
Assert.assertFalse(find.isEmpty());
assertFalse(find.isEmpty());
}
@Test
public void findActiveTest() {
ActiveEntity entity = new ActiveEntity(db, "user");
entity.setFieldNames("name AS name2").load();
Assert.assertEquals("user", entity.getTableName());
Assert.assertFalse(entity.isEmpty());
assertEquals("user", entity.getTableName());
assertFalse(entity.isEmpty());
}
/**
@@ -126,30 +126,30 @@ public class CRUDTest {
* @throws SQLException SQL异常
*/
@Test
@Ignore
@Disabled
public void crudTest() throws SQLException {
// 增
Long id = db.insertForGeneratedKey(Entity.create("user").set("name", "unitTestUser").set("age", 66));
Assert.assertTrue(id > 0);
assertTrue(id > 0);
Entity result = db.get("user", "name", "unitTestUser");
Assert.assertSame(66, result.getInt("age"));
assertSame(66, result.getInt("age"));
// 改
int update = db.update(Entity.create().set("age", 88), Entity.create("user").set("name", "unitTestUser"));
Assert.assertTrue(update > 0);
assertTrue(update > 0);
Entity result2 = db.get("user", "name", "unitTestUser");
Assert.assertSame(88, result2.getInt("age"));
assertSame(88, result2.getInt("age"));
// 删
int del = db.del("user", "name", "unitTestUser");
Assert.assertTrue(del > 0);
assertTrue(del > 0);
Entity result3 = db.get("user", "name", "unitTestUser");
Assert.assertNull(result3);
assertNull(result3);
}
@Test
@Ignore
@Disabled
public void insertBatchTest() throws SQLException {
User user1 = new User();
user1.setName("张三");
@@ -175,7 +175,7 @@ public class CRUDTest {
}
@Test
@Ignore
@Disabled
public void insertBatchOneTest() throws SQLException {
User user1 = new User();
user1.setName("张三");
@@ -195,6 +195,6 @@ public class CRUDTest {
public void selectInTest() throws SQLException {
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());
assertEquals(2, results.size());
}
}

View File

@@ -5,8 +5,8 @@ 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.Disabled;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.List;
@@ -17,7 +17,7 @@ import java.util.List;
* @author looly
*
*/
@Ignore
@Disabled
public class ConcurentTest {
private Db db;

View File

@@ -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 static 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,22 +22,22 @@ public class DbTest {
@Test
public void queryTest() throws SQLException {
List<Entity> find = Db.use().query("select * from user where age = ?", 18);
Assert.assertEquals("王五", find.get(0).get("name"));
assertEquals("王五", find.get(0).get("name"));
}
@Test
public void findTest() throws SQLException {
List<Entity> find = Db.use().find(Entity.create("user").set("age", 18));
Assert.assertEquals("王五", find.get(0).get("name"));
assertEquals("王五", find.get(0).get("name"));
}
@Test
public void pageTest() throws SQLException {
// 测试数据库中一共4条数据第0页有3条第1页有1条
List<Entity> page0 = Db.use().page(Entity.create("user"), 0, 3);
Assert.assertEquals(3, page0.size());
assertEquals(3, page0.size());
List<Entity> page1 = Db.use().page(Entity.create("user"), 1, 3);
Assert.assertEquals(1, page1.size());
assertEquals(1, page1.size());
}
@Test
@@ -46,11 +46,11 @@ public class DbTest {
// 测试数据库中一共4条数据第0页有3条第1页有1条
List<Entity> page0 = Db.use().page(
sql, Page.of(0, 3));
Assert.assertEquals(3, page0.size());
assertEquals(3, page0.size());
List<Entity> page1 = Db.use().page(
sql, Page.of(1, 3));
Assert.assertEquals(1, page1.size());
assertEquals(1, page1.size());
}
@Test
@@ -59,42 +59,42 @@ public class DbTest {
PageResult<Entity> result = Db.use().page(
sql, Page.of(0, 3), "张三");
Assert.assertEquals(2, result.getTotal());
Assert.assertEquals(1, result.getTotalPage());
Assert.assertEquals(2, result.size());
assertEquals(2, result.getTotal());
assertEquals(1, result.getTotalPage());
assertEquals(2, result.size());
}
@Test
public void countTest() throws SQLException {
final long count = Db.use().count("select * from user");
Assert.assertEquals(4, count);
assertEquals(4, count);
}
@Test
public void countByQueryTest() throws SQLException {
final long count = Db.use().count(Entity.create("user"));
Assert.assertEquals(4, count);
assertEquals(4, count);
}
@Test
public void countTest2() throws SQLException {
final long count = Db.use().count("select * from user order by name DESC");
Assert.assertEquals(4, count);
assertEquals(4, count);
}
@Test
public void findLikeTest() throws SQLException {
// 方式1
List<Entity> find = Db.use().find(Entity.create("user").set("name", "like 王%"));
Assert.assertEquals("王五", find.get(0).get("name"));
assertEquals("王五", find.get(0).get("name"));
// 方式2
find = Db.use().findLike("user", "name", "", Condition.LikeType.StartWith);
Assert.assertEquals("王五", find.get(0).get("name"));
assertEquals("王五", find.get(0).get("name"));
// 方式3
find = Db.use().query("select * from user where name like ?", "王%");
Assert.assertEquals("王五", find.get(0).get("name"));
assertEquals("王五", find.get(0).get("name"));
}
@Test
@@ -106,11 +106,11 @@ public class DbTest {
for (Entity entity : find) {
StaticLog.debug("{}", entity);
}
Assert.assertEquals("unitTestUser", find.get(0).get("name"));
assertEquals("unitTestUser", find.get(0).get("name"));
}
@Test
@Ignore
@Disabled
public void txTest() throws SQLException {
Db.use().tx(db -> {
db.insert(Entity.create("user").set("name", "unitTestUser2"));
@@ -120,7 +120,7 @@ public class DbTest {
}
@Test
@Ignore
@Disabled
public void queryFetchTest() throws SQLException {
// https://gitee.com/dromara/hutool/issues/I4JXWN
Db.use().query((conn->{
@@ -134,7 +134,7 @@ public class DbTest {
}
@Test
@Ignore
@Disabled
public void findWithDotTest() throws SQLException {
Db.use().find(Entity.create("user").set("a.b", "1"));
}

View File

@@ -1,23 +1,23 @@
package cn.hutool.db;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.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);
@@ -33,18 +33,18 @@ public class DerbyTest {
db.insert(Entity.create("test").set("a", 3).set("b", 31));
db.insert(Entity.create("test").set("a", 4).set("b", 41));
}
@Test
@Ignore
@Disabled
public void queryTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
assertEquals(4, query.size());
}
@Test
@Ignore
@Disabled
public void findTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
Assert.assertEquals(4, query.size());
assertEquals(4, query.size());
}
}

View File

@@ -1,9 +1,9 @@
package cn.hutool.db;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
@@ -28,11 +28,11 @@ public class DmTest {
}
@Test
@Ignore
@Disabled
public void upsertTest() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
db.upsert(Entity.create("test").set("a", 1).set("b", 111), "a");
Entity a1 = db.get("test", "a", 1);
Assert.assertEquals(Long.valueOf(111), a1.getLong("b"));
assertEquals(Long.valueOf(111), a1.getLong("b"));
}
}

View File

@@ -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 static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -31,7 +31,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -40,7 +40,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -50,7 +50,7 @@ public class DsTest {
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -59,7 +59,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -68,7 +68,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -77,7 +77,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -86,7 +86,7 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
@Test
@@ -94,8 +94,8 @@ public class DsTest {
// https://gitee.com/dromara/hutool/issues/I4T7XZ
DSFactory.setCurrentDSFactory(new C3p0DSFactory());
ComboPooledDataSource ds = (ComboPooledDataSource) ((DataSourceWrapper) DSFactory.get("mysql")).getRaw();
Assert.assertEquals("root", ds.getUser());
Assert.assertEquals("123456", ds.getPassword());
assertEquals("root", ds.getUser());
assertEquals("123456", ds.getPassword());
}
@Test
@@ -104,6 +104,6 @@ public class DsTest {
DataSource ds = DSFactory.get("test");
Db db = Db.use(ds);
List<Entity> all = db.findAll("user");
Assert.assertTrue(CollUtil.isNotEmpty(all));
assertTrue(CollUtil.isNotEmpty(all));
}
}

View File

@@ -1,8 +1,8 @@
package cn.hutool.db;
import cn.hutool.db.pojo.User;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/**
* Entity测试
@@ -19,8 +19,8 @@ public class EntityTest {
user.setName("test");
Entity entity = Entity.create("testTable").parseBean(user);
Assert.assertEquals(Integer.valueOf(1), entity.getInt("id"));
Assert.assertEquals("test", entity.getStr("name"));
assertEquals(Integer.valueOf(1), entity.getInt("id"));
assertEquals("test", entity.getStr("name"));
}
@Test
@@ -30,9 +30,9 @@ public class EntityTest {
user.setName("test");
Entity entity = Entity.create().parseBean(user);
Assert.assertEquals(Integer.valueOf(1), entity.getInt("id"));
Assert.assertEquals("test", entity.getStr("name"));
Assert.assertEquals("user", entity.getTableName());
assertEquals(Integer.valueOf(1), entity.getInt("id"));
assertEquals("test", entity.getStr("name"));
assertEquals("user", entity.getTableName());
}
@Test
@@ -42,9 +42,9 @@ public class EntityTest {
Entity entity = Entity.create().parseBean(user, false, true);
Assert.assertFalse(entity.containsKey("id"));
Assert.assertEquals("test", entity.getStr("name"));
Assert.assertEquals("user", entity.getTableName());
assertFalse(entity.containsKey("id"));
assertEquals("test", entity.getStr("name"));
assertEquals("user", entity.getTableName());
}
@Test
@@ -52,7 +52,7 @@ public class EntityTest {
Entity entity = Entity.create().set("ID", 2).set("NAME", "testName");
User user = entity.toBeanIgnoreCase(User.class);
Assert.assertEquals(Integer.valueOf(2), user.getId());
Assert.assertEquals("testName", user.getName());
assertEquals(Integer.valueOf(2), user.getId());
assertEquals("testName", user.getName());
}
}

View File

@@ -1,16 +1,16 @@
package cn.hutool.db;
import cn.hutool.db.pojo.User;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.List;
/**
* Entity测试
*
*
* @author looly
*
*/
@@ -26,43 +26,43 @@ public class FindBeanTest {
@Test
public void findAllBeanTest() throws SQLException {
List<User> results = db.findAll(Entity.create("user"), User.class);
Assert.assertEquals(4, results.size());
Assert.assertEquals(Integer.valueOf(1), results.get(0).getId());
Assert.assertEquals("张三", results.get(0).getName());
assertEquals(4, results.size());
assertEquals(Integer.valueOf(1), results.get(0).getId());
assertEquals("张三", results.get(0).getName());
}
@Test
@SuppressWarnings("rawtypes")
public void findAllListTest() throws SQLException {
List<List> results = db.findAll(Entity.create("user"), List.class);
Assert.assertEquals(4, results.size());
Assert.assertEquals(1, results.get(0).get(0));
Assert.assertEquals("张三", results.get(0).get(1));
assertEquals(4, results.size());
assertEquals(1, results.get(0).get(0));
assertEquals("张三", results.get(0).get(1));
}
@Test
public void findAllArrayTest() throws SQLException {
List<Object[]> results = db.findAll(Entity.create("user"), Object[].class);
Assert.assertEquals(4, results.size());
Assert.assertEquals(1, results.get(0)[0]);
Assert.assertEquals("张三", results.get(0)[1]);
assertEquals(4, results.size());
assertEquals(1, results.get(0)[0]);
assertEquals("张三", results.get(0)[1]);
}
@Test
public void findAllStringTest() throws SQLException {
List<String> results = db.findAll(Entity.create("user"), String.class);
Assert.assertEquals(4, results.size());
assertEquals(4, results.size());
}
@Test
public void findAllStringArrayTest() throws SQLException {
List<String[]> results = db.findAll(Entity.create("user"), String[].class);
Assert.assertEquals(4, results.size());
Assert.assertEquals("1", results.get(0)[0]);
Assert.assertEquals("张三", results.get(0)[1]);
assertEquals(4, results.size());
assertEquals("1", results.get(0)[0]);
assertEquals("张三", results.get(0)[1]);
}
}

View File

@@ -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 static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.List;
@@ -34,7 +34,7 @@ public class H2Test {
@Test
public void queryTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
assertEquals(4, query.size());
}
@Test
@@ -45,13 +45,13 @@ public class H2Test {
.put("b", 31)
.build();
List<Entity> query = Db.use(DS_GROUP_NAME).page(sql, Page.of(0, 3), paramMap);
Assert.assertEquals(1, query.size());
assertEquals(1, 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());
assertEquals(4, query.size());
}
@Test
@@ -59,6 +59,6 @@ public class H2Test {
Db db=Db.use(DS_GROUP_NAME);
db.upsert(Entity.create("test").set("a",1).set("b",111),"a");
Entity a1=db.get("test","a",1);
Assert.assertEquals(Long.valueOf(111),a1.getLong("b"));
assertEquals(Long.valueOf(111),a1.getLong("b"));
}
}

View File

@@ -1,22 +1,22 @@
package cn.hutool.db;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.List;
/**
* HSQLDB数据库单元测试
*
*
* @author looly
*
*/
public class HsqldbTest {
private static final String DS_GROUP_NAME = "hsqldb";
@BeforeClass
public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
@@ -26,16 +26,16 @@ public class HsqldbTest {
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 connTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
Assert.assertEquals(4, query.size());
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());
assertEquals(4, query.size());
}
}

View File

@@ -13,8 +13,8 @@
package cn.hutool.db;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
@@ -28,8 +28,8 @@ public class IssueI73770Test {
.page("select * from user where id = ?"
, new Page(0, 10), User.class, 9);
Assert.assertEquals(1, result.size());
Assert.assertEquals(Integer.valueOf(9), result.get(0).getId());
assertEquals(1, result.size());
assertEquals(Integer.valueOf(9), result.get(0).getId());
}
@Data

View File

@@ -4,15 +4,15 @@ import cn.hutool.core.lang.Console;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.meta.MetaUtil;
import cn.hutool.db.meta.Table;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
public class IssueI9BANETest {
@Test
@Ignore
@Disabled
public void metaTest() throws SQLException {
final Db db = Db.use("orcl");
db.find(Entity.create("\"1234\""));

View File

@@ -1,10 +1,10 @@
package cn.hutool.db;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.List;
@@ -16,14 +16,14 @@ import java.util.List;
*/
public class MySQLTest {
@BeforeClass
@Ignore
@Disabled
public static void createTable() throws SQLException {
Db db = Db.use("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() throws SQLException {
for (int id = 100; id < 200; id++) {
Db.use("mysql").insert(Entity.create("user")//
@@ -42,7 +42,7 @@ public class MySQLTest {
* @throws SQLException SQL异常
*/
@Test(expected = SQLException.class)
@Ignore
@Disabled
public void txTest() throws SQLException {
Db.use("mysql").tx(db -> {
int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
@@ -56,7 +56,7 @@ public class MySQLTest {
}
@Test
@Ignore
@Disabled
public void pageTest() throws SQLException {
PageResult<Entity> result = Db.use("mysql").page(Entity.create("user"), new Page(2, 10));
for (Entity entity : result) {
@@ -65,20 +65,20 @@ public class MySQLTest {
}
@Test
@Ignore
@Disabled
public void getTimeStampTest() throws SQLException {
final List<Entity> all = Db.use("mysql").findAll("test");
Console.log(all);
}
@Test
@Ignore
@Disabled
public void upsertTest() throws SQLException {
Db db = Db.use("mysql");
db.insert(Entity.create("testuser").set("id", 1).set("account", "ice").set("pass", "123456"));
db.upsert(Entity.create("testuser").set("id", 1).set("account", "icefairy").set("pass", "a123456"));
Entity user = db.get(Entity.create("testuser").set("id", 1));
System.out.println("user======="+user.getStr("account")+"___"+user.getStr("pass"));
Assert.assertEquals(user.getStr("account"), new String("icefairy"));
assertEquals(user.getStr("account"), new String("icefairy"));
}
}

View File

@@ -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 static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.HashMap;
@@ -24,9 +24,9 @@ public class NamedSqlTest {
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]);
assertEquals("select * from table where id=@id and name = ? and nickName = ?", namedSql.getSql());
assertEquals("张三", namedSql.getParams()[0]);
assertEquals("小豆豆", namedSql.getParams()[1]);
}
@Test
@@ -41,11 +41,11 @@ public class NamedSqlTest {
.build();
NamedSql namedSql = new NamedSql(sql, paramMap);
Assert.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql());
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]);
assertNull(namedSql.getParams()[0]);
assertEquals("张三", namedSql.getParams()[1]);
assertEquals("小豆豆", namedSql.getParams()[2]);
}
@Test
@@ -58,7 +58,7 @@ public class NamedSqlTest {
.build();
NamedSql namedSql = new NamedSql(sql, paramMap);
Assert.assertEquals(sql, namedSql.getSql());
assertEquals(sql, namedSql.getSql());
}
@Test
@@ -71,7 +71,7 @@ public class NamedSqlTest {
.build();
NamedSql namedSql = new NamedSql(sql, paramMap);
Assert.assertEquals(sql, namedSql.getSql());
assertEquals(sql, namedSql.getSql());
}
@Test
@@ -80,10 +80,10 @@ public class NamedSqlTest {
final HashMap<String, Object> paramMap = MapUtil.of("ids", new int[]{1, 2, 3});
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]);
assertEquals("select * from user where id in (?,?,?)", namedSql.getSql());
assertEquals(1, namedSql.getParams()[0]);
assertEquals(2, namedSql.getParams()[1]);
assertEquals(3, namedSql.getParams()[2]);
}
@Test
@@ -94,10 +94,10 @@ public class NamedSqlTest {
String sql = "select * from user where name = @name1 and age = @age1";
List<Entity> query = Db.use().query(sql, paramMap);
Assert.assertEquals(1, query.size());
assertEquals(1, query.size());
// 采用传统方式查询是否能识别Map类型参数
query = Db.use().query(sql, new Object[]{paramMap});
Assert.assertEquals(1, query.size());
assertEquals(1, query.size());
}
}

View File

@@ -4,15 +4,15 @@ 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 static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
/**
* Oracle操作单元测试
*
*
* @author looly
*
*/
@@ -36,11 +36,11 @@ public class OracleTest {
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());
assertEquals(ok, builder.toString());
}
@Test
@Ignore
@Disabled
public void insertTest() throws SQLException {
for (int id = 100; id < 200; id++) {
Db.use("orcl").insert(Entity.create("T_USER")//
@@ -53,7 +53,7 @@ public class OracleTest {
}
@Test
@Ignore
@Disabled
public void pageTest() throws SQLException {
PageResult<Entity> result = Db.use("orcl").page(Entity.create("T_USER"), new Page(2, 10));
for (Entity entity : result) {

View File

@@ -1,7 +1,7 @@
package cn.hutool.db;
import org.junit.Assert;
import org.junit.Test;
import static 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());
assertTrue(result.isLast());
}
}

View File

@@ -1,8 +1,8 @@
package cn.hutool.db;
import cn.hutool.db.sql.Order;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class PageTest {
@@ -10,8 +10,8 @@ public class PageTest {
public void addOrderTest() {
Page page = new Page();
page.addOrder(new Order("aaa"));
Assert.assertEquals(page.getOrders().length, 1);
assertEquals(page.getOrders().length, 1);
page.addOrder(new Order("aaa"));
Assert.assertEquals(page.getOrders().length, 2);
assertEquals(page.getOrders().length, 2);
}
}

View File

@@ -3,8 +3,8 @@ package cn.hutool.db;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.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() throws SQLException {
Db.use().find(
ListUtil.of("NAME", "TYPE", "GROUP", "PIC"),

View File

@@ -2,9 +2,9 @@ package cn.hutool.db;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import cn.hutool.core.lang.Console;
@@ -16,7 +16,7 @@ import cn.hutool.core.lang.Console;
public class PostgreTest {
@Test
@Ignore
@Disabled
public void insertTest() throws SQLException {
for (int id = 100; id < 200; id++) {
Db.use("postgre").insert(Entity.create("user")//
@@ -27,7 +27,7 @@ public class PostgreTest {
}
@Test
@Ignore
@Disabled
public void pageTest() throws SQLException {
PageResult<Entity> result = Db.use("postgre").page(Entity.create("user"), new Page(2, 10));
for (Entity entity : result) {
@@ -36,7 +36,7 @@ public class PostgreTest {
}
@Test
@Ignore
@Disabled
public void upsertTest() throws SQLException {
Db db = Db.use("postgre");
db.executeBatch("drop table if exists ctest",
@@ -44,6 +44,6 @@ public class PostgreTest {
db.insert(Entity.create("ctest").set("id", 1).set("t1", "111").set("t2", "222").set("t3", "333"));
db.upsert(Entity.create("ctest").set("id", 1).set("t1", "new111").set("t2", "new222").set("t3", "bew333"),"id");
Entity et=db.get(Entity.create("ctest").set("id", 1));
Assert.assertEquals("new111",et.getStr("t1"));
assertEquals("new111",et.getStr("t1"));
}
}

View File

@@ -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;
import java.sql.SQLException;
@@ -11,9 +11,9 @@ import java.sql.SQLException;
*
*/
public class SessionTest {
@Test
@Ignore
@Disabled
public void transTest() {
Session session = Session.create("test");
try {
@@ -24,9 +24,9 @@ public class SessionTest {
session.quietRollback();
}
}
@Test
@Ignore
@Disabled
public void txTest() throws SQLException {
Session.create("test").tx(session -> session.update(Entity.create().set("age", 78), Entity.create("user").set("name", "unitTestUser")));
}

View File

@@ -2,27 +2,27 @@ package cn.hutool.db;
import java.sql.SQLException;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import cn.hutool.core.lang.Console;
/**
* SQL Server操作单元测试
*
*
* @author looly
*
*/
public class SqlServerTest {
@Test
@Ignore
@Disabled
public void createTableTest() throws SQLException {
Db.use("sqlserver").execute("create table T_USER(ID bigint, name varchar(255))");
}
@Test
@Ignore
@Disabled
public void insertTest() throws SQLException {
for (int id = 100; id < 200; id++) {
Db.use("sqlserver").insert(Entity.create("T_USER")//
@@ -33,7 +33,7 @@ public class SqlServerTest {
}
@Test
@Ignore
@Disabled
public void pageTest() throws SQLException {
PageResult<Entity> result = Db.use("sqlserver").page(Entity.create("T_USER"), new Page(2, 10));
for (Entity entity : result) {

View File

@@ -1,34 +1,34 @@
package cn.hutool.db;
import org.junit.Assert;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.sql.SQLException;
public class UpdateTest {
Db db;
@Before
public void init() {
db = Db.use("test");
}
/**
* 对更新做单元测试
*
*
* @throws SQLException SQL异常
*/
@Test
@Ignore
@Disabled
public void updateTest() throws SQLException {
// 改
int update = db.update(Entity.create("user").set("age", 88), Entity.create().set("name", "unitTestUser"));
Assert.assertTrue(update > 0);
assertTrue(update > 0);
Entity result2 = db.get("user", "name", "unitTestUser");
Assert.assertSame(88, result2.getInt("age"));
assertSame(88, result2.getInt("age"));
}
}

View File

@@ -1,9 +1,9 @@
package cn.hutool.db;
import cn.hutool.db.sql.Wrapper;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author bwcx_jzy
@@ -12,32 +12,32 @@ import org.junit.Test;
public class WrapperTest {
@Test
@Ignore
@Disabled
public void test() {
Wrapper wrapper = new Wrapper('`');
String originalName = "name";
String wrapName = wrapper.wrap(originalName);
String unWrapName = wrapper.unWrap(wrapName);
Assert.assertEquals(unWrapName, originalName);
assertEquals(unWrapName, originalName);
}
@Test
@Ignore
@Disabled
public void testDotWrap() {
Wrapper wrapper = new Wrapper('`');
String originalName = "name.age";
String wrapName = wrapper.wrap(originalName);
String unWrapName = wrapper.unWrap(wrapName);
Assert.assertEquals(unWrapName, originalName);
assertEquals(unWrapName, originalName);
}
@Test
@Ignore
@Disabled
public void testError() {
Wrapper wrapper = new Wrapper('`');
String originalName = "name.age*";
String wrapName = wrapper.wrap(originalName);
String unWrapName = wrapper.unWrap(wrapName);
Assert.assertEquals(unWrapName, originalName);
assertEquals(unWrapName, originalName);
}
}

View File

@@ -1,8 +1,8 @@
package cn.hutool.db.dialect;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
@@ -44,7 +44,7 @@ public class DialectFactoryTest {
map.put("mariadb",DRIVER_MARIADB);
map.forEach((k,v) -> Assert.assertEquals(v,
map.forEach((k,v) -> assertEquals(v,
DialectFactory.identifyDriver(k+ RandomUtil.randomString(2),null) ));
}

View File

@@ -1,7 +1,7 @@
package cn.hutool.db.dialect;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class DriverUtilTest {
@@ -9,6 +9,6 @@ public class DriverUtilTest {
public void identifyDriverTest(){
String url = "jdbc:h2:file:./db/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL";
String driver = DriverUtil.identifyDriver(url); // driver 返回 mysql 的 driver
Assert.assertEquals("org.h2.Driver", driver);
assertEquals("org.h2.Driver", driver);
}
}

View File

@@ -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 static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class DataSourceWrapperTest {
@@ -12,7 +12,7 @@ public class DataSourceWrapperTest {
final DataSourceWrapper wrapper = new DataSourceWrapper(simpleDataSource, "test.driver");
final DataSourceWrapper clone = wrapper.clone();
Assert.assertEquals("test.driver", clone.getDriver());
Assert.assertEquals(simpleDataSource, clone.getRaw());
assertEquals("test.driver", clone.getDriver());
assertEquals(simpleDataSource, clone.getRaw());
}
}

View File

@@ -13,8 +13,8 @@
package cn.hutool.db.ds;
import cn.hutool.setting.Setting;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
@@ -35,6 +35,6 @@ public class IssueI70J95Test {
public void getDataSourceTest2() {
final Setting dbSetting = new Setting("config/db.setting");
final DataSource dataSource = DSFactory.create(dbSetting).getDataSource("");
Assert.assertNotNull(dataSource);
assertNotNull(dataSource);
}
}

View File

@@ -4,8 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.ds.DSFactory;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.util.List;
@@ -22,25 +22,25 @@ public class MetaUtilTest {
@Test
public void getTablesTest() {
final List<String> tables = MetaUtil.getTables(ds);
Assert.assertEquals("user", tables.get(0));
assertEquals("user", tables.get(0));
}
@Test
public void getTableMetaTest() {
final Table table = MetaUtil.getTableMeta(ds, "user");
Assert.assertEquals(CollectionUtil.newHashSet("id"), table.getPkNames());
assertEquals(CollectionUtil.newHashSet("id"), table.getPkNames());
}
@Test
public void getColumnNamesTest() {
final String[] names = MetaUtil.getColumnNames(ds, "user");
Assert.assertArrayEquals(StrUtil.splitToArray("id,name,age,birthday,gender", ','), names);
assertArrayEquals(StrUtil.splitToArray("id,name,age,birthday,gender", ','), names);
}
@Test
public void getTableIndexInfoTest() {
final Table table = MetaUtil.getTableMeta(ds, "user_1");
Assert.assertEquals(table.getIndexInfoList().size(), 2);
assertEquals(table.getIndexInfoList().size(), 2);
}
/**
@@ -49,6 +49,6 @@ public class MetaUtilTest {
@Test(expected = DbRuntimeException.class)
public void getTableNotExistTest() {
final Table table = MetaUtil.getTableMeta(ds, "user_not_exist");
Assert.assertEquals(table.getIndexInfoList().size(), 2);
assertEquals(table.getIndexInfoList().size(), 2);
}
}

View File

@@ -2,9 +2,9 @@ package cn.hutool.db.nosql;
import cn.hutool.db.nosql.mongo.MongoFactory;
import com.mongodb.client.MongoDatabase;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author VampireAchao
@@ -12,9 +12,9 @@ import org.junit.Test;
public class MongoDBTest {
@Test
@Ignore
@Disabled
public void mongoDSTest() {
MongoDatabase db = MongoFactory.getDS("master").getDb("test");
Assert.assertEquals("test", db.getName());
assertEquals("test", db.getName());
}
}

View File

@@ -1,14 +1,14 @@
package cn.hutool.db.nosql;
import cn.hutool.db.nosql.redis.RedisDS;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
public class RedisDSTest {
@Test
@Ignore
@Disabled
public void redisDSTest(){
final Jedis jedis = RedisDS.create().getJedis();
}

View File

@@ -1,7 +1,7 @@
package cn.hutool.db.sql;
import org.junit.Assert;
import org.junit.Test;
import static 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));
assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql);
assertEquals(1, builder.getParamValues().size());
assertEquals("%aaa", builder.getParamValues().get(0));
}
}

View File

@@ -1,8 +1,8 @@
package cn.hutool.db.sql;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import static 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.of("A", "B", "C", "D"), conditionBuilder.getParamValues());
assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build());
assertEquals(ListUtil.of("A", "B", "C", "D"), conditionBuilder.getParamValues());
}
}

View File

@@ -1,7 +1,7 @@
package cn.hutool.db.sql;
import org.junit.Assert;
import org.junit.Test;
import static 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() {
Condition conditionNull = new Condition("user", null);
Assert.assertEquals("user IS NULL", conditionNull.toString());
assertEquals("user IS NULL", conditionNull.toString());
Condition conditionNotNull = new Condition("user", "!= null");
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
assertEquals("user IS NOT NULL", conditionNotNull.toString());
Condition condition2 = new Condition("user", "= zhangsan");
Assert.assertEquals("user = ?", condition2.toString());
assertEquals("user = ?", condition2.toString());
Condition conditionLike = new Condition("user", "like %aaa");
Assert.assertEquals("user LIKE ?", conditionLike.toString());
assertEquals("user LIKE ?", conditionLike.toString());
Condition conditionIn = new Condition("user", "in 1,2,3");
Assert.assertEquals("user IN (?,?,?)", conditionIn.toString());
assertEquals("user IN (?,?,?)", conditionIn.toString());
Condition conditionBetween = new Condition("user", "between 12 and 13");
Assert.assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
assertEquals("user BETWEEN ? AND ?", conditionBetween.toString());
}
@Test
public void toStringNoPlaceHolderTest() {
Condition conditionNull = new Condition("user", null);
conditionNull.setPlaceHolder(false);
Assert.assertEquals("user IS NULL", conditionNull.toString());
assertEquals("user IS NULL", conditionNull.toString());
Condition conditionNotNull = new Condition("user", "!= null");
conditionNotNull.setPlaceHolder(false);
Assert.assertEquals("user IS NOT NULL", conditionNotNull.toString());
assertEquals("user IS NOT NULL", conditionNotNull.toString());
Condition conditionEquals = new Condition("user", "= zhangsan");
conditionEquals.setPlaceHolder(false);
Assert.assertEquals("user = zhangsan", conditionEquals.toString());
assertEquals("user = zhangsan", conditionEquals.toString());
Condition conditionLike = new Condition("user", "like %aaa");
conditionLike.setPlaceHolder(false);
Assert.assertEquals("user LIKE '%aaa'", conditionLike.toString());
assertEquals("user LIKE '%aaa'", conditionLike.toString());
Condition conditionIn = new Condition("user", "in 1,2,3");
conditionIn.setPlaceHolder(false);
Assert.assertEquals("user IN (1,2,3)", conditionIn.toString());
assertEquals("user IN (1,2,3)", conditionIn.toString());
Condition conditionBetween = new Condition("user", "between 12 and 13");
conditionBetween.setPlaceHolder(false);
Assert.assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
assertEquals("user BETWEEN 12 AND 13", conditionBetween.toString());
}
@Test
public void parseTest(){
final Condition age = Condition.parse("age", "< 10");
Assert.assertEquals("age < ?", age.toString());
assertEquals("age < ?", age.toString());
// issue I38LTM
Assert.assertSame(BigDecimal.class, age.getValue().getClass());
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());
assertEquals("age IN (?,?,?)", age.toString());
}
}

View File

@@ -1,23 +1,23 @@
package cn.hutool.db.sql;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class SqlBuilderTest {
@Test
public void queryNullTest() {
SqlBuilder builder = SqlBuilder.create().select().from("user").where(new Condition("name", "= null"));
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build());
assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build());
SqlBuilder builder2 = SqlBuilder.create().select().from("user").where(new Condition("name", "is null"));
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
SqlBuilder builder3 = SqlBuilder.create().select().from("user").where(new Condition("name", "!= null"));
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
SqlBuilder builder4 = SqlBuilder.create().select().from("user").where(new Condition("name", "is not null"));
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
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());
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);
String s1 = sqlBuilder.build();
Assert.assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1);
assertEquals("SELECT id FROM user WHERE user LIKE '%123%'", s1);
}
}

View File

@@ -1,7 +1,7 @@
package cn.hutool.db.sql;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class SqlFormatterTest {
@@ -14,7 +14,7 @@ public class SqlFormatterTest {
}
@Test
@Ignore
@Disabled
public void testKeyword() {
final String sql = "select * from `order`";
final String format = SqlFormatter.format(sql);
@@ -22,7 +22,7 @@ public class SqlFormatterTest {
}
@Test
@Ignore
@Disabled
public void testSqlBuilderFormat() {
final String sql = "SELECT `link_table_a`.`value_a` AS `link_table_a.value_a`,`link_table_a`.`id` AS `link_table_a.id`,`link_table_b`.`value_b` AS `link_table_b.value_b`,`link_table_c`.`id` AS `link_table_c.id`,`link_table_b`.`id` AS `link_table_b.id`,`link_table_c`.`value_c` AS `link_table_c.value_c` FROM `link_table_a` INNER JOIN `link_table_b` ON `link_table_a`.`table_b_id` = `link_table_b`.`id` INNER JOIN `link_table_c` ON `link_table_b`.`table_c_id` = `link_table_c`.`id`";
final String format = SqlBuilder.of(sql).format().build();