完善单元测试

pull/2/head
YunaiV 2022-05-05 19:29:53 +08:00
parent 4b90792bf1
commit 52010d5535
4 changed files with 33 additions and 29 deletions

View File

@ -1,12 +1,12 @@
CREATE TABLE IF NOT EXISTS "infra_config" ( CREATE TABLE IF NOT EXISTS "infra_config" (
"id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"group" varchar(50) NOT NULL, "category" varchar(50) NOT NULL,
"type" tinyint NOT NULL, "type" tinyint NOT NULL,
"name" varchar(100) NOT NULL DEFAULT '', "name" varchar(100) NOT NULL DEFAULT '',
"key" varchar(100) NOT NULL DEFAULT '', "config_key" varchar(100) NOT NULL DEFAULT '',
"value" varchar(500) NOT NULL DEFAULT '', "value" varchar(500) NOT NULL DEFAULT '',
"sensitive" bit NOT NULL, "visible" bit NOT NULL,
"remark" varchar(500) DEFAULT NULL, "remark" varchar(500) DEFAULT NULL,
"creator" varchar(64) DEFAULT '', "creator" varchar(64) DEFAULT '',
"create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.logger;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
@ -16,32 +16,32 @@ import java.util.List;
public interface OperateLogMapper extends BaseMapperX<OperateLogDO> { public interface OperateLogMapper extends BaseMapperX<OperateLogDO> {
default PageResult<OperateLogDO> selectPage(OperateLogPageReqVO reqVO, Collection<Long> userIds) { default PageResult<OperateLogDO> selectPage(OperateLogPageReqVO reqVO, Collection<Long> userIds) {
QueryWrapperX<OperateLogDO> query = new QueryWrapperX<OperateLogDO>() LambdaQueryWrapperX<OperateLogDO> query = new LambdaQueryWrapperX<OperateLogDO>()
.likeIfPresent("module", reqVO.getModule()) .likeIfPresent(OperateLogDO::getModule, reqVO.getModule())
.inIfPresent("user_id", userIds) .inIfPresent(OperateLogDO::getUserId, userIds)
.eqIfPresent("operate_type", reqVO.getType()) .eqIfPresent(OperateLogDO::getType, reqVO.getType())
.betweenIfPresent("start_time", reqVO.getBeginTime(), reqVO.getEndTime()); .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getBeginTime(), reqVO.getEndTime());
if (Boolean.TRUE.equals(reqVO.getSuccess())) { if (Boolean.TRUE.equals(reqVO.getSuccess())) {
query.eq("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
} else if (Boolean.FALSE.equals(reqVO.getSuccess())) { } else if (Boolean.FALSE.equals(reqVO.getSuccess())) {
query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
} }
query.orderByDesc("id"); // 降序 query.orderByDesc(OperateLogDO::getId); // 降序
return selectPage(reqVO, query); return selectPage(reqVO, query);
} }
default List<OperateLogDO> selectList(OperateLogExportReqVO reqVO, Collection<Long> userIds) { default List<OperateLogDO> selectList(OperateLogExportReqVO reqVO, Collection<Long> userIds) {
QueryWrapperX<OperateLogDO> query = new QueryWrapperX<OperateLogDO>() LambdaQueryWrapperX<OperateLogDO> query = new LambdaQueryWrapperX<OperateLogDO>()
.likeIfPresent("module", reqVO.getModule()) .likeIfPresent(OperateLogDO::getModule, reqVO.getModule())
.inIfPresent("user_id", userIds) .inIfPresent(OperateLogDO::getUserId, userIds)
.eqIfPresent("operate_type", reqVO.getType()) .eqIfPresent(OperateLogDO::getType, reqVO.getType())
.betweenIfPresent("start_time", reqVO.getBeginTime(), reqVO.getEndTime()); .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getBeginTime(), reqVO.getEndTime());
if (Boolean.TRUE.equals(reqVO.getSuccess())) { if (Boolean.TRUE.equals(reqVO.getSuccess())) {
query.eq("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
} else if (Boolean.FALSE.equals(reqVO.getSuccess())) { } else if (Boolean.FALSE.equals(reqVO.getSuccess())) {
query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
} }
query.orderByDesc("id"); // 降序 query.orderByDesc(OperateLogDO::getId); // 降序
return selectList(query); return selectList(query);
} }

View File

@ -1,5 +1,10 @@
package cn.iocoder.yudao.module.system.service.auth; package cn.iocoder.yudao.module.system.service.auth;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.framework.test.core.util.AssertUtils;
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
@ -8,12 +13,8 @@ import cn.iocoder.yudao.module.system.service.common.CaptchaService;
import cn.iocoder.yudao.module.system.service.dept.PostService; import cn.iocoder.yudao.module.system.service.dept.PostService;
import cn.iocoder.yudao.module.system.service.logger.LoginLogService; import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.module.system.service.social.SocialUserService; import cn.iocoder.yudao.module.system.service.social.SocialUserService;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.test.core.util.AssertUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
@ -30,11 +31,12 @@ import javax.annotation.Resource;
import javax.validation.Validator; import javax.validation.Validator;
import java.util.Set; import java.util.Set;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
import static java.util.Collections.singleton; import static java.util.Collections.singleton;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ -62,6 +64,8 @@ public class AuthServiceImplTest extends BaseDbUnitTest {
private SocialUserService socialService; private SocialUserService socialService;
@MockBean @MockBean
private PostService postService; private PostService postService;
@MockBean
private SmsCodeApi smsCodeApi;
@MockBean @MockBean
private Validator validator; private Validator validator;

View File

@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS "system_menu" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar(50) NOT NULL, "name" varchar(50) NOT NULL,
"permission" varchar(100) NOT NULL DEFAULT '', "permission" varchar(100) NOT NULL DEFAULT '',
"menu_type" tinyint NOT NULL, "type" tinyint NOT NULL,
"sort" int NOT NULL DEFAULT '0', "sort" int NOT NULL DEFAULT '0',
"parent_id" bigint NOT NULL DEFAULT '0', "parent_id" bigint NOT NULL DEFAULT '0',
"path" varchar(200) DEFAULT '', "path" varchar(200) DEFAULT '',
@ -202,7 +202,7 @@ CREATE TABLE IF NOT EXISTS `system_operate_log` (
"user_type" tinyint not null default '0', "user_type" tinyint not null default '0',
`module` varchar(50) NOT NULL, `module` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL, `name` varchar(50) NOT NULL,
`operate_type` bigint(4) NOT NULL DEFAULT '0', `type` bigint(4) NOT NULL DEFAULT '0',
`content` varchar(2000) NOT NULL DEFAULT '', `content` varchar(2000) NOT NULL DEFAULT '',
`exts` varchar(512) NOT NULL DEFAULT '', `exts` varchar(512) NOT NULL DEFAULT '',
`request_method` varchar(16) DEFAULT '', `request_method` varchar(16) DEFAULT '',