完善 AdminUserServiceImpl 的单元测试
This commit is contained in:
parent
6c9ef97122
commit
be465d758b
|
@ -23,6 +23,7 @@ import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||||
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
||||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
@ -75,6 +76,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||||
private FileApi fileApi;
|
private FileApi fileApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@DSTransactional // 多租户多 DB 场景:使用 @DSTransactional 实现事务,避免 @Transactional 无法切换数据源
|
||||||
public Long createUser(UserCreateReqVO reqVO) {
|
public Long createUser(UserCreateReqVO reqVO) {
|
||||||
// 校验账户配合
|
// 校验账户配合
|
||||||
tenantService.handleTenantInfo(tenant -> {
|
tenantService.handleTenantInfo(tenant -> {
|
||||||
|
|
|
@ -345,7 +345,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||||
reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门
|
reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门
|
||||||
// mock 方法
|
// mock 方法
|
||||||
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
|
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
|
||||||
when(deptService.getChildDeptIdListFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList);
|
when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO);
|
PageResult<AdminUserDO> pageResult = userService.getUserPage(reqVO);
|
||||||
|
@ -368,7 +368,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||||
reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门
|
reqVO.setDeptId(1L); // 其中,1L 是 2L 的父部门
|
||||||
// mock 方法
|
// mock 方法
|
||||||
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
|
List<DeptDO> deptList = newArrayList(randomPojo(DeptDO.class, o -> o.setId(2L)));
|
||||||
when(deptService.getChildDeptIdListFromCache(eq(reqVO.getDeptId()), eq(true))).thenReturn(deptList);
|
when(deptService.getChildDeptList(eq(reqVO.getDeptId()))).thenReturn(deptList);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
List<AdminUserDO> list = userService.getUserList(reqVO);
|
List<AdminUserDO> list = userService.getUserList(reqVO);
|
||||||
|
|
Loading…
Reference in New Issue