|
|
@@ -0,0 +1,274 @@
|
|
|
+package cn.iocoder.yudao.module.employee.service.employeeinfo;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.employee.controller.admin.employeeinfo.vo.*;
|
|
|
+import cn.iocoder.yudao.module.employee.dal.dataobject.employeeinfo.EmployeeInfoDO;
|
|
|
+import cn.iocoder.yudao.module.employee.dal.mysql.employeeinfo.EmployeeInfoMapper;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+
|
|
|
+import org.springframework.context.annotation.Import;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
|
|
+import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
|
|
+import static cn.iocoder.yudao.module.employee.enums.ErrorCodeConstants.EMPLOYEE_INFO_NOT_EXISTS;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link EmployeeInfoServiceImpl} 的单元测试类
|
|
|
+ *
|
|
|
+ * @author 芋道源码
|
|
|
+ */
|
|
|
+@Import(EmployeeInfoServiceImpl.class)
|
|
|
+public class EmployeeInfoServiceImplTest extends BaseDbUnitTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EmployeeInfoServiceImpl infoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EmployeeInfoMapper infoMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreateInfo_success() {
|
|
|
+ // 准备参数
|
|
|
+ EmployeeInfoSaveReqVO createReqVO = randomPojo(EmployeeInfoSaveReqVO.class).setId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ Long infoId = infoService.createInfo(createReqVO);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(infoId);
|
|
|
+ // 校验记录的属性是否正确
|
|
|
+ EmployeeInfoDO info = infoMapper.selectById(infoId);
|
|
|
+ assertPojoEquals(createReqVO, info, "id");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateInfo_success() {
|
|
|
+ // mock 数据
|
|
|
+ EmployeeInfoDO dbInfo = randomPojo(EmployeeInfoDO.class);
|
|
|
+ infoMapper.insert(dbInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ EmployeeInfoSaveReqVO updateReqVO = randomPojo(EmployeeInfoSaveReqVO.class, o -> {
|
|
|
+ o.setId(dbInfo.getId()); // 设置更新的 ID
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ infoService.updateInfo(updateReqVO);
|
|
|
+ // 校验是否更新正确
|
|
|
+ EmployeeInfoDO info = infoMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+ assertPojoEquals(updateReqVO, info);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateInfo_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ EmployeeInfoSaveReqVO updateReqVO = randomPojo(EmployeeInfoSaveReqVO.class);
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> infoService.updateInfo(updateReqVO), EMPLOYEE_INFO_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteInfo_success() {
|
|
|
+ // mock 数据
|
|
|
+ EmployeeInfoDO dbInfo = randomPojo(EmployeeInfoDO.class);
|
|
|
+ infoMapper.insert(dbInfo);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbInfo.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ infoService.deleteInfo(id);
|
|
|
+ // 校验数据不存在了
|
|
|
+ assertNull(infoMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteInfo_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ Long id = randomLongId();
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> infoService.deleteInfo(id), EMPLOYEE_INFO_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+ public void testGetInfoPage() {
|
|
|
+ // mock 数据
|
|
|
+ EmployeeInfoDO dbInfo = randomPojo(EmployeeInfoDO.class, o -> { // 等会查询到
|
|
|
+ o.setInfoId(null);
|
|
|
+ o.setEmployeeNumber(null);
|
|
|
+ o.setName(null);
|
|
|
+ o.setDeptId(null);
|
|
|
+ o.setPhone(null);
|
|
|
+ o.setAvatar(null);
|
|
|
+ o.setEmail(null);
|
|
|
+ o.setPosition(null);
|
|
|
+ o.setPostId(null);
|
|
|
+ o.setEntryDate(null);
|
|
|
+ o.setProbationEndDate(null);
|
|
|
+ o.setWorkLocation(null);
|
|
|
+ o.setEmployeeStatus(null);
|
|
|
+ o.setGender(null);
|
|
|
+ o.setBirthDate(null);
|
|
|
+ o.setMarriageStatus(null);
|
|
|
+ o.setIdCardNumber(null);
|
|
|
+ o.setIdCardAddress(null);
|
|
|
+ o.setHouseholdType(null);
|
|
|
+ o.setHouseholdLocation(null);
|
|
|
+ o.setEducationLevel(null);
|
|
|
+ o.setMajor(null);
|
|
|
+ o.setGraduationSchool(null);
|
|
|
+ o.setGraduationDate(null);
|
|
|
+ o.setWorkStartDate(null);
|
|
|
+ o.setAnnualLeaveDays(null);
|
|
|
+ o.setSalaryBank(null);
|
|
|
+ o.setSalaryCardNumber(null);
|
|
|
+ o.setSalary(null);
|
|
|
+ o.setPositionSalary(null);
|
|
|
+ o.setProjectAllowance(null);
|
|
|
+ o.setSpecialPositionAllowance(null);
|
|
|
+ o.setForeignAllowance(null);
|
|
|
+ o.setLunchSubsidy(null);
|
|
|
+ o.setSpecialAllowance(null);
|
|
|
+ o.setSubsidy(null);
|
|
|
+ o.setYearEndBonus(null);
|
|
|
+ o.setStatus(null);
|
|
|
+ o.setCreateTime(null);
|
|
|
+ o.setUserId(null);
|
|
|
+ });
|
|
|
+ infoMapper.insert(dbInfo);
|
|
|
+ // 测试 infoId 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setInfoId(null)));
|
|
|
+ // 测试 employeenumber 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setEmployeeNumber(null)));
|
|
|
+ // 测试 name 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setName(null)));
|
|
|
+ // 测试 deptId 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setDeptId(null)));
|
|
|
+ // 测试 phone 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setPhone(null)));
|
|
|
+ // 测试 avatar 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setAvatar(null)));
|
|
|
+ // 测试 email 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setEmail(null)));
|
|
|
+ // 测试 position 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setPosition(null)));
|
|
|
+ // 测试 postId 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setPostId(null)));
|
|
|
+ // 测试 entryDate 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setEntryDate(null)));
|
|
|
+ // 测试 probationEndDate 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setProbationEndDate(null)));
|
|
|
+ // 测试 workLocation 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setWorkLocation(null)));
|
|
|
+ // 测试 employeeStatus 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setEmployeeStatus(null)));
|
|
|
+ // 测试 gender 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setGender(null)));
|
|
|
+ // 测试 birthDate 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setBirthDate(null)));
|
|
|
+ // 测试 marriageStatus 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setMarriageStatus(null)));
|
|
|
+ // 测试 idCardNumber 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setIdCardNumber(null)));
|
|
|
+ // 测试 idCardAddress 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setIdCardAddress(null)));
|
|
|
+ // 测试 householdType 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setHouseholdType(null)));
|
|
|
+ // 测试 householdLocation 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setHouseholdLocation(null)));
|
|
|
+ // 测试 educationLevel 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setEducationLevel(null)));
|
|
|
+ // 测试 major 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setMajor(null)));
|
|
|
+ // 测试 graduationSchool 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setGraduationSchool(null)));
|
|
|
+ // 测试 graduationDate 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setGraduationDate(null)));
|
|
|
+ // 测试 workStartDate 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setWorkStartDate(null)));
|
|
|
+ // 测试 annualLeaveDays 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setAnnualLeaveDays(null)));
|
|
|
+ // 测试 salaryBank 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSalaryBank(null)));
|
|
|
+ // 测试 salaryCardNumber 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSalaryCardNumber(null)));
|
|
|
+ // 测试 salary 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSalary(null)));
|
|
|
+ // 测试 positionSalary 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setPositionSalary(null)));
|
|
|
+ // 测试 projectAllowance 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setProjectAllowance(null)));
|
|
|
+ // 测试 specialPositionAllowance 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSpecialPositionAllowance(null)));
|
|
|
+ // 测试 foreignAllowance 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setForeignAllowance(null)));
|
|
|
+ // 测试 lunchSubsidy 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setLunchSubsidy(null)));
|
|
|
+ // 测试 specialAllowance 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSpecialAllowance(null)));
|
|
|
+ // 测试 subsidy 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setSubsidy(null)));
|
|
|
+ // 测试 yearEndBonus 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setYearEndBonus(null)));
|
|
|
+ // 测试 status 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setStatus(null)));
|
|
|
+ // 测试 createTime 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setCreateTime(null)));
|
|
|
+ // 测试 userId 不匹配
|
|
|
+ infoMapper.insert(cloneIgnoreId(dbInfo, o -> o.setUserId(null)));
|
|
|
+ // 准备参数
|
|
|
+ EmployeeInfoPageReqVO reqVO = new EmployeeInfoPageReqVO();
|
|
|
+ reqVO.setInfoId(null);
|
|
|
+ reqVO.setEmployeeNumber(null);
|
|
|
+ reqVO.setName(null);
|
|
|
+ reqVO.setDeptId(null);
|
|
|
+ reqVO.setPhone(null);
|
|
|
+ reqVO.setAvatar(null);
|
|
|
+ reqVO.setEmail(null);
|
|
|
+ reqVO.setPosition(null);
|
|
|
+ reqVO.setPostId(null);
|
|
|
+ reqVO.setWorkLocation(null);
|
|
|
+ reqVO.setEmployeeStatus(null);
|
|
|
+ reqVO.setGender(null);
|
|
|
+ reqVO.setMarriageStatus(null);
|
|
|
+ reqVO.setIdCardNumber(null);
|
|
|
+ reqVO.setIdCardAddress(null);
|
|
|
+ reqVO.setHouseholdType(null);
|
|
|
+ reqVO.setHouseholdLocation(null);
|
|
|
+ reqVO.setEducationLevel(null);
|
|
|
+ reqVO.setMajor(null);
|
|
|
+ reqVO.setGraduationSchool(null);
|
|
|
+ reqVO.setAnnualLeaveDays(null);
|
|
|
+ reqVO.setSalaryBank(null);
|
|
|
+ reqVO.setSalaryCardNumber(null);
|
|
|
+ reqVO.setSalary(null);
|
|
|
+ reqVO.setPositionSalary(null);
|
|
|
+ reqVO.setProjectAllowance(null);
|
|
|
+ reqVO.setSpecialPositionAllowance(null);
|
|
|
+ reqVO.setForeignAllowance(null);
|
|
|
+ reqVO.setLunchSubsidy(null);
|
|
|
+ reqVO.setSpecialAllowance(null);
|
|
|
+ reqVO.setSubsidy(null);
|
|
|
+ reqVO.setYearEndBonus(null);
|
|
|
+ reqVO.setStatus(null);
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+ reqVO.setUserId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ PageResult<EmployeeInfoDO> pageResult = infoService.getInfoPage(reqVO);
|
|
|
+ // 断言
|
|
|
+ assertEquals(1, pageResult.getTotal());
|
|
|
+ assertEquals(1, pageResult.getList().size());
|
|
|
+ assertPojoEquals(dbInfo, pageResult.getList().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|