1. 修复 LoginLogServiceImplTest

2. 修复 OperateLogServiceImplTest
3. 修复 SmsLogServiceTest
This commit is contained in:
YunaiV 2022-11-11 01:39:41 +08:00
parent 40d3324266
commit de09f992bf
4 changed files with 74 additions and 70 deletions

View File

@ -20,7 +20,7 @@ public interface SmsLogMapper extends BaseMapperX<SmsLogDO> {
.likeIfPresent(SmsLogDO::getMobile, reqVO.getMobile())
.eqIfPresent(SmsLogDO::getSendStatus, reqVO.getSendStatus())
.betweenIfPresent(SmsLogDO::getSendTime, reqVO.getSendTime())
.eqIfPresent(SmsLogDO::getSendStatus, reqVO.getReceiveStatus())
.eqIfPresent(SmsLogDO::getReceiveStatus, reqVO.getReceiveStatus())
.betweenIfPresent(SmsLogDO::getReceiveTime, reqVO.getReceiveTime())
.orderByDesc(SmsLogDO::getId));
}
@ -32,7 +32,7 @@ public interface SmsLogMapper extends BaseMapperX<SmsLogDO> {
.likeIfPresent(SmsLogDO::getMobile, reqVO.getMobile())
.eqIfPresent(SmsLogDO::getSendStatus, reqVO.getSendStatus())
.betweenIfPresent(SmsLogDO::getSendTime, reqVO.getSendTime())
.eqIfPresent(SmsLogDO::getSendStatus, reqVO.getReceiveStatus())
.eqIfPresent(SmsLogDO::getReceiveStatus, reqVO.getReceiveStatus())
.betweenIfPresent(SmsLogDO::getReceiveTime, reqVO.getReceiveTime())
.orderByDesc(SmsLogDO::getId));
}

View File

@ -1,19 +1,18 @@
package cn.iocoder.yudao.module.system.service.logger;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
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.util.RandomUtils;
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.loginlog.LoginLogPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.logger.LoginLogDO;
import cn.iocoder.yudao.module.system.dal.mysql.logger.LoginLogMapper;
import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
@ -22,8 +21,9 @@ import java.time.LocalDateTime;
import java.util.List;
import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildLocalDateTime;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Import(LoginLogServiceImpl.class)
@ -40,20 +40,20 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest {
// 构造测试数据
// 登录成功的
LoginLogDO loginLogDO = RandomUtils.randomPojo(LoginLogDO.class, logDO -> {
logDO.setLogType(RandomUtil.randomEle(cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum.values()).getType());
logDO.setLogType(RandomUtil.randomEle(LoginLogTypeEnum.values()).getType());
logDO.setTraceId(TracerUtils.getTraceId());
logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue());
logDO.setUserIp("192.168.199.16");
logDO.setUsername("wangkai");
logDO.setCreateTime(buildLocalDateTime(2021, 3, 6));
logDO.setResult(cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.SUCCESS.getResult());
logDO.setResult(SUCCESS.getResult());
});
loginLogMapper.insert(loginLogDO);
// 下面几个都是不匹配的数据
// 登录失败的
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.CAPTCHA_CODE_ERROR.getResult())));
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(CAPTCHA_CODE_ERROR.getResult())));
// 不同ip段的
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUserIp("192.168.128.18")));
// 不同username
@ -67,7 +67,8 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest {
reqVO.setUsername("wangkai");
reqVO.setUserIp("192.168.199");
reqVO.setStatus(true);
reqVO.setCreateTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),buildLocalDateTime(2021, 3, 5)}));
reqVO.setCreateTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),
buildLocalDateTime(2021, 3, 7)}));
// 调用service方法
PageResult<LoginLogDO> pageResult = loginLogService.getLoginLogPage(reqVO);
@ -84,20 +85,20 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest {
// 登录成功的
LoginLogDO loginLogDO = RandomUtils.randomPojo(LoginLogDO.class, logDO -> {
logDO.setLogType(RandomUtil.randomEle(cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum.values()).getType());
logDO.setLogType(RandomUtil.randomEle(LoginLogTypeEnum.values()).getType());
logDO.setTraceId(TracerUtils.getTraceId());
logDO.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue());
logDO.setUserIp("192.168.111.16");
logDO.setUsername("wangxiaokai");
logDO.setCreateTime(buildLocalDateTime(2021, 3, 6));
logDO.setResult(cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.SUCCESS.getResult());
logDO.setResult(SUCCESS.getResult());
});
loginLogMapper.insert(loginLogDO);
// 下面几个都是不匹配的数据
// 登录失败的
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum.CAPTCHA_CODE_ERROR.getResult())));
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setResult(CAPTCHA_CODE_ERROR.getResult())));
// 不同ip段的
loginLogMapper.insert(ObjectUtils.cloneIgnoreId(loginLogDO, logDO -> logDO.setUserIp("192.168.128.18")));
// 不同username
@ -110,7 +111,8 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest {
reqVO.setUsername("wangxiaokai");
reqVO.setUserIp("192.168.111");
reqVO.setStatus(true);
reqVO.setCreateTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),buildLocalDateTime(2021, 3, 5)}));
reqVO.setCreateTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),
buildLocalDateTime(2021, 3, 7)}));
// 调用service方法
List<LoginLogDO> loginLogList = loginLogService.getLoginLogList(reqVO);
@ -126,7 +128,7 @@ public class LoginLogServiceImplTest extends BaseDbUnitTest {
// 指定随机的范围,避免超出范围入库失败
vo.setUserType(randomEle(UserTypeEnum.values()).getValue());
vo.setLogType(randomEle(LoginLogTypeEnum.values()).getType());
vo.setResult(randomEle(LoginResultEnum.values()).getResult());
vo.setResult(randomEle(values()).getResult());
vo.setTraceId(TracerUtils.getTraceId());
});

View File

@ -104,7 +104,8 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest {
reqVO.setUserNickname("wangkai");
reqVO.setModule("order");
reqVO.setType(OperateTypeEnum.CREATE.getType());
reqVO.setStartTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),buildLocalDateTime(2021, 3, 7)}));
reqVO.setStartTime((new LocalDateTime[]{buildLocalDateTime(2021, 3, 5),
buildLocalDateTime(2021, 3, 7)}));
reqVO.setSuccess(true);
// 调用service方法

View File

@ -1,7 +1,12 @@
package cn.iocoder.yudao.module.system.service.sms;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.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.dal.dataobject.sms.SmsLogDO;
@ -10,11 +15,6 @@ import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsLogMapper;
import cn.iocoder.yudao.module.system.enums.sms.SmsReceiveStatusEnum;
import cn.iocoder.yudao.module.system.enums.sms.SmsSendStatusEnum;
import cn.iocoder.yudao.module.system.enums.sms.SmsTemplateTypeEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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 org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
@ -27,7 +27,6 @@ import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.randomBoolean;
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.DateUtils.buildTime;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -75,9 +74,11 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
reqVO.setTemplateId(10L);
reqVO.setMobile("156");
reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
reqVO.setSendTime((new LocalDateTime[]{buildLocalDateTime(2020, 11, 1), buildLocalDateTime(2020, 11, 30)}));
reqVO.setSendTime((new LocalDateTime[]{buildLocalDateTime(2020, 11, 1),
buildLocalDateTime(2020, 11, 30)}));
reqVO.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
reqVO.setReceiveTime((new LocalDateTime[]{buildLocalDateTime(2021, 11, 1), buildLocalDateTime(2021, 11, 30)}));
reqVO.setReceiveTime((new LocalDateTime[]{buildLocalDateTime(2021, 11, 1),
buildLocalDateTime(2021, 11, 30)}));
// 调用
PageResult<SmsLogDO> pageResult = smsLogService.getSmsLogPage(reqVO);