chore: 更新单元测试以适配新的 Feature

This commit is contained in:
Michael Yang 2024-10-05 12:57:34 +08:00
parent fd81f4aeb8
commit cc5306e06a
3 changed files with 9 additions and 7 deletions

View File

@ -17,11 +17,11 @@
package com.mybatisflex.coretest; package com.mybatisflex.coretest;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.coretest.table.ArticleTableDef;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT;
import static com.mybatisflex.coretest.table.ArticleTableDef.ARTICLE;
/** /**
* @author 王帅 * @author 王帅
@ -31,10 +31,11 @@ public class DynamicOrderByTest {
@Test @Test
public void test01() { public void test01() {
ArticleTableDef ARTICLE = ArticleTableDef.ARTICLE.as("ar");
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.select(ACCOUNT.ID, ACCOUNT.USER_NAME.as("name"), ACCOUNT.AGE) .select(ACCOUNT.ID, ACCOUNT.USER_NAME.as("name"), ACCOUNT.AGE)
.from(ACCOUNT.as("ac")) .from(ACCOUNT.as("ac"))
.leftJoin(ARTICLE).as("ar").on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) .leftJoin(ARTICLE).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID))
.orderBy(ACCOUNT.USER_NAME, true) .orderBy(ACCOUNT.USER_NAME, true)
.orderBy(Account::getAge, false) .orderBy(Account::getAge, false)
.orderBy("name", true) .orderBy("name", true)

View File

@ -43,9 +43,9 @@ public class PlusCompatibleTest {
}); });
Assert.assertEquals("SELECT * FROM `user` " + Assert.assertEquals("SELECT * FROM `user` " +
"WHERE `tb_account`.`age` >= 18 " + "WHERE `age` >= 18 " +
"OR (column2 LIKE 'value2%') " + "OR (column2 LIKE 'value2%') " +
"OR (column3 = 'value3' AND `tb_account`.`sex` >= 0)" "OR (column3 = 'value3' AND `sex` >= 0)"
, queryWrapper.toSQL()); , queryWrapper.toSQL());
System.out.println(queryWrapper.toSQL()); System.out.println(queryWrapper.toSQL());

View File

@ -22,6 +22,7 @@ import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.query.QueryChain; import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.test.table.ArticleTableDef;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.apache.ibatis.logging.stdout.StdOutImpl; import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.assertj.core.api.WithAssertions; import org.assertj.core.api.WithAssertions;
@ -38,7 +39,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT;
import static com.mybatisflex.test.table.ArticleTableDef.ARTICLE;
public class UpdateChainTest implements WithAssertions { public class UpdateChainTest implements WithAssertions {
@ -129,15 +129,16 @@ public class UpdateChainTest implements WithAssertions {
@Test @Test
public void testUpdateChainToSql() { public void testUpdateChainToSql() {
ArticleTableDef ARTICLE1 = ArticleTableDef.ARTICLE.as("ar");
String sql = UpdateChain.of(Account.class) String sql = UpdateChain.of(Account.class)
.set(ACCOUNT.AGE, 18) .set(ACCOUNT.AGE, 18)
.set(Article::getAccountId, 4) .set(Article::getAccountId, 4)
.leftJoin(ARTICLE).as("ar").on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)) .leftJoin(ARTICLE1).on(ACCOUNT.ID.eq(ARTICLE1.ACCOUNT_ID))
.where(ACCOUNT.ID.eq(4)) .where(ACCOUNT.ID.eq(4))
.toSQL(); .toSQL();
String expectSQL = "UPDATE `tb_account` " + String expectSQL = "UPDATE `tb_account` " +
"LEFT JOIN `tb_article` AS `ar` ON `tb_account`.`id` = `ar`.`account_id` " + "LEFT JOIN `tb_article` AS `ar` ON `id` = `ar`.`account_id` " +
"SET `age` = 18 , `accountId` = 4 WHERE `id` = 4"; "SET `age` = 18 , `accountId` = 4 WHERE `id` = 4";
assertThat(sql).isEqualTo(expectSQL); assertThat(sql).isEqualTo(expectSQL);