1. 修复所有的单元测试

2. 最新的 sql 脚本
This commit is contained in:
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("查看操作日志分页列表")
@PreAuthorize("@ss.hasPermission('system:operate-log:query')")
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);
@ -71,7 +71,7 @@ public class SysOperateLogController {
@PreAuthorize("@ss.hasPermission('system:operate-log:export')")
@OperateLog(type = EXPORT)
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);

View File

@ -19,7 +19,7 @@ public interface SysOperateLogService extends OperateLogFrameworkService {
* @param reqVO 分页条件
* @return 操作日志分页列表
*/
PageResult<SysOperateLogDO> pageOperateLog(SysOperateLogPageReqVO reqVO);
PageResult<SysOperateLogDO> getOperateLogPage(SysOperateLogPageReqVO reqVO);
/**
* 获得操作日志列表
@ -27,6 +27,6 @@ public interface SysOperateLogService extends OperateLogFrameworkService {
* @param reqVO 列表条件
* @return 日志列表
*/
List<SysOperateLogDO> listOperateLogs(SysOperateLogExportReqVO reqVO);
List<SysOperateLogDO> getOperateLogs(SysOperateLogExportReqVO reqVO);
}

View File

@ -55,7 +55,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
}
@Override
public PageResult<SysOperateLogDO> pageOperateLog(SysOperateLogPageReqVO reqVO) {
public PageResult<SysOperateLogDO> getOperateLogPage(SysOperateLogPageReqVO reqVO) {
// 处理基于用户昵称的查询
Collection<Long> userIds = null;
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
@ -69,7 +69,7 @@ public class SysOperateLogServiceImpl implements SysOperateLogService {
}
@Override
public List<SysOperateLogDO> listOperateLogs(SysOperateLogExportReqVO reqVO) {
public List<SysOperateLogDO> getOperateLogs(SysOperateLogExportReqVO reqVO) {
// 处理基于用户昵称的查询
Collection<Long> userIds = null;
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.iocoder.dashboard.BaseDbUnitTest;
import cn.iocoder.dashboard.framework.quartz.core.scheduler.SchedulerManager;
import cn.iocoder.dashboard.modules.system.job.auth.SysUserSessionTimeoutJob;
import org.junit.jupiter.api.Test;
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.message.mail.SysMailSendMessage;
import cn.iocoder.dashboard.modules.system.mq.message.sms.SysSmsSendMessage;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.core.RedisTemplate;
@ -18,6 +19,7 @@ import java.util.concurrent.TimeUnit;
public class RedisStreamTest {
@Import({SysSmsSendConsumer.class, SysMailSendConsumer.class})
@Disabled
public static class ConsumerTest extends BaseRedisIntegrationTest {
@Test
@ -27,6 +29,7 @@ public class RedisStreamTest {
}
@Disabled
public static class ProducerTest extends BaseRedisIntegrationTest {
@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.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
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.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.service.codegen.impl.ToolCodegenEngine;
import org.junit.jupiter.api.Test;
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.modules.tool.service.codegen.impl.ToolCodegenSQLParser;
import org.junit.jupiter.api.Test;
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.modules.tool.service.codegen.impl.ToolCodegenServiceImpl;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -269,7 +269,7 @@ CREATE TABLE IF NOT EXISTS `sys_operate_log` (
PRIMARY KEY (`id`)
) COMMENT ='操作日志记录';
create table IF NOT EXISTS "sys_user" (
CREATE TABLE IF NOT EXISTS "sys_user" (
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
"username" varchar(30) not null,
"password" varchar(100) not null default '',
@ -292,8 +292,7 @@ create table IF NOT EXISTS "sys_user" (
primary key ("id")
) comment '用户信息表';
create table "inf_api_access_log" (
CREATE TABLE IF NOT EXISTS "inf_api_access_log" (
"id" bigint not null GENERATED BY DEFAULT AS IDENTITY,
"trace_id" varchar(64) not null default '',
"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,
"deleted" bit not null default false,
primary key ("id")
) comment 'API 访问日志表';
) COMMENT 'API 访问日志表';
create table "inf_api_error_log" (
CREATE TABLE IF NOT EXISTS "inf_api_error_log" (
"id" integer not null GENERATED BY DEFAULT AS IDENTITY,
"trace_id" varchar(64) not null,
"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,
"deleted" bit not null default false,
primary key ("id")
) comment '系统异常日志';
) COMMENT '系统异常日志';