test: modify failed unit test

This commit is contained in:
mofan 2023-12-05 23:21:08 +08:00
parent adb9f6f27c
commit b429ea6475
22 changed files with 931 additions and 94 deletions

View File

@ -17,7 +17,6 @@
package com.mybatisflex.test.relation.onetoone; package com.mybatisflex.test.relation.onetoone;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.RelationManyToMany; import com.mybatisflex.annotation.RelationManyToMany;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
@ -28,7 +27,7 @@ import java.util.Map;
@Table(value = "tb_account") @Table(value = "tb_account")
public class Account implements Serializable { public class Account implements Serializable {
@Id(keyType = KeyType.Auto) @Id
private Long id; private Long id;
private String userName; private String userName;

View File

@ -45,7 +45,8 @@ public class AccountDTO implements Serializable {
@RelationManyToMany( @RelationManyToMany(
joinTable = "tb_role_mapping", joinTable = "tb_role_mapping",
joinSelfColumn = "account_id", joinSelfColumn = "account_id",
joinTargetColumn = "role_id" joinTargetColumn = "role_id",
selfField = "id"
) )
private List<Role> roles; private List<Role> roles;

View File

@ -16,6 +16,7 @@
package com.mybatisflex.test.relation.onetoone; package com.mybatisflex.test.relation.onetoone;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.RelationManyToMany; import com.mybatisflex.annotation.RelationManyToMany;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
@ -25,6 +26,7 @@ import java.util.List;
@Table(value = "tb_role") @Table(value = "tb_role")
public class Role implements Serializable { public class Role implements Serializable {
@Id
private Long id; private Long id;
private String name; private String name;

View File

@ -3,6 +3,7 @@ package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.mapper.Account6Mapper; import com.mybatisflex.mapper.Account6Mapper;
import org.apache.ibatis.logging.stdout.StdOutImpl; import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.api.InstanceOfAssertFactories;
@ -28,6 +29,8 @@ public class Account6Test implements WithAssertions {
private EmbeddedDatabase dataSource; private EmbeddedDatabase dataSource;
private Account6Mapper mapper; private Account6Mapper mapper;
private static final String DATA_SOURCE_KEY = "none_key";
@BeforeClass @BeforeClass
public static void enableAudit() { public static void enableAudit() {
AuditManager.setAuditEnable(true); AuditManager.setAuditEnable(true);
@ -43,17 +46,20 @@ public class Account6Test implements WithAssertions {
.build(); .build();
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setDataSource(this.dataSource) .setDataSource(DATA_SOURCE_KEY, this.dataSource)
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.addMapper(Account6Mapper.class) .addMapper(Account6Mapper.class)
.start(); .start();
DataSourceKey.use(DATA_SOURCE_KEY);
mapper = bootstrap.getMapper(Account6Mapper.class); mapper = bootstrap.getMapper(Account6Mapper.class);
} }
@After @After
public void destroy() { public void destroy() {
this.dataSource.shutdown(); this.dataSource.shutdown();
DataSourceKey.clear();
} }
/** /**

View File

@ -3,6 +3,7 @@ package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.keygen.KeyGeneratorFactory; import com.mybatisflex.core.keygen.KeyGeneratorFactory;
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;
@ -28,6 +29,8 @@ public class Account7Test implements WithAssertions {
private EmbeddedDatabase dataSource; private EmbeddedDatabase dataSource;
private Account7Mapper mapper; private Account7Mapper mapper;
private static final String DATA_SOURCE_KEY = "generate_key";
@BeforeClass @BeforeClass
public static void enableAudit() { public static void enableAudit() {
AuditManager.setAuditEnable(true); AuditManager.setAuditEnable(true);
@ -45,17 +48,20 @@ public class Account7Test implements WithAssertions {
.build(); .build();
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setDataSource(this.dataSource) .setDataSource(DATA_SOURCE_KEY, this.dataSource)
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.addMapper(Account7Mapper.class) .addMapper(Account7Mapper.class)
.start(); .start();
DataSourceKey.use(DATA_SOURCE_KEY);
mapper = bootstrap.getMapper(Account7Mapper.class); mapper = bootstrap.getMapper(Account7Mapper.class);
} }
@After @After
public void destroy() { public void destroy() {
this.dataSource.shutdown(); this.dataSource.shutdown();
DataSourceKey.clear();
} }
/** /**

View File

@ -18,6 +18,7 @@ package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.mapper.Account5Mapper; import com.mybatisflex.mapper.Account5Mapper;
import org.assertj.core.api.WithAssertions; import org.assertj.core.api.WithAssertions;
import org.junit.After; import org.junit.After;
@ -34,6 +35,8 @@ public class AccountInsertWithArrayAttrTest implements WithAssertions {
private Account5Mapper accountMapper; private Account5Mapper accountMapper;
private EmbeddedDatabase dataSource; private EmbeddedDatabase dataSource;
private static final String DATA_SOURCE_KEY = "data05";
@BeforeClass @BeforeClass
public static void enableAudit() { public static void enableAudit() {
AuditManager.setAuditEnable(true); AuditManager.setAuditEnable(true);
@ -49,16 +52,19 @@ public class AccountInsertWithArrayAttrTest implements WithAssertions {
.build(); .build();
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setDataSource(dataSource) .setDataSource(DATA_SOURCE_KEY, dataSource)
.addMapper(Account5Mapper.class) .addMapper(Account5Mapper.class)
.start(); .start();
DataSourceKey.use(DATA_SOURCE_KEY);
accountMapper = bootstrap.getMapper(Account5Mapper.class); accountMapper = bootstrap.getMapper(Account5Mapper.class);
} }
@After @After
public void destroy() { public void destroy() {
this.dataSource.shutdown(); this.dataSource.shutdown();
DataSourceKey.clear();
} }
@Test @Test
@ -70,7 +76,7 @@ public class AccountInsertWithArrayAttrTest implements WithAssertions {
account.setDataScope(new Long[]{1L, 2L}); account.setDataScope(new Long[]{1L, 2L});
accountMapper.insertWithPk(account, false); accountMapper.insertWithPk(account, false);
// todo 查询有问题会抛出 argument type mismatch // todo argument type mismatch
Account5 result = accountMapper.selectOneById(3L); Account5 result = accountMapper.selectOneById(3L);
assertThat(result).isNotNull() assertThat(result).isNotNull()
.extracting(Account5::getUserName, Account5::getDataScope) .extracting(Account5::getUserName, Account5::getDataScope)

View File

@ -19,6 +19,7 @@ import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.mybatis.Mappers; import com.mybatisflex.core.mybatis.Mappers;
import com.mybatisflex.core.query.If; import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
@ -52,6 +53,8 @@ public class AccountNativeTest implements WithAssertions {
private AccountMapper accountMapper; private AccountMapper accountMapper;
private ArticleMapper articleMapper; private ArticleMapper articleMapper;
private static final String DATA_SOURCE_KEY = "auto_increment";
@BeforeClass @BeforeClass
public static void enableAudit() { public static void enableAudit() {
AuditManager.setAuditEnable(true); AuditManager.setAuditEnable(true);
@ -68,12 +71,14 @@ public class AccountNativeTest implements WithAssertions {
.build(); .build();
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setDataSource(this.dataSource) .setDataSource(DATA_SOURCE_KEY, this.dataSource)
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.addMapper(AccountMapper.class) .addMapper(AccountMapper.class)
.addMapper(ArticleMapper.class) .addMapper(ArticleMapper.class)
.start(); .start();
DataSourceKey.use(DATA_SOURCE_KEY);
accountMapper = bootstrap.getMapper(AccountMapper.class); accountMapper = bootstrap.getMapper(AccountMapper.class);
articleMapper = bootstrap.getMapper(ArticleMapper.class); articleMapper = bootstrap.getMapper(ArticleMapper.class);
} }
@ -81,6 +86,7 @@ public class AccountNativeTest implements WithAssertions {
@After @After
public void destroy() { public void destroy() {
this.dataSource.shutdown(); this.dataSource.shutdown();
DataSourceKey.clear();
} }
@Test @Test
@ -154,19 +160,21 @@ public class AccountNativeTest implements WithAssertions {
* issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7QD29 * issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7QD29
*/ */
@Test @Test
@Ignore
public void testGiteeIssue_I7QD29() { public void testGiteeIssue_I7QD29() {
QueryWrapper queryWrapper = QueryWrapper.create(); QueryWrapper queryWrapper = QueryWrapper.create();
queryWrapper.from(ACCOUNT) queryWrapper.from(ACCOUNT)
.leftJoin(ACCOUNT).as("a1").on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)) .leftJoin(ARTICLE).as("a1").on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID))
.leftJoin(ACCOUNT).as("a2").on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID)) .leftJoin(ARTICLE).as("a2").on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID))
.where(ACCOUNT.ID.ge(1)); .where(ACCOUNT.ID.ge(1));
// todo Column "TB_ARTICLE.ACCOUNT_ID" not found
List<Article> accounts = articleMapper.selectListByQuery(queryWrapper); List<Article> accounts = articleMapper.selectListByQuery(queryWrapper);
System.out.println(accounts); String expectSql = "SELECT * FROM `tb_account` " +
"LEFT JOIN `tb_article` AS `a1` ON `tb_account`.`id` = `a1`.`account_id` AND `a1`.`is_delete` = 0 " +
"LEFT JOIN `tb_article` AS `a2` ON `tb_account`.`id` = `a1`.`account_id` AND `a2`.`is_delete` = 0 " +
"WHERE `tb_account`.`id` >= 1";
assertThat(queryWrapper.toSQL()).isEqualTo(expectSql);
assertThat(accounts).hasSize(9);
} }
/** /**
* issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7VAG8 * issues https://gitee.com/mybatis-flex/mybatis-flex/issues/I7VAG8
*/ */
@ -205,7 +213,7 @@ public class AccountNativeTest implements WithAssertions {
// 设置 Ignore 字段会被自动忽略 // 设置 Ignore 字段会被自动忽略
.setRaw(Account::getTitle, "xxxx") .setRaw(Account::getTitle, "xxxx")
.toEntity(); .toEntity();
// todo Column "TITLE" not found // todo title not found
accountMapper.update(account); accountMapper.update(account);
} }

View File

@ -16,13 +16,11 @@
package com.mybatisflex.test; package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.row.DbChain;
import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.Row;
import com.mybatisflex.core.row.RowKey; import com.mybatisflex.core.row.RowKey;
import com.mybatisflex.core.row.RowUtil;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.assertj.core.api.WithAssertions; import org.assertj.core.api.WithAssertions;
import org.junit.After; import org.junit.After;
@ -46,6 +44,7 @@ public class DbChainTest implements WithAssertions {
private static final String[] PROPERTIES = new String[]{"ID", "USER_NAME", "AGE", "BIRTHDAY"}; private static final String[] PROPERTIES = new String[]{"ID", "USER_NAME", "AGE", "BIRTHDAY"};
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private static final String ENVIRONMENT_ID = "db_chain";
private EmbeddedDatabase database; private EmbeddedDatabase database;
@ -63,9 +62,13 @@ public class DbChainTest implements WithAssertions {
.addScript("auto_increment_key_data.sql") .addScript("auto_increment_key_data.sql")
.build(); .build();
new MybatisFlexBootstrap() // Environment environment = new Environment(ENVIRONMENT_ID, new JdbcTransactionFactory(), this.database);
.setDataSource(this.database) // FlexConfiguration configuration = new FlexConfiguration(environment);
.start(); // configuration.addMapper(RowMapper.class);
// FlexGlobalConfig flexGlobalConfig = new FlexGlobalConfig();
// flexGlobalConfig.setConfiguration(configuration);
// flexGlobalConfig.setSqlSessionFactory(new DefaultSqlSessionFactory(configuration));
// FlexGlobalConfig.setConfig(environment.getId(), flexGlobalConfig, false);
} }
@After @After
@ -122,7 +125,6 @@ public class DbChainTest implements WithAssertions {
assertThat(count).isEqualTo(1L); assertThat(count).isEqualTo(1L);
List<Row> tb_account = DbChain.table("tb_account").list(); List<Row> tb_account = DbChain.table("tb_account").list();
RowUtil.printPretty(tb_account);
assertThat(tb_account).hasSize(1) assertThat(tb_account).hasSize(1)
.extracting(PROPERTIES) .extracting(PROPERTIES)

View File

@ -18,13 +18,16 @@ package com.mybatisflex.test;
import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.datasource.DataSourceKey;
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;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
import java.util.Date; import java.util.Date;
/** /**
@ -35,9 +38,14 @@ import java.util.Date;
*/ */
public class ListenerTest implements WithAssertions { public class ListenerTest implements WithAssertions {
@Test private static final String DATA_SOURCE_KEY = "listener";
public void onInsertInterface() {
DataSource dataSource = new EmbeddedDatabaseBuilder() private AccountMapper accountMapper;
private EmbeddedDatabase dataSource;
@Before
public void init() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2) .setType(EmbeddedDatabaseType.H2)
.addScript("auto_increment_key_schema.sql") .addScript("auto_increment_key_schema.sql")
.build(); .build();
@ -48,11 +56,22 @@ public class ListenerTest implements WithAssertions {
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.setDataSource(dataSource) .setDataSource(DATA_SOURCE_KEY, dataSource)
.addMapper(AccountMapper.class) .addMapper(AccountMapper.class)
.start(); .start();
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class); DataSourceKey.use(DATA_SOURCE_KEY);
accountMapper = bootstrap.getMapper(AccountMapper.class);
}
@After
public void destroy() {
this.dataSource.shutdown();
DataSourceKey.clear();
}
@Test
public void onInsertInterface() {
Account account = new Account(); Account account = new Account();
account.setAge(-2); account.setAge(-2);
account.setUserName("on insert"); account.setUserName("on insert");

View File

@ -15,11 +15,11 @@
*/ */
package com.mybatisflex.test; package com.mybatisflex.test;
import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.json.JsonMapper;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.audit.MessageCollector; import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.relation.RelationManager; import com.mybatisflex.core.relation.RelationManager;
@ -30,78 +30,103 @@ import com.mybatisflex.test.relation.onetoone.Account;
import com.mybatisflex.test.relation.onetoone.AccountDTO; import com.mybatisflex.test.relation.onetoone.AccountDTO;
import com.mybatisflex.test.relation.onetoone.Book; import com.mybatisflex.test.relation.onetoone.Book;
import com.mybatisflex.test.relation.onetoone.Menu; import com.mybatisflex.test.relation.onetoone.Menu;
import lombok.SneakyThrows;
import net.javacrumbs.jsonunit.assertj.JsonAssertions;
import org.apache.commons.io.FileUtils;
import org.assertj.core.api.WithAssertions;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import static com.mybatisflex.test.relation.onetoone.table.MenuTableDef.MENU; import static com.mybatisflex.test.relation.onetoone.table.MenuTableDef.MENU;
public class RelationsTester { public class RelationsTest implements WithAssertions {
static AccountMapper accountMapper; private AccountMapper accountMapper;
static BookMapper bookMapper; private BookMapper bookMapper;
static MenuMapper menuMapper; private MenuMapper menuMapper;
private EmbeddedDatabase dataSource;
private static final String DATA_SOURCE_KEY = "relation-onetoone";
private static final JsonMapper JSON_MAPPER = JsonMapper.builder().build();
@BeforeClass @BeforeClass
public static void init() { public static void enableAudit() {
DataSource dataSource = new EmbeddedDatabaseBuilder() AuditManager.setAuditEnable(true);
AuditManager.setMessageCollector(new ConsoleMessageCollector());
}
@Before
public void init() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2) .setType(EmbeddedDatabaseType.H2)
.addScript("relation/onetoone/schema.sql") .addScript("relation/onetoone/schema.sql")
.addScript("relation/onetoone/data.sql") .addScript("relation/onetoone/data.sql")
.build(); .build();
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
.setDataSource(dataSource) .setDataSource(DATA_SOURCE_KEY, dataSource)
.addMapper(AccountMapper.class) .addMapper(AccountMapper.class)
.addMapper(BookMapper.class) .addMapper(BookMapper.class)
.addMapper(MenuMapper.class) .addMapper(MenuMapper.class)
.start(); .start();
//开启审计功能 DataSourceKey.use(DATA_SOURCE_KEY);
AuditManager.setAuditEnable(true);
//设置 SQL 审计收集器
MessageCollector collector = new ConsoleMessageCollector();
AuditManager.setMessageCollector(collector);
accountMapper = bootstrap.getMapper(AccountMapper.class); accountMapper = bootstrap.getMapper(AccountMapper.class);
bookMapper = bootstrap.getMapper(BookMapper.class); bookMapper = bootstrap.getMapper(BookMapper.class);
menuMapper = bootstrap.getMapper(MenuMapper.class); menuMapper = bootstrap.getMapper(MenuMapper.class);
} }
@After
@Test public void destroy() {
public void testOneToOne() { this.dataSource.shutdown();
List<com.mybatisflex.test.relation.onetoone.Account> accounts = accountMapper.selectAllWithRelations(); DataSourceKey.clear();
System.out.println(JSON.toJSONString(accounts));
} }
@Test
@SneakyThrows
public void testOneToOne() {
List<com.mybatisflex.test.relation.onetoone.Account> accounts = accountMapper.selectAllWithRelations();
assertThat(accounts).hasSize(5);
assertRelationResult(accounts, "relation/result/account-relation-result.json");
}
@Test @Test
public void testManyToOne() { public void testManyToOne() {
List<Book> books = bookMapper.selectAll(); List<Book> books = bookMapper.selectAll();
System.out.println(">>>>>>1: " + books); assertThat(books).hasSize(6)
.extracting(Book::getId)
.containsExactly(1L, 2L, 3L, 4L, 5L, 6L);
RelationManager.queryRelations(bookMapper, books); RelationManager.queryRelations(bookMapper, books);
System.out.println(">>>>>>2: " + books); assertRelationResult(books, "relation/result/book-relation-result.json");
} }
@Test @Test
public void testManyToMany1() { public void testManyToMany1() {
List<com.mybatisflex.test.relation.onetoone.Account> accounts = accountMapper.selectAll(); List<com.mybatisflex.test.relation.onetoone.Account> accounts = accountMapper.selectAll();
System.out.println(">>>>>>1: " + accounts); assertThat(accounts).hasSize(5)
.extracting(Account::getId)
.containsExactly(1L, 2L, 3L, 4L, 5L);
RelationManager.queryRelations(accountMapper, accounts); RelationManager.queryRelations(accountMapper, accounts);
System.out.println(">>>>>>2: " + accounts); assertRelationResult(accounts, "relation/result/account-relation-result.json");
} }
@Test @Test
public void testAsDto() { public void testAsDto() {
List<com.mybatisflex.test.relation.onetoone.AccountDTO> accounts = accountMapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), AccountDTO.class); List<com.mybatisflex.test.relation.onetoone.AccountDTO> accounts = accountMapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), AccountDTO.class);
System.out.println(">>>>>>1: " + accounts); assertRelationResult(accounts, "relation/result/accountDto-relation-result.json");
} }
@Test @Test
@ -110,7 +135,7 @@ public class RelationsTester {
qw.where(MENU.PARENT_ID.eq(0)); qw.where(MENU.PARENT_ID.eq(0));
List<Menu> menus = menuMapper.selectListWithRelationsByQuery(qw); List<Menu> menus = menuMapper.selectListWithRelationsByQuery(qw);
System.out.println(JSON.toJSONString(menus)); assertRelationResult(menus, "relation/result/menu-relation-result.json");
} }
@Test @Test
@ -120,14 +145,29 @@ public class RelationsTester {
RelationManager.addIgnoreRelations("parent"); RelationManager.addIgnoreRelations("parent");
List<Menu> menus = menuMapper.selectListWithRelationsByQuery(qw); List<Menu> menus = menuMapper.selectListWithRelationsByQuery(qw);
System.out.println(JSON.toJSONString(menus)); assertRelationResult(menus, "relation/result/menu-relation-ignore-parent-result.json");
} }
@Test @Test
public void testPaginate() { public void testPaginate() {
Page<Account> accountPage = accountMapper.paginateWithRelations(1, 2, QueryWrapper.create()); Page<Account> accountPage = accountMapper.paginateWithRelations(1, 2, QueryWrapper.create());
System.out.println(accountPage); assertRelationResult(accountPage.getRecords(), "relation/result/account-page-relation-result.json");
} }
private void assertRelationResult(Object object, String classPath) {
String resultJson = writeObject2String(object);
String expectJson = getFileAsString(classPath);
JsonAssertions.assertThatJson(resultJson).isEqualTo(expectJson);
}
@SneakyThrows
private String writeObject2String(Object object) {
return JSON_MAPPER.writeValueAsString(object);
}
@SneakyThrows
private String getFileAsString(String classPath) {
ClassPathResource resource = new ClassPathResource(classPath);
return FileUtils.readFileToString(resource.getFile(), StandardCharsets.UTF_8);
}
} }

View File

@ -19,76 +19,104 @@ import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.keygen.KeyGenerators; import com.mybatisflex.core.keygen.KeyGenerators;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.Row;
import com.mybatisflex.core.row.RowKey; import com.mybatisflex.core.row.RowKey;
import com.mybatisflex.core.row.RowUtil;
import org.apache.ibatis.logging.stdout.StdOutImpl; import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.assertj.core.api.WithAssertions;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
import java.util.List; import java.util.List;
import static com.mybatisflex.test.relation.onetoone.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.test.relation.onetoone.table.AccountTableDef.ACCOUNT;
public class RowTestStarter { public class RowTest implements WithAssertions {
private static final String DATA_SOURCE_KEY = "row";
private EmbeddedDatabase dataSource;
@BeforeClass @BeforeClass
public static void init() { public static void enableAudit() {
DataSource dataSource = new EmbeddedDatabaseBuilder() AuditManager.setAuditEnable(true);
AuditManager.setMessageCollector(new ConsoleMessageCollector());
}
@Before
public void init() {
dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2) .setType(EmbeddedDatabaseType.H2)
.addScript("schema_row.sql") .addScript("schema_row.sql")
.addScript("data_row.sql") .addScript("data_row.sql")
.build(); .build();
MybatisFlexBootstrap.getInstance() new MybatisFlexBootstrap().setDataSource(DATA_SOURCE_KEY, dataSource)
.setDataSource(dataSource)
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.start(); .start();
AuditManager.setAuditEnable(true); DataSourceKey.use(DATA_SOURCE_KEY);
AuditManager.setMessageCollector(new ConsoleMessageCollector());
} }
@After
public void destroy() {
this.dataSource.shutdown();
DataSourceKey.clear();
}
@Test @Test
public void testSetRaw(){ public void testSetRaw() {
Row row = new Row(); Row row = new Row();
row.set("user_name","michael"); row.set("user_name", "michael");
row.setRaw("birthday","now()"); row.setRaw("birthday", "now()");
Db.insert("tb_account",row); Db.insert("tb_account", row);
List<Row> rowList = Db.selectAll("tb_account"); List<Row> rowList = Db.selectAll("tb_account");
RowUtil.printPretty(rowList); assertThat(rowList).hasSize(3)
.extracting("USER_NAME")
.containsOnly("张三", "王麻子叔叔", "michael");
// 插入的数据没有 id
assertThat(row).doesNotContainKey("id");
} }
@Test @Test
public void testCustomRowKey(){ public void testCustomRowKey() {
RowKey rowKey = RowKey.of("id", KeyType.Generator, KeyGenerators.flexId); RowKey rowKey = RowKey.of("id", KeyType.Generator, KeyGenerators.flexId);
Row row = Row.ofKey(rowKey); Row row = Row.ofKey(rowKey);
row.set("user_name","michael"); row.set("user_name", "michael");
row.setRaw("birthday","now()"); row.setRaw("birthday", "now()");
Db.insert("tb_account",row); Db.insert("tb_account", row);
List<Row> rowList = Db.selectAll("tb_account"); List<Row> rowList = Db.selectAll("tb_account");
RowUtil.printPretty(rowList); assertThat(rowList).hasSize(3)
.extracting("USER_NAME")
.containsOnly("张三", "王麻子叔叔", "michael");
// 指定了主键生成策略 ID
assertThat(row).containsKey("id")
.extracting("id")
.isInstanceOf(Long.class);
} }
//https://gitee.com/mybatis-flex/mybatis-flex/issues/I7W7HQ // https://gitee.com/mybatis-flex/mybatis-flex/issues/I7W7HQ
@Test @Test
public void testRow01(){ public void testGiteeIssue_I7W7HQ() {
QueryWrapper qw = QueryWrapper.create().select("id, MAX(`tb_account`.`age`)") QueryWrapper qw = QueryWrapper.create().select("id, MAX(`tb_account`.`age`)")
.groupBy("id") .groupBy("id")
.from(ACCOUNT); .from(ACCOUNT);
List<Row> rowList = Db.selectListByQuery(qw); List<Row> rowList = Db.selectListByQuery(qw);
RowUtil.printPretty(rowList); assertThat(rowList).hasSize(2)
.extracting("MAX(TB_ACCOUNT.AGE)")
.containsOnly(18, 19);
} }
} }

View File

@ -19,6 +19,7 @@ package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager; import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.ConsoleMessageCollector;
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 lombok.SneakyThrows; import lombok.SneakyThrows;
@ -44,6 +45,8 @@ public class UpdateChainTest implements WithAssertions {
private AccountMapper accountMapper; private AccountMapper accountMapper;
private EmbeddedDatabase dataSource; private EmbeddedDatabase dataSource;
private static final String DATA_SOURCE_KEY = "ds2";
@BeforeClass @BeforeClass
public static void enableAudit() { public static void enableAudit() {
AuditManager.setAuditEnable(true); AuditManager.setAuditEnable(true);
@ -59,16 +62,19 @@ public class UpdateChainTest implements WithAssertions {
.build(); .build();
MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap() MybatisFlexBootstrap bootstrap = new MybatisFlexBootstrap()
.setDataSource(this.dataSource) .setDataSource(DATA_SOURCE_KEY, this.dataSource)
.setLogImpl(StdOutImpl.class) .setLogImpl(StdOutImpl.class)
.addMapper(AccountMapper.class) .addMapper(AccountMapper.class)
.start(); .start();
DataSourceKey.use(DATA_SOURCE_KEY);
accountMapper = bootstrap.getMapper(AccountMapper.class); accountMapper = bootstrap.getMapper(AccountMapper.class);
} }
@After @After
public void destroy() { public void destroy() {
this.dataSource.shutdown(); this.dataSource.shutdown();
DataSourceKey.clear();
} }
@Test @Test

View File

@ -1,11 +1,11 @@
CREATE TABLE IF NOT EXISTS `tb_account` CREATE TABLE IF NOT EXISTS `tb_account`
( (
`id` INTEGER auto_increment, `id` INTEGER,
`user_name` VARCHAR(100), `user_name` VARCHAR(100),
`age` Integer `age` Integer,
PRIMARY KEY(id)
); );
CREATE TABLE IF NOT EXISTS `tb_idcard` CREATE TABLE IF NOT EXISTS `tb_idcard`
( (
`account_id` Integer, `account_id` Integer,
@ -13,39 +13,38 @@ CREATE TABLE IF NOT EXISTS `tb_idcard`
`content` text `content` text
); );
CREATE TABLE IF NOT EXISTS `tb_idcard_mapping` CREATE TABLE IF NOT EXISTS `tb_idcard_mapping`
( (
`account_id` Integer, `account_id` Integer,
`idcard_id` Integer `idcard_id` Integer
); );
CREATE TABLE IF NOT EXISTS `tb_book` CREATE TABLE IF NOT EXISTS `tb_book`
( (
`id` INTEGER auto_increment, `id` INTEGER,
`account_id` Integer, `account_id` Integer,
`title` VARCHAR(100), `title` VARCHAR(100),
`content` text `content` text,
PRIMARY KEY(id)
); );
CREATE TABLE IF NOT EXISTS `tb_role` CREATE TABLE IF NOT EXISTS `tb_role`
( (
`id` INTEGER auto_increment, `id` INTEGER,
`name` VARCHAR(100) `name` VARCHAR(100),
PRIMARY KEY(id)
); );
CREATE TABLE IF NOT EXISTS `tb_role_mapping` CREATE TABLE IF NOT EXISTS `tb_role_mapping`
( (
`account_id` INTEGER , `account_id` INTEGER ,
`role_id` INTEGER `role_id` INTEGER
); );
CREATE TABLE IF NOT EXISTS `tb_menu` CREATE TABLE IF NOT EXISTS `tb_menu`
( (
`id` INTEGER auto_increment, `id` INTEGER,
`parent_id` INTEGER, `parent_id` INTEGER,
`name` VARCHAR(100) `name` VARCHAR(100),
PRIMARY KEY(id)
); );

View File

@ -0,0 +1,85 @@
[
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
}
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"2": {
"id": 2,
"name": "角色2",
"accounts": [
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
},
"3": {
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
}
}
]

View File

@ -0,0 +1,112 @@
[
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
}
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"2": {
"id": 2,
"name": "角色2",
"accounts": [
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
},
"3": {
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
}
},
{
"id": 3,
"userName": "沙和尚",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 4,
"userName": "六耳猕猴",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 5,
"userName": "王麻子叔叔",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]

View File

@ -0,0 +1,155 @@
[
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [
{
"id": 1,
"name": "角色1",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
},
{
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
]
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [
{
"id": 1,
"name": "角色1",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
},
{
"id": 2,
"name": "角色2",
"accounts": [
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
},
{
"id": 3,
"name": "角色3",
"accounts": [
{
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
},
{
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": null
}
]
}
]
},
{
"id": 3,
"userName": "沙和尚",
"age": 19,
"idCard": null,
"books": [],
"roles": null
},
{
"id": 4,
"userName": "六耳猕猴",
"age": 19,
"idCard": null,
"books": [],
"roles": null
},
{
"id": 5,
"userName": "王麻子叔叔",
"age": 19,
"idCard": null,
"books": [],
"roles": null
}
]

View File

@ -0,0 +1,138 @@
[
{
"id": 1,
"accountId": 1,
"title": "图书1",
"content": "内容1",
"account": {
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
},
{
"id": 2,
"accountId": 2,
"title": "图书2",
"content": "内容2",
"account": {
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"2": {
"id": 2,
"name": "角色2",
"accounts": []
},
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
},
{
"id": 3,
"accountId": 1,
"title": "图书3",
"content": "内容2",
"account": {
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
},
{
"id": 4,
"accountId": 1,
"title": "图书4",
"content": "内容2",
"account": {
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
},
{
"id": 5,
"accountId": 1,
"title": "图书5",
"content": "内容2",
"account": {
"id": 1,
"userName": "孙悟空",
"age": 18,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
},
{
"id": 6,
"accountId": 2,
"title": "图书6",
"content": "内容2",
"account": {
"id": 2,
"userName": "猪八戒",
"age": 19,
"idCard": null,
"books": [],
"roles": [],
"rolesMap": {
"2": {
"id": 2,
"name": "角色2",
"accounts": []
},
"3": {
"id": 3,
"name": "角色3",
"accounts": []
}
}
}
}
]

View File

@ -0,0 +1,90 @@
[
{
"id": 1,
"parentId": 0,
"name": "顶级菜单1",
"parent": null,
"children": [
{
"id": 4,
"parentId": 1,
"name": "子菜单4",
"parent": null,
"children": [
{
"id": 9,
"parentId": 4,
"name": "子菜单9",
"parent": null,
"children": null
},
{
"id": 10,
"parentId": 4,
"name": "子菜单10",
"parent": null,
"children": null
}
]
},
{
"id": 5,
"parentId": 1,
"name": "子菜单5",
"parent": null,
"children": [
{
"id": 11,
"parentId": 5,
"name": "子菜单11",
"parent": null,
"children": null
},
{
"id": 12,
"parentId": 5,
"name": "子菜单12",
"parent": null,
"children": null
}
]
}
]
},
{
"id": 2,
"parentId": 0,
"name": "顶级菜单2",
"parent": null,
"children": []
},
{
"id": 3,
"parentId": 0,
"name": "顶级菜单3",
"parent": null,
"children": [
{
"id": 6,
"parentId": 3,
"name": "子菜单6",
"parent": null,
"children": []
},
{
"id": 7,
"parentId": 3,
"name": "子菜单7",
"parent": null,
"children": []
},
{
"id": 8,
"parentId": 3,
"name": "子菜单8",
"parent": null,
"children": []
}
]
}
]

View File

@ -0,0 +1,120 @@
[
{
"id": 1,
"parentId": 0,
"name": "顶级菜单1",
"parent": null,
"children": [
{
"id": 4,
"parentId": 1,
"name": "子菜单4",
"parent": {
"id": 1,
"parentId": 0,
"name": "顶级菜单1",
"parent": null,
"children": null
},
"children": [
{
"id": 9,
"parentId": 4,
"name": "子菜单9",
"parent": null,
"children": null
},
{
"id": 10,
"parentId": 4,
"name": "子菜单10",
"parent": null,
"children": null
}
]
},
{
"id": 5,
"parentId": 1,
"name": "子菜单5",
"parent": {
"id": 1,
"parentId": 0,
"name": "顶级菜单1",
"parent": null,
"children": null
},
"children": [
{
"id": 11,
"parentId": 5,
"name": "子菜单11",
"parent": null,
"children": null
},
{
"id": 12,
"parentId": 5,
"name": "子菜单12",
"parent": null,
"children": null
}
]
}
]
},
{
"id": 2,
"parentId": 0,
"name": "顶级菜单2",
"parent": null,
"children": []
},
{
"id": 3,
"parentId": 0,
"name": "顶级菜单3",
"parent": null,
"children": [
{
"id": 6,
"parentId": 3,
"name": "子菜单6",
"parent": {
"id": 3,
"parentId": 0,
"name": "顶级菜单3",
"parent": null,
"children": null
},
"children": []
},
{
"id": 7,
"parentId": 3,
"name": "子菜单7",
"parent": {
"id": 3,
"parentId": 0,
"name": "顶级菜单3",
"parent": null,
"children": null
},
"children": []
},
{
"id": 8,
"parentId": 3,
"name": "子菜单8",
"parent": {
"id": 3,
"parentId": 0,
"name": "顶级菜单3",
"parent": null,
"children": null
},
"children": []
}
]
}
]

View File

@ -24,15 +24,30 @@
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<commons-io.version>2.15.1</commons-io.version>
<org.projectlombok.version>1.18.30</org.projectlombok.version> <org.projectlombok.version>1.18.30</org.projectlombok.version>
<!-- 高版本基于 JDK17勿动 -->
<json-unit-assertj.version>2.38.0</json-unit-assertj.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version> <version>${org.projectlombok.version}</version>
</dependency> </dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-assertj</artifactId>
<version>${json-unit-assertj.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>