| | |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserImportRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO; |
| | |
| | | import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper; |
| | | import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; |
| | | import cn.iocoder.yudao.module.system.enums.common.SexEnum; |
| | | import cn.iocoder.yudao.module.system.mq.producer.user.AdminUserProducer; |
| | | 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.oauth2.OAuth2TokenService; |
| | |
| | | private ConfigApi configApi; |
| | | @MockitoBean |
| | | private OAuth2TokenService oauth2TokenService; |
| | | @MockitoBean |
| | | private AdminUserProducer adminUserProducer; |
| | | |
| | | @BeforeEach |
| | | public void before() { |
| | |
| | | */ |
| | | @Test |
| | | public void testImportUserList_01() { |
| | | // 准备参数 |
| | | // 准备参数:部门名称在系统中不存在 |
| | | UserImportExcelVO importUser = randomPojo(UserImportExcelVO.class, o -> { |
| | | o.setDeptName("不存在的部门-" + System.currentTimeMillis()); |
| | | o.setEmail(randomEmail()); |
| | | o.setMobile(randomMobile()); |
| | | }); |
| | | // mock 方法,模拟失败 |
| | | doThrow(new ServiceException(DEPT_NOT_FOUND)).when(deptService).validateDeptList(any()); |
| | | // mock:系统中没有匹配的部门 |
| | | when(deptService.getDeptList(any(DeptListReqVO.class))).thenReturn(newArrayList()); |
| | | |
| | | // 调用 |
| | | UserImportRespVO respVO = userService.importUserList(newArrayList(importUser), true); |
| | | // 断言 |
| | | // 断言:该行因部门不存在而失败 |
| | | assertEquals(0, respVO.getCreateUsernames().size()); |
| | | assertEquals(0, respVO.getUpdateUsernames().size()); |
| | | assertEquals(1, respVO.getFailureUsernames().size()); |
| | | assertEquals(DEPT_NOT_FOUND.getMsg(), respVO.getFailureUsernames().get(importUser.getUsername())); |
| | | assertTrue(respVO.getFailureUsernames().get(importUser.getUsername()).contains("不存在")); |
| | | } |
| | | |
| | | /** |
| | |
| | | o.setMobile(randomMobile()); |
| | | }); |
| | | // mock deptService 的方法 |
| | | // 部门已改为按名称导入:mock getDeptList 返回一个可匹配的部门 |
| | | DeptDO dept = randomPojo(DeptDO.class, o -> { |
| | | o.setId(importUser.getDeptId()); |
| | | o.setId(1L); |
| | | o.setName(importUser.getDeptName()); |
| | | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| | | }); |
| | | when(deptService.getDeptList(any(DeptListReqVO.class))).thenReturn(newArrayList(dept)); |
| | | when(deptService.getDept(eq(dept.getId()))).thenReturn(dept); |
| | | // mock passwordEncoder 的方法 |
| | | when(passwordEncoder.encode(eq("yudaoyuanma"))).thenReturn("java"); |
| | |
| | | o.setEmail(randomEmail()); |
| | | o.setMobile(randomMobile()); |
| | | }); |
| | | // mock deptService 的方法 |
| | | // 部门已改为按名称导入:mock getDeptList 返回一个可匹配的部门 |
| | | DeptDO dept = randomPojo(DeptDO.class, o -> { |
| | | o.setId(importUser.getDeptId()); |
| | | o.setId(1L); |
| | | o.setName(importUser.getDeptName()); |
| | | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| | | }); |
| | | when(deptService.getDeptList(any(DeptListReqVO.class))).thenReturn(newArrayList(dept)); |
| | | when(deptService.getDept(eq(dept.getId()))).thenReturn(dept); |
| | | |
| | | // 调用 |
| | |
| | | o.setEmail(randomEmail()); |
| | | o.setMobile(randomMobile()); |
| | | }); |
| | | // mock deptService 的方法 |
| | | // 部门已改为按名称导入:mock getDeptList 返回一个可匹配的部门 |
| | | DeptDO dept = randomPojo(DeptDO.class, o -> { |
| | | o.setId(importUser.getDeptId()); |
| | | o.setId(1L); |
| | | o.setName(importUser.getDeptName()); |
| | | o.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| | | }); |
| | | when(deptService.getDeptList(any(DeptListReqVO.class))).thenReturn(newArrayList(dept)); |
| | | when(deptService.getDept(eq(dept.getId()))).thenReturn(dept); |
| | | |
| | | // 调用 |