|
|
@@ -0,0 +1,225 @@
|
|
|
+package cn.iocoder.yudao.module.bpm.service.oa.renew;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.oa.renew.vo.OaRenewPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.oa.renew.vo.OaRenewSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.service.oa.renew.OaRenewServiceImpl;
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.renew.OaRenewDO;
|
|
|
+import cn.iocoder.yudao.module.bpm.dal.mysql.oa.renew.OaRenewMapper;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+
|
|
|
+import org.springframework.context.annotation.Import;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
|
|
+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 org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link OaRenewServiceImpl} 的单元测试类
|
|
|
+ *
|
|
|
+ * @author dp
|
|
|
+ */
|
|
|
+@Import(OaRenewServiceImpl.class)
|
|
|
+public class OaRenewServiceImplTest extends BaseDbUnitTest {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OaRenewServiceImpl oaRenewService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OaRenewMapper oaRenewMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreateOaRenew_success() {
|
|
|
+ // 准备参数
|
|
|
+ OaRenewSaveReqVO createReqVO = randomPojo(OaRenewSaveReqVO.class).setId(null);
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ Long oaRenewId = oaRenewService.createOaRenew(createReqVO);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(oaRenewId);
|
|
|
+ // 校验记录的属性是否正确
|
|
|
+ OaRenewDO oaRenew = oaRenewMapper.selectById(oaRenewId);
|
|
|
+ assertPojoEquals(createReqVO, oaRenew, "id");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateOaRenew_success() {
|
|
|
+ // mock 数据
|
|
|
+ OaRenewDO dbOaRenew = randomPojo(OaRenewDO.class);
|
|
|
+ oaRenewMapper.insert(dbOaRenew);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ OaRenewSaveReqVO updateReqVO = randomPojo(OaRenewSaveReqVO.class, o -> {
|
|
|
+ o.setId(dbOaRenew.getId()); // 设置更新的 ID
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ oaRenewService.updateOaRenew(updateReqVO);
|
|
|
+ // 校验是否更新正确
|
|
|
+ OaRenewDO oaRenew = oaRenewMapper.selectById(updateReqVO.getId()); // 获取最新的
|
|
|
+ assertPojoEquals(updateReqVO, oaRenew);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateOaRenew_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ OaRenewSaveReqVO updateReqVO = randomPojo(OaRenewSaveReqVO.class);
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> oaRenewService.updateOaRenew(updateReqVO), OA_RENEW_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteOaRenew_success() {
|
|
|
+ // mock 数据
|
|
|
+ OaRenewDO dbOaRenew = randomPojo(OaRenewDO.class);
|
|
|
+ oaRenewMapper.insert(dbOaRenew);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbOaRenew.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ oaRenewService.deleteOaRenew(id);
|
|
|
+ // 校验数据不存在了
|
|
|
+ assertNull(oaRenewMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteOaRenew_notExists() {
|
|
|
+ // 准备参数
|
|
|
+ Long id = randomLongId();
|
|
|
+
|
|
|
+ // 调用, 并断言异常
|
|
|
+ assertServiceException(() -> oaRenewService.deleteOaRenew(id), OA_RENEW_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
|
+ public void testGetOaRenewPage() {
|
|
|
+ // mock 数据
|
|
|
+ OaRenewDO dbOaRenew = randomPojo(OaRenewDO.class, o -> { // 等会查询到
|
|
|
+ o.setRenewId(null);
|
|
|
+ o.setEmployeeId(null);
|
|
|
+ o.setEmployeeUuid(null);
|
|
|
+ o.setEmployeeName(null);
|
|
|
+ o.setUserId(null);
|
|
|
+ o.setUserUuid(null);
|
|
|
+ o.setDeptId(null);
|
|
|
+ o.setDeptUuid(null);
|
|
|
+ o.setPosition(null);
|
|
|
+ o.setOldContractStartDate(null);
|
|
|
+ o.setOldContractEndDate(null);
|
|
|
+ o.setRenewPeriod(null);
|
|
|
+ o.setRenewContractStartDate(null);
|
|
|
+ o.setRenewContractEndDate(null);
|
|
|
+ o.setRenewReason(null);
|
|
|
+ o.setWorkPerformance(null);
|
|
|
+ o.setRemarks(null);
|
|
|
+ o.setProcInstId(null);
|
|
|
+ o.setAuditStatus(null);
|
|
|
+ o.setCurrentAuditUserId(null);
|
|
|
+ o.setCurrentAuditUserUuid(null);
|
|
|
+ o.setCurrentAuditEmployeeId(null);
|
|
|
+ o.setCurrentAuditEmployeeUuid(null);
|
|
|
+ o.setFinalAuditDate(null);
|
|
|
+ o.setInfoSource(null);
|
|
|
+ o.setCreateTime(null);
|
|
|
+ });
|
|
|
+ oaRenewMapper.insert(dbOaRenew);
|
|
|
+ // 测试 renewId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRenewId(null)));
|
|
|
+ // 测试 employeeId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setEmployeeId(null)));
|
|
|
+ // 测试 employeeUuid 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setEmployeeUuid(null)));
|
|
|
+ // 测试 employeeName 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setEmployeeName(null)));
|
|
|
+ // 测试 userId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setUserId(null)));
|
|
|
+ // 测试 userUuid 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setUserUuid(null)));
|
|
|
+ // 测试 deptId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setDeptId(null)));
|
|
|
+ // 测试 deptUuid 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setDeptUuid(null)));
|
|
|
+ // 测试 position 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setPosition(null)));
|
|
|
+ // 测试 oldContractStartDate 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setOldContractStartDate(null)));
|
|
|
+ // 测试 oldContractEndDate 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setOldContractEndDate(null)));
|
|
|
+ // 测试 renewPeriod 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRenewPeriod(null)));
|
|
|
+ // 测试 renewContractStartDate 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRenewContractStartDate(null)));
|
|
|
+ // 测试 renewContractEndDate 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRenewContractEndDate(null)));
|
|
|
+ // 测试 renewReason 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRenewReason(null)));
|
|
|
+ // 测试 workPerformance 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setWorkPerformance(null)));
|
|
|
+ // 测试 remarks 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setRemarks(null)));
|
|
|
+ // 测试 procInstId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setProcInstId(null)));
|
|
|
+ // 测试 auditStatus 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setAuditStatus(null)));
|
|
|
+ // 测试 currentAuditUserId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setCurrentAuditUserId(null)));
|
|
|
+ // 测试 currentAuditUserUuid 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setCurrentAuditUserUuid(null)));
|
|
|
+ // 测试 currentAuditEmployeeId 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setCurrentAuditEmployeeId(null)));
|
|
|
+ // 测试 currentAuditEmployeeUuid 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setCurrentAuditEmployeeUuid(null)));
|
|
|
+ // 测试 finalAuditDate 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setFinalAuditDate(null)));
|
|
|
+ // 测试 infoSource 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setInfoSource(null)));
|
|
|
+ // 测试 createTime 不匹配
|
|
|
+ oaRenewMapper.insert(cloneIgnoreId(dbOaRenew, o -> o.setCreateTime(null)));
|
|
|
+ // 准备参数
|
|
|
+ OaRenewPageReqVO reqVO = new OaRenewPageReqVO();
|
|
|
+ reqVO.setRenewId(null);
|
|
|
+ reqVO.setEmployeeId(null);
|
|
|
+ reqVO.setEmployeeUuid(null);
|
|
|
+ reqVO.setEmployeeName(null);
|
|
|
+ reqVO.setUserId(null);
|
|
|
+ reqVO.setUserUuid(null);
|
|
|
+ reqVO.setDeptId(null);
|
|
|
+ reqVO.setDeptUuid(null);
|
|
|
+ reqVO.setPosition(null);
|
|
|
+ reqVO.setOldContractStartDate(null);
|
|
|
+ reqVO.setOldContractEndDate(null);
|
|
|
+ reqVO.setRenewPeriod(null);
|
|
|
+ reqVO.setRenewContractStartDate(null);
|
|
|
+ reqVO.setRenewContractEndDate(null);
|
|
|
+ reqVO.setRenewReason(null);
|
|
|
+ reqVO.setWorkPerformance(null);
|
|
|
+ reqVO.setRemarks(null);
|
|
|
+ reqVO.setProcInstId(null);
|
|
|
+ reqVO.setAuditStatus(null);
|
|
|
+ reqVO.setCurrentAuditUserId(null);
|
|
|
+ reqVO.setCurrentAuditUserUuid(null);
|
|
|
+ reqVO.setCurrentAuditEmployeeId(null);
|
|
|
+ reqVO.setCurrentAuditEmployeeUuid(null);
|
|
|
+ reqVO.setFinalAuditDate(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+ reqVO.setInfoSource(null);
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ PageResult<OaRenewDO> pageResult = oaRenewService.getOaRenewPage(reqVO);
|
|
|
+ // 断言
|
|
|
+ assertEquals(1, pageResult.getTotal());
|
|
|
+ assertEquals(1, pageResult.getList().size());
|
|
|
+ assertPojoEquals(dbOaRenew, pageResult.getList().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|