完善 SmsLogServiceImpl 单元测试

This commit is contained in:
YunaiV 2023-02-02 21:08:40 +08:00
parent 36c8448ed5
commit 0d81431541

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.sms.vo.log.SmsLogPageReqVO;
@ -26,7 +25,9 @@ import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.randomBoolean; import static cn.hutool.core.util.RandomUtil.randomBoolean;
import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildLocalDateTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -49,36 +50,34 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
o.setTemplateId(10L); o.setTemplateId(10L);
o.setMobile("15601691300"); o.setMobile("15601691300");
o.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); o.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
o.setSendTime(buildLocalDateTime(2020, 11, 11)); o.setSendTime(buildTime(2020, 11, 11));
o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
o.setReceiveTime(buildLocalDateTime(2021, 11, 11)); o.setReceiveTime(buildTime(2021, 11, 11));
}); });
smsLogMapper.insert(dbSmsLog); smsLogMapper.insert(dbSmsLog);
// 测试 channelId 不匹配 // 测试 channelId 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L)));
// 测试 templateId 不匹配 // 测试 templateId 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L)));
// 测试 mobile 不匹配 // 测试 mobile 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999"))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999")));
// 测试 sendStatus 不匹配 // 测试 sendStatus 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus()))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus())));
// 测试 sendTime 不匹配 // 测试 sendTime 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildLocalDateTime(2020, 12, 12)))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildTime(2020, 12, 12))));
// 测试 receiveStatus 不匹配 // 测试 receiveStatus 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus()))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus())));
// 测试 receiveTime 不匹配 // 测试 receiveTime 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildLocalDateTime(2021, 12, 12)))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildTime(2021, 12, 12))));
// 准备参数 // 准备参数
SmsLogPageReqVO reqVO = new SmsLogPageReqVO(); SmsLogPageReqVO reqVO = new SmsLogPageReqVO();
reqVO.setChannelId(1L); reqVO.setChannelId(1L);
reqVO.setTemplateId(10L); reqVO.setTemplateId(10L);
reqVO.setMobile("156"); reqVO.setMobile("156");
reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
reqVO.setSendTime((new LocalDateTime[]{buildLocalDateTime(2020, 11, 1), reqVO.setSendTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30));
buildLocalDateTime(2020, 11, 30)}));
reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
reqVO.setReceiveTime((new LocalDateTime[]{buildLocalDateTime(2021, 11, 1), reqVO.setReceiveTime(buildBetweenTime(2021, 11, 1, 2021, 11, 30));
buildLocalDateTime(2021, 11, 30)}));
// 调用 // 调用
PageResult<SmsLogDO> pageResult = smsLogService.getSmsLogPage(reqVO); PageResult<SmsLogDO> pageResult = smsLogService.getSmsLogPage(reqVO);
@ -96,36 +95,34 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
o.setTemplateId(10L); o.setTemplateId(10L);
o.setMobile("15601691300"); o.setMobile("15601691300");
o.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); o.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
o.setSendTime(buildLocalDateTime(2020, 11, 11)); o.setSendTime(buildTime(2020, 11, 11));
o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
o.setReceiveTime(buildLocalDateTime(2021, 11, 11)); o.setReceiveTime(buildTime(2021, 11, 11));
}); });
smsLogMapper.insert(dbSmsLog); smsLogMapper.insert(dbSmsLog);
// 测试 channelId 不匹配 // 测试 channelId 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L)));
// 测试 templateId 不匹配 // 测试 templateId 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L)));
// 测试 mobile 不匹配 // 测试 mobile 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999"))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999")));
// 测试 sendStatus 不匹配 // 测试 sendStatus 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus()))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus())));
// 测试 sendTime 不匹配 // 测试 sendTime 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildLocalDateTime(2020, 12, 12)))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildTime(2020, 12, 12))));
// 测试 receiveStatus 不匹配 // 测试 receiveStatus 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus()))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus())));
// 测试 receiveTime 不匹配 // 测试 receiveTime 不匹配
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildLocalDateTime(2021, 12, 12)))); smsLogMapper.insert(cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildTime(2021, 12, 12))));
// 准备参数 // 准备参数
SmsLogExportReqVO reqVO = new SmsLogExportReqVO(); SmsLogExportReqVO reqVO = new SmsLogExportReqVO();
reqVO.setChannelId(1L); reqVO.setChannelId(1L);
reqVO.setTemplateId(10L); reqVO.setTemplateId(10L);
reqVO.setMobile("156"); reqVO.setMobile("156");
reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus()); reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
reqVO.setSendTime((new LocalDateTime[]{buildLocalDateTime(2020, 11, 1), reqVO.setSendTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30));
buildLocalDateTime(2020, 11, 30)}));
reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus()); reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
reqVO.setReceiveTime((new LocalDateTime[]{buildLocalDateTime(2021, 11, 1), reqVO.setReceiveTime(buildBetweenTime(2021, 11, 1, 2021, 11, 30));
buildLocalDateTime(2021, 11, 30)}));
// 调用 // 调用
List<SmsLogDO> list = smsLogService.getSmsLogList(reqVO); List<SmsLogDO> list = smsLogService.getSmsLogList(reqVO);
@ -235,7 +232,6 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
return randomPojo(SmsLogDO.class, ArrayUtils.append(consumer, consumers)); return randomPojo(SmsLogDO.class, ArrayUtils.append(consumer, consumers));
} }
private static Map<String, Object> randomTemplateParams() { private static Map<String, Object> randomTemplateParams() {
return MapUtil.<String, Object>builder().put(randomString(), randomString()) return MapUtil.<String, Object>builder().put(randomString(), randomString())
.put(randomString(), randomString()).build(); .put(randomString(), randomString()).build();