Commit 52010d5535bc62e09a487eb1fedc8f7cfbbc62c8

Authored by YunaiV
1 parent 4b90792b

完善单元测试

yudao-module-infra/yudao-module-infra-biz/src/test/resources/sql/create_tables.sql
1 1
2 CREATE TABLE IF NOT EXISTS "infra_config" ( 2 CREATE TABLE IF NOT EXISTS "infra_config" (
3 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, 3 "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY,
4 - "group" varchar(50) NOT NULL, 4 + "category" varchar(50) NOT NULL,
5 "type" tinyint NOT NULL, 5 "type" tinyint NOT NULL,
6 "name" varchar(100) NOT NULL DEFAULT '', 6 "name" varchar(100) NOT NULL DEFAULT '',
7 - "key" varchar(100) NOT NULL DEFAULT '', 7 + "config_key" varchar(100) NOT NULL DEFAULT '',
8 "value" varchar(500) NOT NULL DEFAULT '', 8 "value" varchar(500) NOT NULL DEFAULT '',
9 - "sensitive" bit NOT NULL, 9 + "visible" bit NOT NULL,
10 "remark" varchar(500) DEFAULT NULL, 10 "remark" varchar(500) DEFAULT NULL,
11 "creator" varchar(64) DEFAULT '', 11 "creator" varchar(64) DEFAULT '',
12 "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 12 "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogMapper.java
@@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.logger; @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.dal.mysql.logger;
3 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; 3 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; 6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7 import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO; 7 import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogExportReqVO;
8 import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO; 8 import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
9 import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
@@ -16,32 +16,32 @@ import java.util.List; @@ -16,32 +16,32 @@ import java.util.List;
16 public interface OperateLogMapper extends BaseMapperX<OperateLogDO> { 16 public interface OperateLogMapper extends BaseMapperX<OperateLogDO> {
17 17
18 default PageResult<OperateLogDO> selectPage(OperateLogPageReqVO reqVO, Collection<Long> userIds) { 18 default PageResult<OperateLogDO> selectPage(OperateLogPageReqVO reqVO, Collection<Long> userIds) {
19 - QueryWrapperX<OperateLogDO> query = new QueryWrapperX<OperateLogDO>()  
20 - .likeIfPresent("module", reqVO.getModule())  
21 - .inIfPresent("user_id", userIds)  
22 - .eqIfPresent("operate_type", reqVO.getType())  
23 - .betweenIfPresent("start_time", reqVO.getBeginTime(), reqVO.getEndTime()); 19 + LambdaQueryWrapperX<OperateLogDO> query = new LambdaQueryWrapperX<OperateLogDO>()
  20 + .likeIfPresent(OperateLogDO::getModule, reqVO.getModule())
  21 + .inIfPresent(OperateLogDO::getUserId, userIds)
  22 + .eqIfPresent(OperateLogDO::getType, reqVO.getType())
  23 + .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getBeginTime(), reqVO.getEndTime());
24 if (Boolean.TRUE.equals(reqVO.getSuccess())) { 24 if (Boolean.TRUE.equals(reqVO.getSuccess())) {
25 - query.eq("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); 25 + query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
26 } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { 26 } else if (Boolean.FALSE.equals(reqVO.getSuccess())) {
27 - query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); 27 + query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
28 } 28 }
29 - query.orderByDesc("id"); // 降序 29 + query.orderByDesc(OperateLogDO::getId); // 降序
30 return selectPage(reqVO, query); 30 return selectPage(reqVO, query);
31 } 31 }
32 32
33 default List<OperateLogDO> selectList(OperateLogExportReqVO reqVO, Collection<Long> userIds) { 33 default List<OperateLogDO> selectList(OperateLogExportReqVO reqVO, Collection<Long> userIds) {
34 - QueryWrapperX<OperateLogDO> query = new QueryWrapperX<OperateLogDO>()  
35 - .likeIfPresent("module", reqVO.getModule())  
36 - .inIfPresent("user_id", userIds)  
37 - .eqIfPresent("operate_type", reqVO.getType())  
38 - .betweenIfPresent("start_time", reqVO.getBeginTime(), reqVO.getEndTime()); 34 + LambdaQueryWrapperX<OperateLogDO> query = new LambdaQueryWrapperX<OperateLogDO>()
  35 + .likeIfPresent(OperateLogDO::getModule, reqVO.getModule())
  36 + .inIfPresent(OperateLogDO::getUserId, userIds)
  37 + .eqIfPresent(OperateLogDO::getType, reqVO.getType())
  38 + .betweenIfPresent(OperateLogDO::getStartTime, reqVO.getBeginTime(), reqVO.getEndTime());
39 if (Boolean.TRUE.equals(reqVO.getSuccess())) { 39 if (Boolean.TRUE.equals(reqVO.getSuccess())) {
40 - query.eq("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); 40 + query.eq(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
41 } else if (Boolean.FALSE.equals(reqVO.getSuccess())) { 41 } else if (Boolean.FALSE.equals(reqVO.getSuccess())) {
42 - query.gt("result_code", GlobalErrorCodeConstants.SUCCESS.getCode()); 42 + query.gt(OperateLogDO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
43 } 43 }
44 - query.orderByDesc("id"); // 降序 44 + query.orderByDesc(OperateLogDO::getId); // 降序
45 return selectList(query); 45 return selectList(query);
46 } 46 }
47 47
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AuthServiceImplTest.java
1 package cn.iocoder.yudao.module.system.service.auth; 1 package cn.iocoder.yudao.module.system.service.auth;
2 2
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.security.core.LoginUser;
  5 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  6 +import cn.iocoder.yudao.framework.test.core.util.AssertUtils;
  7 +import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
3 import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; 8 import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO;
4 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; 9 import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
5 import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; 10 import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
@@ -8,12 +13,8 @@ import cn.iocoder.yudao.module.system.service.common.CaptchaService; @@ -8,12 +13,8 @@ import cn.iocoder.yudao.module.system.service.common.CaptchaService;
8 import cn.iocoder.yudao.module.system.service.dept.PostService; 13 import cn.iocoder.yudao.module.system.service.dept.PostService;
9 import cn.iocoder.yudao.module.system.service.logger.LoginLogService; 14 import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
10 import cn.iocoder.yudao.module.system.service.permission.PermissionService; 15 import cn.iocoder.yudao.module.system.service.permission.PermissionService;
11 -import cn.iocoder.yudao.module.system.service.user.AdminUserService;  
12 import cn.iocoder.yudao.module.system.service.social.SocialUserService; 16 import cn.iocoder.yudao.module.system.service.social.SocialUserService;
13 -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;  
14 -import cn.iocoder.yudao.framework.security.core.LoginUser;  
15 -import cn.iocoder.yudao.framework.test.core.util.AssertUtils;  
16 -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; 17 +import cn.iocoder.yudao.module.system.service.user.AdminUserService;
17 import org.junit.jupiter.api.BeforeEach; 18 import org.junit.jupiter.api.BeforeEach;
18 import org.junit.jupiter.api.Test; 19 import org.junit.jupiter.api.Test;
19 import org.springframework.boot.test.mock.mockito.MockBean; 20 import org.springframework.boot.test.mock.mockito.MockBean;
@@ -30,11 +31,12 @@ import javax.annotation.Resource; @@ -30,11 +31,12 @@ import javax.annotation.Resource;
30 import javax.validation.Validator; 31 import javax.validation.Validator;
31 import java.util.Set; 32 import java.util.Set;
32 33
33 -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;  
34 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; 34 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
35 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; 35 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  36 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
36 import static java.util.Collections.singleton; 37 import static java.util.Collections.singleton;
37 -import static org.junit.jupiter.api.Assertions.*; 38 +import static org.junit.jupiter.api.Assertions.assertEquals;
  39 +import static org.junit.jupiter.api.Assertions.assertThrows;
38 import static org.mockito.ArgumentMatchers.eq; 40 import static org.mockito.ArgumentMatchers.eq;
39 import static org.mockito.Mockito.*; 41 import static org.mockito.Mockito.*;
40 42
@@ -62,6 +64,8 @@ public class AuthServiceImplTest extends BaseDbUnitTest { @@ -62,6 +64,8 @@ public class AuthServiceImplTest extends BaseDbUnitTest {
62 private SocialUserService socialService; 64 private SocialUserService socialService;
63 @MockBean 65 @MockBean
64 private PostService postService; 66 private PostService postService;
  67 + @MockBean
  68 + private SmsCodeApi smsCodeApi;
65 69
66 @MockBean 70 @MockBean
67 private Validator validator; 71 private Validator validator;
yudao-module-system/yudao-module-system-biz/src/test/resources/sql/create_tables.sql
@@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS &quot;system_menu&quot; ( @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS &quot;system_menu&quot; (
70 "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, 70 "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
71 "name" varchar(50) NOT NULL, 71 "name" varchar(50) NOT NULL,
72 "permission" varchar(100) NOT NULL DEFAULT '', 72 "permission" varchar(100) NOT NULL DEFAULT '',
73 - "menu_type" tinyint NOT NULL, 73 + "type" tinyint NOT NULL,
74 "sort" int NOT NULL DEFAULT '0', 74 "sort" int NOT NULL DEFAULT '0',
75 "parent_id" bigint NOT NULL DEFAULT '0', 75 "parent_id" bigint NOT NULL DEFAULT '0',
76 "path" varchar(200) DEFAULT '', 76 "path" varchar(200) DEFAULT '',
@@ -202,7 +202,7 @@ CREATE TABLE IF NOT EXISTS `system_operate_log` ( @@ -202,7 +202,7 @@ CREATE TABLE IF NOT EXISTS `system_operate_log` (
202 "user_type" tinyint not null default '0', 202 "user_type" tinyint not null default '0',
203 `module` varchar(50) NOT NULL, 203 `module` varchar(50) NOT NULL,
204 `name` varchar(50) NOT NULL, 204 `name` varchar(50) NOT NULL,
205 - `operate_type` bigint(4) NOT NULL DEFAULT '0', 205 + `type` bigint(4) NOT NULL DEFAULT '0',
206 `content` varchar(2000) NOT NULL DEFAULT '', 206 `content` varchar(2000) NOT NULL DEFAULT '',
207 `exts` varchar(512) NOT NULL DEFAULT '', 207 `exts` varchar(512) NOT NULL DEFAULT '',
208 `request_method` varchar(16) DEFAULT '', 208 `request_method` varchar(16) DEFAULT '',