test: 优化一些测试。

This commit is contained in:
Suomm 2024-04-14 11:00:04 +08:00
parent 3e23a68b6c
commit d3135c2d6b
7 changed files with 34 additions and 7 deletions

View File

@ -79,6 +79,15 @@ public class UpdateChainTest implements WithAssertions {
DataSourceKey.clear(); DataSourceKey.clear();
} }
@Test
public void testUpdateAll() {
assertThatThrownBy(() -> {
UpdateChain.of(accountMapper)
.set(Account::getAge, 11)
.update();
});
}
@Test @Test
@SneakyThrows @SneakyThrows
public void testUpdateChain() { public void testUpdateChain() {

View File

@ -16,6 +16,8 @@
package com.mybatisflex.test.alisa; package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
/** /**
@ -27,6 +29,7 @@ import com.mybatisflex.annotation.Table;
@Table("sys_dept") @Table("sys_dept")
public class SysDept extends BaseEntity { public class SysDept extends BaseEntity {
@Id(keyType = KeyType.Auto)
private Integer id; private Integer id;
private String deptName; private String deptName;

View File

@ -16,6 +16,8 @@
package com.mybatisflex.test.alisa; package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
/** /**
@ -27,6 +29,7 @@ import com.mybatisflex.annotation.Table;
@Table("sys_role") @Table("sys_role")
public class SysRole extends BaseEntity { public class SysRole extends BaseEntity {
@Id(keyType = KeyType.Auto)
private Integer id; private Integer id;
private String roleKey; private String roleKey;
private String roleName; private String roleName;

View File

@ -17,6 +17,8 @@
package com.mybatisflex.test.alisa; package com.mybatisflex.test.alisa;
import com.mybatisflex.annotation.ColumnAlias; import com.mybatisflex.annotation.ColumnAlias;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import java.util.Date; import java.util.Date;
@ -31,6 +33,7 @@ import java.util.List;
@Table("sys_user") @Table("sys_user")
public class SysUser extends BaseEntity { public class SysUser extends BaseEntity {
@Id(keyType = KeyType.Auto)
private Integer id; private Integer id;
private String userName; private String userName;
@ColumnAlias("user_age") @ColumnAlias("user_age")

View File

@ -18,6 +18,8 @@ package com.mybatisflex.test.model;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import java.util.List;
/** /**
* @author 王帅 * @author 王帅
* @since 2023-06-07 * @since 2023-06-07
@ -28,7 +30,7 @@ public class UserVO3 {
@Id @Id
private String userId; private String userId;
private String userName; private String userName;
private RoleVO3 roleVO3; private List<RoleVO3> roleVO3;
public String getUserId() { public String getUserId() {
return userId; return userId;
@ -46,11 +48,11 @@ public class UserVO3 {
this.userName = userName; this.userName = userName;
} }
public RoleVO3 getRoleVO3() { public List<RoleVO3> getRoleVO3() {
return roleVO3; return roleVO3;
} }
public void setRoleVO3(RoleVO3 roleVO3) { public void setRoleVO3(List<RoleVO3> roleVO3) {
this.roleVO3 = roleVO3; this.roleVO3 = roleVO3;
} }

View File

@ -166,4 +166,11 @@ class AlisaTest {
Assertions.assertEquals(userList1, userList2); Assertions.assertEquals(userList1, userList2);
} }
@Test
void test08() throws JsonProcessingException {
SysUser user = userMapper.selectOneById(1);
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
System.out.println(objectWriter.writeValueAsString(user));
}
} }

View File

@ -60,11 +60,11 @@ class UserMapperTest {
.from(USER.as("u")) .from(USER.as("u"))
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID))
.leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
.where(USER.USER_ID.eq(1)); .where(USER.USER_ID.eq(3));
System.out.println(queryWrapper.toSQL()); System.out.println(queryWrapper.toSQL());
// UserVO userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO.class); // UserVO userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO.class);
// UserVO1 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO1.class); // UserVO1 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO1.class);
// UserVO2 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO2.class); // UserVO2 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO2.class);
UserVO3 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO3.class); UserVO3 userVO = userMapper.selectOneByQueryAs(queryWrapper, UserVO3.class);
System.err.println(userVO); System.err.println(userVO);
} }