1. 修复所有的单元测试

2. 最新的 sql 脚本
pull/2/head
YunaiV 2021-03-21 20:10:04 +08:00
parent b8857df7fe
commit 64b085ae0d
17 changed files with 104 additions and 1205 deletions

File diff suppressed because it is too large Load Diff

View File

@ -50,7 +50,7 @@ public class SysOperateLogController {
@ApiOperation("查看操作日志分页列表") @ApiOperation("查看操作日志分页列表")
@PreAuthorize("@ss.hasPermission('system:operate-log:query')") @PreAuthorize("@ss.hasPermission('system:operate-log:query')")
public CommonResult<PageResult<SysOperateLogRespVO>> pageOperateLog(@Valid SysOperateLogPageReqVO reqVO) { public CommonResult<PageResult<SysOperateLogRespVO>> pageOperateLog(@Valid SysOperateLogPageReqVO reqVO) {
PageResult<SysOperateLogDO> pageResult = operateLogService.pageOperateLog(reqVO); PageResult<SysOperateLogDO> pageResult = operateLogService.getOperateLogPage(reqVO);
// 获得拼接需要的数据 // 获得拼接需要的数据
Collection<Long> userIds = CollectionUtils.convertList(pageResult.getList(), SysOperateLogDO::getUserId); Collection<Long> userIds = CollectionUtils.convertList(pageResult.getList(), SysOperateLogDO::getUserId);
@ -71,7 +71,7 @@ public class SysOperateLogController {
@PreAuthorize("@ss.hasPermission('system:operate-log:export')") @PreAuthorize("@ss.hasPermission('system:operate-log:export')")
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportOperateLog(HttpServletResponse response, @Valid SysOperateLogExportReqVO reqVO) throws IOException { public void exportOperateLog(HttpServletResponse response, @Valid SysOperateLogExportReqVO reqVO) throws IOException {
List<SysOperateLogDO> list = operateLogService.listOperateLogs(reqVO); List<SysOperateLogDO> list = operateLogService.getOperateLogs(reqVO);
// 获得拼接需要的数据 // 获得拼接需要的数据
Collection<Long> userIds = CollectionUtils.convertList(list, SysOperateLogDO::getUserId); Collection<Long> userIds = CollectionUtils.convertList(list, SysOperateLogDO::getUserId);

View File

@ -19,7 +19,7 @@ public interface SysOperateLogService extends OperateLogFrameworkService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
PageResult<SysOperateLogDO> pageOperateLog(SysOperateLogPageReqVO reqVO); PageResult<SysOperateLogDO> getOperateLogPage(SysOperateLogPageReqVO reqVO);
/** /**
* *
@ -27,6 +27,6 @@ public interface SysOperateLogService extends OperateLogFrameworkService {
* @param reqVO * @param reqVO
* @return * @return
*/ */
List<SysOperateLogDO> listOperateLogs(SysOperateLogExportReqVO reqVO); List<SysOperateLogDO> getOperateLogs(SysOperateLogExportReqVO reqVO);
} }

View File

@ -55,7 +55,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
} }
@Override @Override
public PageResult<SysOperateLogDO> pageOperateLog(SysOperateLogPageReqVO reqVO) { public PageResult<SysOperateLogDO> getOperateLogPage(SysOperateLogPageReqVO reqVO) {
// 处理基于用户昵称的查询 // 处理基于用户昵称的查询
Collection<Long> userIds = null; Collection<Long> userIds = null;
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
@ -69,7 +69,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
} }
@Override @Override
public List<SysOperateLogDO> listOperateLogs(SysOperateLogExportReqVO reqVO) { public List<SysOperateLogDO> getOperateLogs(SysOperateLogExportReqVO reqVO) {
// 处理基于用户昵称的查询 // 处理基于用户昵称的查询
Collection<Long> userIds = null; Collection<Long> userIds = null;
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {

View File

@ -1,7 +1,8 @@
package cn.iocoder.dashboard.framework.quartz.core.scheduler; package cn.iocoder.dashboard.framework.quartz.core;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.dashboard.BaseDbUnitTest; import cn.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.framework.quartz.core.scheduler.SchedulerManager;
import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob; import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;

View File

@ -7,6 +7,7 @@ import cn.iocoder.dashboard.modules.system.mq.consumer.mail.SysMailSendConsumer;
import cn.iocoder.dashboard.modules.system.mq.consumer.sms.SysSmsSendConsumer; import cn.iocoder.dashboard.modules.system.mq.consumer.sms.SysSmsSendConsumer;
import cn.iocoder.dashboard.modules.system.mq.message.mail.SysMailSendMessage; import cn.iocoder.dashboard.modules.system.mq.message.mail.SysMailSendMessage;
import cn.iocoder.dashboard.modules.system.mq.message.sms.SysSmsSendMessage; import cn.iocoder.dashboard.modules.system.mq.message.sms.SysSmsSendMessage;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -18,6 +19,7 @@ import java.util.concurrent.TimeUnit;
public class RedisStreamTest { public class RedisStreamTest {
@Import({SysSmsSendConsumer.class, SysMailSendConsumer.class}) @Import({SysSmsSendConsumer.class, SysMailSendConsumer.class})
@Disabled
public static class ConsumerTest extends BaseRedisIntegrationTest { public static class ConsumerTest extends BaseRedisIntegrationTest {
@Test @Test
@ -27,6 +29,7 @@ public class RedisStreamTest {
} }
@Disabled
public static class ProducerTest extends BaseRedisIntegrationTest { public static class ProducerTest extends BaseRedisIntegrationTest {
@Resource @Resource

View File

@ -1,10 +1,11 @@
package cn.iocoder.dashboard.modules.tool.service.codegen.impl; package cn.iocoder.dashboard.modules.tool.service.codegen;
import cn.iocoder.dashboard.BaseDbUnitTest; import cn.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper; import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper; import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.service.codegen.impl.ToolCodegenEngine;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -1,6 +1,7 @@
package cn.iocoder.dashboard.modules.tool.service.codegen.impl; package cn.iocoder.dashboard.modules.tool.service.codegen;
import cn.iocoder.dashboard.BaseDbUnitTest; import cn.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.modules.tool.service.codegen.impl.ToolCodegenSQLParser;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class ToolCodegenSQLParserTest extends BaseDbUnitTest { public class ToolCodegenSQLParserTest extends BaseDbUnitTest {

View File

@ -1,6 +1,7 @@
package cn.iocoder.dashboard.modules.tool.service.codegen.impl; package cn.iocoder.dashboard.modules.tool.service.codegen;
import cn.iocoder.dashboard.BaseDbUnitTest; import cn.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.modules.tool.service.codegen.impl.ToolCodegenServiceImpl;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -17,7 +17,7 @@ public class RedisTestConfiguration {
/** /**
* Redis Server * Redis Server
*/ */
@Bean(destroyMethod = "stop") @Bean
public RedisServer redisServer(RedisProperties properties) throws IOException { public RedisServer redisServer(RedisProperties properties) throws IOException {
RedisServer redisServer = new RedisServer(properties.getPort()); RedisServer redisServer = new RedisServer(properties.getPort());
// TODO 芋艿:一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样就导致端口被占用无法启动。。。 // TODO 芋艿:一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样就导致端口被占用无法启动。。。

View File

@ -38,7 +38,6 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
@Resource @Resource
private InfApiAccessLogMapper infApiAccessLogMapper; private InfApiAccessLogMapper infApiAccessLogMapper;
@Test @Test
public void testCreateApiAccessLogAsync() throws Exception { public void testCreateApiAccessLogAsync() throws Exception {
ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo( ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(
@ -59,13 +58,12 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(createDTO, infApiAccessLogDO); assertPojoEquals(createDTO, infApiAccessLogDO);
} }
@Test @Test
public void testGetApiAccessLogPage() { public void testGetApiAccessLogPage() {
// 构造测试数据 // 构造测试数据
long userId = 2233L; long userId = 2233L;
int userType = UserTypeEnum.ADMIN.getValue(); int userType = UserTypeEnum.ADMIN.getValue();
String applicationName = "ruoyi-test"; String applicationName = "yudao-test";
String requestUrl = "foo"; String requestUrl = "foo";
Date beginTime = buildTime(2021, 3, 13); Date beginTime = buildTime(2021, 3, 13);
int duration = 1000; int duration = 1000;
@ -123,7 +121,7 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
// 构造测试数据 // 构造测试数据
long userId = 2233L; long userId = 2233L;
int userType = UserTypeEnum.ADMIN.getValue(); int userType = UserTypeEnum.ADMIN.getValue();
String applicationName = "ruoyi-test"; String applicationName = "yudao-test";
String requestUrl = "foo"; String requestUrl = "foo";
Date beginTime = buildTime(2021, 3, 13); Date beginTime = buildTime(2021, 3, 13);
int duration = 1000; int duration = 1000;
@ -174,4 +172,5 @@ public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
assertEquals(1, list.size()); assertEquals(1, list.size());
assertPojoEquals(infApiAccessLogDO, list.get(0)); assertPojoEquals(infApiAccessLogDO, list.get(0));
} }
} }

View File

@ -68,7 +68,7 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest {
// 构造测试数据 // 构造测试数据
long userId = 2233L; long userId = 2233L;
int userType = UserTypeEnum.ADMIN.getValue(); int userType = UserTypeEnum.ADMIN.getValue();
String applicationName = "ruoyi-test"; String applicationName = "yudao-test";
String requestUrl = "foo"; String requestUrl = "foo";
Date beginTime = buildTime(2021, 3, 13); Date beginTime = buildTime(2021, 3, 13);
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus(); int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();
@ -121,7 +121,7 @@ public class InfApiErrorLogServiceImplTest extends BaseDbUnitTest {
// 构造测试数据 // 构造测试数据
long userId = 2233L; long userId = 2233L;
int userType = UserTypeEnum.ADMIN.getValue(); int userType = UserTypeEnum.ADMIN.getValue();
String applicationName = "ruoyi-test"; String applicationName = "yudao-test";
String requestUrl = "foo"; String requestUrl = "foo";
Date beginTime = buildTime(2021, 3, 13); Date beginTime = buildTime(2021, 3, 13);
int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus(); int progressStatus = InfApiErrorLogProcessStatusEnum.INIT.getStatus();

View File

@ -1,15 +1,11 @@
package cn.iocoder.dashboard.modules.system.service.logger; package cn.iocoder.dashboard.modules.system.service.logger;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.iocoder.dashboard.BaseDbUnitTest; import cn.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum; import cn.iocoder.dashboard.framework.logger.operatelog.core.enums.OperateTypeEnum;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.framework.tracer.core.util.TracerUtils; import cn.iocoder.dashboard.framework.tracer.core.util.TracerUtils;
import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO; import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOperateLogExportReqVO;
@ -17,7 +13,6 @@ import cn.iocoder.dashboard.modules.system.controller.logger.vo.operatelog.SysOp
import cn.iocoder.dashboard.modules.system.dal.dataobject.logger.SysOperateLogDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.logger.SysOperateLogDO;
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.logger.SysOperateLogMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.logger.SysOperateLogMapper;
import cn.iocoder.dashboard.modules.system.dal.mysql.user.SysUserMapper;
import cn.iocoder.dashboard.modules.system.enums.common.SysSexEnum; import cn.iocoder.dashboard.modules.system.enums.common.SysSexEnum;
import cn.iocoder.dashboard.modules.system.service.logger.impl.SysOperateLogServiceImpl; import cn.iocoder.dashboard.modules.system.service.logger.impl.SysOperateLogServiceImpl;
import cn.iocoder.dashboard.modules.system.service.user.SysUserService; import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
@ -28,105 +23,78 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.Field; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals; import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.dashboard.util.RandomUtils.randomLongId;
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime; import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when;
@Import({SysOperateLogServiceImpl.class}) @Import({SysOperateLogServiceImpl.class})
public class SysOperateLogServiceImplTest extends BaseDbUnitTest { public class SysOperateLogServiceImplTest extends BaseDbUnitTest {
@Resource @Resource
private SysOperateLogService sysOperateLogServiceImpl; private SysOperateLogService operateLogServiceImpl;
@Resource @Resource
private SysOperateLogMapper sysOperateLogMapper; private SysOperateLogMapper operateLogMapper;
@Resource
private SysUserMapper sysUserMapper;
@MockBean @MockBean
private SysUserService sysUserService; private SysUserService userService;
@Test @Test
public void testCreateOperateLogAsync() throws InterruptedException, ExecutionException { public void testCreateOperateLogAsync() throws InterruptedException, ExecutionException {
String traceId = TracerUtils.getTraceId(); String traceId = TracerUtils.getTraceId();
SysOperateLogCreateReqVO reqVO = RandomUtils.randomPojo(SysOperateLogCreateReqVO.class, vo -> { SysOperateLogCreateReqVO reqVO = RandomUtils.randomPojo(SysOperateLogCreateReqVO.class, o -> {
vo.setTraceId(traceId); o.setTraceId(traceId);
vo.setUserId(RandomUtil.randomLong(1, Long.MAX_VALUE)); o.setUserId(randomLongId());
o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build());
Map<String, Object> map = MapUtil.builder("orderId", (Object) 1).build();
vo.setExts(map);
}); });
// 执行service方法 // 执行service方法
Future<Boolean> future = sysOperateLogServiceImpl.createOperateLogAsync(reqVO); Future<Boolean> future = operateLogServiceImpl.createOperateLogAsync(reqVO);
// 等异步执行完
future.get(); future.get();
// 断言插入是否正确
// 查询插入的数据 SysOperateLogDO sysOperateLogDO = operateLogMapper.selectOne("trace_id", traceId);
SysOperateLogDO sysOperateLogDO = sysOperateLogMapper.selectOne("trace_id", traceId);
// 断言
assertNotNull(sysOperateLogDO);
// 断言,忽略基本字段
assertPojoEquals(reqVO, sysOperateLogDO); assertPojoEquals(reqVO, sysOperateLogDO);
} }
@Test @Test
public void testPageOperateLog() { public void testGetOperateLogPage() {
// 构造测试数据 // 构造测试数据
// 先构造用户 // 先构造用户
SysUserDO user = RandomUtils.randomPojo(SysUserDO.class, sysUserDO -> { SysUserDO user = RandomUtils.randomPojo(SysUserDO.class, o -> {
sysUserDO.setNickname("wangkai"); o.setNickname("wangkai");
sysUserDO.setSex(SysSexEnum.MALE.getSEX()); o.setSex(SysSexEnum.MALE.getSEX());
sysUserDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}); });
sysUserMapper.insert(user); when(userService.getUsersByNickname("wangkai")).thenReturn(Collections.singletonList(user));
Long userId = user.getId(); Long userId = user.getId();
// 构造操作日志 // 构造操作日志
SysOperateLogDO sysOperateLogDO = RandomUtils.randomPojo(SysOperateLogDO.class, entity -> { SysOperateLogDO sysOperateLogDO = RandomUtils.randomPojo(SysOperateLogDO.class, o -> {
entity.setTraceId(TracerUtils.getTraceId()); o.setUserId(userId);
entity.setUserId(userId); o.setModule("order");
entity.setModule("order"); o.setType(OperateTypeEnum.CREATE.getType());
entity.setType(OperateTypeEnum.CREATE.getType()); o.setStartTime(buildTime(2021, 3, 6));
entity.setStartTime(buildTime(2021, 3, 6)); o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode());
entity.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build());
Map<String, Object> map = new HashMap<>();
map.put("orderId", 1);
entity.setExts(map);
}); });
operateLogMapper.insert(sysOperateLogDO);
sysOperateLogMapper.insert(sysOperateLogDO);
// 下面几个是不匹配的数据 // 下面几个是不匹配的数据
// 随机userId // 随机 userId
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1)));
// module不同 // module 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setModule("user"))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setModule("user")));
// type不同 // type 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType()))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType())));
// createTime不同 // createTime 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6)))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6))));
// resultCode不同 // resultCode 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setResultCode(GlobalErrorCodeConstants.BAD_REQUEST.getCode()))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setResultCode(GlobalErrorCodeConstants.BAD_REQUEST.getCode())));
// 构造调用参数 // 构造调用参数
SysOperateLogPageReqVO reqVO = new SysOperateLogPageReqVO(); SysOperateLogPageReqVO reqVO = new SysOperateLogPageReqVO();
@ -138,8 +106,7 @@ public class SysOperateLogServiceImplTest extends BaseDbUnitTest {
reqVO.setSuccess(true); reqVO.setSuccess(true);
// 调用service方法 // 调用service方法
PageResult<SysOperateLogDO> pageResult = sysOperateLogServiceImpl.pageOperateLog(reqVO); PageResult<SysOperateLogDO> pageResult = operateLogServiceImpl.getOperateLogPage(reqVO);
// 断言,只查到了一条符合条件的 // 断言,只查到了一条符合条件的
assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size()); assertEquals(1, pageResult.getList().size());
@ -147,47 +114,38 @@ public class SysOperateLogServiceImplTest extends BaseDbUnitTest {
} }
@Test @Test
public void testListOperateLogs() { public void testGetOperateLogs() {
// 构造测试数据 // 构造测试数据
// 先构造用户 // 先构造用户
SysUserDO user = RandomUtils.randomPojo(SysUserDO.class, sysUserDO -> { SysUserDO user = RandomUtils.randomPojo(SysUserDO.class, o -> {
sysUserDO.setNickname("wangkai"); o.setNickname("wangkai");
sysUserDO.setSex(SysSexEnum.MALE.getSEX()); o.setSex(SysSexEnum.MALE.getSEX());
sysUserDO.setStatus(CommonStatusEnum.ENABLE.getStatus()); o.setStatus(CommonStatusEnum.ENABLE.getStatus());
}); });
sysUserMapper.insert(user); when(userService.getUsersByNickname("wangkai")).thenReturn(Collections.singletonList(user));
Long userId = user.getId(); Long userId = user.getId();
// 构造操作日志 // 构造操作日志
SysOperateLogDO sysOperateLogDO = RandomUtils.randomPojo(SysOperateLogDO.class, entity -> { SysOperateLogDO sysOperateLogDO = RandomUtils.randomPojo(SysOperateLogDO.class, o -> {
entity.setTraceId(TracerUtils.getTraceId()); o.setUserId(userId);
entity.setUserId(userId); o.setModule("order");
entity.setModule("order"); o.setType(OperateTypeEnum.CREATE.getType());
entity.setType(OperateTypeEnum.CREATE.getType()); o.setStartTime(buildTime(2021, 3, 6));
entity.setStartTime(buildTime(2021, 3, 6)); o.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode());
entity.setResultCode(GlobalErrorCodeConstants.SUCCESS.getCode()); o.setExts(MapUtil.<String, Object>builder("orderId", randomLongId()).build());
Map<String, Object> map = MapUtil.builder("orderId", (Object) 1).build();
entity.setExts(map);
}); });
operateLogMapper.insert(sysOperateLogDO);
sysOperateLogMapper.insert(sysOperateLogDO);
// 下面几个是不匹配的数据 // 下面几个是不匹配的数据
// 随机userId // 随机 userId
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setUserId(userId + 1)));
// module不同 // module 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setModule("user"))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setModule("user")));
// type不同 // type 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType()))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setType(OperateTypeEnum.IMPORT.getType())));
// createTime不同 // createTime 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6)))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setStartTime(buildTime(2021, 2, 6))));
// resultCode不同 // resultCode 不同
sysOperateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setResultCode(GlobalErrorCodeConstants.BAD_REQUEST.getCode()))); operateLogMapper.insert(ObjectUtils.clone(sysOperateLogDO, logDO -> logDO.setResultCode(GlobalErrorCodeConstants.BAD_REQUEST.getCode())));
// 构造调用参数 // 构造调用参数
SysOperateLogExportReqVO reqVO = new SysOperateLogExportReqVO(); SysOperateLogExportReqVO reqVO = new SysOperateLogExportReqVO();
@ -198,11 +156,11 @@ public class SysOperateLogServiceImplTest extends BaseDbUnitTest {
reqVO.setEndTime(buildTime(2021, 3, 7)); reqVO.setEndTime(buildTime(2021, 3, 7));
reqVO.setSuccess(true); reqVO.setSuccess(true);
// 调用service方法 // 调用 service 方法
List<SysOperateLogDO> list = sysOperateLogServiceImpl.listOperateLogs(reqVO); List<SysOperateLogDO> list = operateLogServiceImpl.getOperateLogs(reqVO);
// 断言,只查到了一条符合条件的 // 断言,只查到了一条符合条件的
assertEquals(1, list.size()); assertEquals(1, list.size());
assertPojoEquals(sysOperateLogDO, list.get(0)); assertPojoEquals(sysOperateLogDO, list.get(0));
} }
} }

View File

@ -3,6 +3,8 @@ DELETE FROM "inf_config";
DELETE FROM "inf_file"; DELETE FROM "inf_file";
DELETE FROM "inf_job"; DELETE FROM "inf_job";
DELETE FROM "inf_job_log"; DELETE FROM "inf_job_log";
DELETE FROM "inf_api_access_log";
DELETE FROM "inf_api_error_log";
-- sys 开头的 DB -- sys 开头的 DB
DELETE FROM "sys_dept"; DELETE FROM "sys_dept";

View File

@ -269,7 +269,7 @@ CREATE TABLE IF NOT EXISTS `sys_operate_log` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) COMMENT ='操作日志记录'; ) COMMENT ='操作日志记录';
create table IF NOT EXISTS "sys_user" ( CREATE TABLE IF NOT EXISTS "sys_user" (
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY, "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
"username" varchar(30) not null, "username" varchar(30) not null,
"password" varchar(100) not null default '', "password" varchar(100) not null default '',
@ -292,8 +292,7 @@ create table IF NOT EXISTS "sys_user" (
primary key ("id") primary key ("id")
) comment '用户信息表'; ) comment '用户信息表';
CREATE TABLE IF NOT EXISTS "inf_api_access_log" (
create table "inf_api_access_log" (
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY, "id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
"trace_id" varchar(64) not null default '', "trace_id" varchar(64) not null default '',
"user_id" bigint not null default '0', "user_id" bigint not null default '0',
@ -315,10 +314,9 @@ create table "inf_api_access_log" (
"update_time" timestamp not null default current_timestamp, "update_time" timestamp not null default current_timestamp,
"deleted" bit not null default false, "deleted" bit not null default false,
primary key ("id") primary key ("id")
) comment 'API 访问日志表'; ) COMMENT 'API 访问日志表';
CREATE TABLE IF NOT EXISTS "inf_api_error_log" (
create table "inf_api_error_log" (
"id" integer not null GENERATED BY DEFAULT AS IDENTITY, "id" integer not null GENERATED BY DEFAULT AS IDENTITY,
"trace_id" varchar(64) not null, "trace_id" varchar(64) not null,
"user_id" bigint not null default '0', "user_id" bigint not null default '0',
@ -347,4 +345,4 @@ create table "inf_api_error_log" (
"update_time" timestamp not null default current_timestamp, "update_time" timestamp not null default current_timestamp,
"deleted" bit not null default false, "deleted" bit not null default false,
primary key ("id") primary key ("id")
) comment '系统异常日志'; ) COMMENT '系统异常日志';