1. 修复 LoginLogServiceImplTest
2. 修复 OperateLogServiceImplTest 3. 修复 SmsLogServiceTest
This commit is contained in:
parent
40d3324266
commit
de09f992bf
@ -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));
|
||||
}
|
||||
|
@ -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());
|
||||
});
|
||||
|
||||
|
@ -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方法
|
||||
|
@ -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;
|
||||
@ -44,47 +43,49 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Test
|
||||
public void testGetSmsLogPage() {
|
||||
// mock 数据
|
||||
SmsLogDO dbSmsLog = randomSmsLogDO(o -> { // 等会查询到
|
||||
o.setChannelId(1L);
|
||||
o.setTemplateId(10L);
|
||||
o.setMobile("15601691300");
|
||||
o.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
|
||||
o.setSendTime(buildLocalDateTime(2020, 11, 11));
|
||||
o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
|
||||
o.setReceiveTime(buildLocalDateTime(2021, 11, 11));
|
||||
});
|
||||
smsLogMapper.insert(dbSmsLog);
|
||||
// 测试 channelId 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L)));
|
||||
// 测试 templateId 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L)));
|
||||
// 测试 mobile 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999")));
|
||||
// 测试 sendStatus 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus())));
|
||||
// 测试 sendTime 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildLocalDateTime(2020, 12, 12))));
|
||||
// 测试 receiveStatus 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus())));
|
||||
// 测试 receiveTime 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildLocalDateTime(2021, 12, 12))));
|
||||
// 准备参数
|
||||
SmsLogPageReqVO reqVO = new SmsLogPageReqVO();
|
||||
reqVO.setChannelId(1L);
|
||||
reqVO.setTemplateId(10L);
|
||||
reqVO.setMobile("156");
|
||||
reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
|
||||
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)}));
|
||||
// mock 数据
|
||||
SmsLogDO dbSmsLog = randomSmsLogDO(o -> { // 等会查询到
|
||||
o.setChannelId(1L);
|
||||
o.setTemplateId(10L);
|
||||
o.setMobile("15601691300");
|
||||
o.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
|
||||
o.setSendTime(buildLocalDateTime(2020, 11, 11));
|
||||
o.setReceiveStatus(SmsReceiveStatusEnum.INIT.getStatus());
|
||||
o.setReceiveTime(buildLocalDateTime(2021, 11, 11));
|
||||
});
|
||||
smsLogMapper.insert(dbSmsLog);
|
||||
// 测试 channelId 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setChannelId(2L)));
|
||||
// 测试 templateId 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setTemplateId(20L)));
|
||||
// 测试 mobile 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setMobile("18818260999")));
|
||||
// 测试 sendStatus 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendStatus(SmsSendStatusEnum.IGNORE.getStatus())));
|
||||
// 测试 sendTime 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setSendTime(buildLocalDateTime(2020, 12, 12))));
|
||||
// 测试 receiveStatus 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveStatus(SmsReceiveStatusEnum.SUCCESS.getStatus())));
|
||||
// 测试 receiveTime 不匹配
|
||||
smsLogMapper.insert(ObjectUtils.cloneIgnoreId(dbSmsLog, o -> o.setReceiveTime(buildLocalDateTime(2021, 12, 12))));
|
||||
// 准备参数
|
||||
SmsLogPageReqVO reqVO = new SmsLogPageReqVO();
|
||||
reqVO.setChannelId(1L);
|
||||
reqVO.setTemplateId(10L);
|
||||
reqVO.setMobile("156");
|
||||
reqVO.setSendStatus(SmsSendStatusEnum.INIT.getStatus());
|
||||
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)}));
|
||||
|
||||
// 调用
|
||||
PageResult<SmsLogDO> pageResult = smsLogService.getSmsLogPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSmsLog, pageResult.getList().get(0));
|
||||
// 调用
|
||||
PageResult<SmsLogDO> pageResult = smsLogService.getSmsLogPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSmsLog, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -126,11 +127,11 @@ public class SmsLogServiceTest extends BaseDbUnitTest {
|
||||
reqVO.setReceiveTime((new LocalDateTime[]{buildLocalDateTime(2021, 11, 1),
|
||||
buildLocalDateTime(2021, 11, 30)}));
|
||||
|
||||
// 调用
|
||||
List<SmsLogDO> list = smsLogService.getSmsLogList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbSmsLog, list.get(0));
|
||||
// 调用
|
||||
List<SmsLogDO> list = smsLogService.getSmsLogList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbSmsLog, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user