Commit a7509f6184bc32908a97ab9c39ebc144cf8a750a

Authored by niudehua
2 parents b5f70811 816808f8

Merge remote-tracking branch 'origin/master' into unit_system_dept

src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenEngine.java
@@ -53,9 +53,7 @@ public class ToolCodegenEngine { @@ -53,9 +53,7 @@ public class ToolCodegenEngine {
53 * value:生成的路径 53 * value:生成的路径
54 */ 54 */
55 private static final Map<String, String> TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序 55 private static final Map<String, String> TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序
56 - // Java  
57 - .put(javaTemplatePath("controller/controller"),  
58 - javaFilePath("controller/${table.businessName}/${table.className}Controller")) 56 + // Java Main
59 .put(javaTemplatePath("controller/vo/baseVO"), 57 .put(javaTemplatePath("controller/vo/baseVO"),
60 javaFilePath("controller/${table.businessName}/vo/${table.className}BaseVO")) 58 javaFilePath("controller/${table.businessName}/vo/${table.className}BaseVO"))
61 .put(javaTemplatePath("controller/vo/createReqVO"), 59 .put(javaTemplatePath("controller/vo/createReqVO"),
@@ -70,6 +68,8 @@ public class ToolCodegenEngine { @@ -70,6 +68,8 @@ public class ToolCodegenEngine {
70 javaFilePath("controller/${table.businessName}/vo/${table.className}ExportReqVO")) 68 javaFilePath("controller/${table.businessName}/vo/${table.className}ExportReqVO"))
71 .put(javaTemplatePath("controller/vo/excelVO"), 69 .put(javaTemplatePath("controller/vo/excelVO"),
72 javaFilePath("controller/${table.businessName}/vo/${table.className}ExcelVO")) 70 javaFilePath("controller/${table.businessName}/vo/${table.className}ExcelVO"))
  71 + .put(javaTemplatePath("controller/controller"),
  72 + javaFilePath("controller/${table.businessName}/${table.className}Controller"))
73 .put(javaTemplatePath("convert/convert"), 73 .put(javaTemplatePath("convert/convert"),
74 javaFilePath("convert/${table.businessName}/${table.className}Convert")) 74 javaFilePath("convert/${table.businessName}/${table.className}Convert"))
75 .put(javaTemplatePath("dal/do"), 75 .put(javaTemplatePath("dal/do"),
@@ -78,10 +78,13 @@ public class ToolCodegenEngine { @@ -78,10 +78,13 @@ public class ToolCodegenEngine {
78 javaFilePath("dal/mysql/${table.businessName}/${table.className}Mapper")) 78 javaFilePath("dal/mysql/${table.businessName}/${table.className}Mapper"))
79 .put(javaTemplatePath("enums/errorcode"), 79 .put(javaTemplatePath("enums/errorcode"),
80 javaFilePath("enums/${simpleModuleName_upperFirst}ErrorCodeConstants")) 80 javaFilePath("enums/${simpleModuleName_upperFirst}ErrorCodeConstants"))
81 - .put(javaTemplatePath("service/service"),  
82 - javaFilePath("service/${table.businessName}/${table.className}Service"))  
83 .put(javaTemplatePath("service/serviceImpl"), 81 .put(javaTemplatePath("service/serviceImpl"),
84 javaFilePath("service/${table.businessName}/impl/${table.className}ServiceImpl")) 82 javaFilePath("service/${table.businessName}/impl/${table.className}ServiceImpl"))
  83 + .put(javaTemplatePath("service/service"),
  84 + javaFilePath("service/${table.businessName}/${table.className}Service"))
  85 + // Java Test
  86 + .put(javaTemplatePath("test/serviceTest"),
  87 + javaFilePath("service/${table.businessName}/${table.className}ServiceTest"))
85 // Vue 88 // Vue
86 .put(vueTemplatePath("views/index.vue"), 89 .put(vueTemplatePath("views/index.vue"),
87 vueFilePath("views/${table.moduleName}/${classNameVar}/index.vue")) 90 vueFilePath("views/${table.moduleName}/${classNameVar}/index.vue"))
src/main/resources/application-dev.yaml
@@ -154,7 +154,7 @@ yudao: @@ -154,7 +154,7 @@ yudao:
154 file: 154 file:
155 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ 155 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
156 codegen: 156 codegen:
157 - base-package: ${yudao.info.base-package}.modules 157 + base-package: ${yudao.info.base-package}
158 db-schemas: ${spring.datasource.name} 158 db-schemas: ${spring.datasource.name}
159 xss: 159 xss:
160 enable: false 160 enable: false
src/main/resources/application-local.yaml
@@ -154,7 +154,7 @@ yudao: @@ -154,7 +154,7 @@ yudao:
154 file: 154 file:
155 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ 155 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
156 codegen: 156 codegen:
157 - base-package: ${yudao.info.base-package}.modules 157 + base-package: ${yudao.info.base-package}
158 db-schemas: ${spring.datasource.name} 158 db-schemas: ${spring.datasource.name}
159 xss: 159 xss:
160 enable: false 160 enable: false
src/main/resources/codegen/java/controller/controller.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName};
2 2
3 import org.springframework.web.bind.annotation.*; 3 import org.springframework.web.bind.annotation.*;
4 import javax.annotation.Resource; 4 import javax.annotation.Resource;
@@ -22,10 +22,10 @@ import ${ExcelUtilsClassName}; @@ -22,10 +22,10 @@ import ${ExcelUtilsClassName};
22 import ${OperateLogClassName}; 22 import ${OperateLogClassName};
23 import static ${OperateTypeEnumClassName}.*; 23 import static ${OperateTypeEnumClassName}.*;
24 24
25 -import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;  
26 -import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;  
27 -import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;  
28 -import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service; 25 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  26 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
  27 +import ${basePackage}.modules.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
  28 +import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service;
29 29
30 @Api(tags = "${table.classComment}") 30 @Api(tags = "${table.classComment}")
31 @RestController 31 @RestController
src/main/resources/codegen/java/controller/vo/baseVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/createReqVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/excelVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/exportReqVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/pageReqVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/respVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/controller/vo/updateReqVO.vm
1 -package ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo; 1 +package ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo;
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/convert/convert.vm
1 -package ${basePackage}.${table.moduleName}.convert.${table.businessName}; 1 +package ${basePackage}.modules.${table.moduleName}.convert.${table.businessName};
2 2
3 import java.util.*; 3 import java.util.*;
4 4
@@ -6,8 +6,8 @@ import ${PageResultClassName}; @@ -6,8 +6,8 @@ import ${PageResultClassName};
6 6
7 import org.mapstruct.Mapper; 7 import org.mapstruct.Mapper;
8 import org.mapstruct.factory.Mappers; 8 import org.mapstruct.factory.Mappers;
9 -import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;  
10 -import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; 9 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  10 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
11 11
12 /** 12 /**
13 * ${table.classComment} Convert 13 * ${table.classComment} Convert
src/main/resources/codegen/java/dal/do.vm
1 -package ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}; 1 +package ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName};
2 2
3 import lombok.*; 3 import lombok.*;
4 import java.util.*; 4 import java.util.*;
src/main/resources/codegen/java/dal/mapper.vm
1 -package ${basePackage}.${table.moduleName}.dal.mysql.${table.businessName}; 1 +package ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName};
2 2
3 import java.util.*; 3 import java.util.*;
4 4
5 import ${PageResultClassName}; 5 import ${PageResultClassName};
6 import ${QueryWrapperClassName}; 6 import ${QueryWrapperClassName};
7 import ${BaseMapperClassName}; 7 import ${BaseMapperClassName};
8 -import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; 8 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
10 -import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; 10 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
11 11
12 ## 字段模板 12 ## 字段模板
13 #macro(listCondition) 13 #macro(listCondition)
src/main/resources/codegen/java/service/service.vm
1 -package ${basePackage}.${table.moduleName}.service.${table.businessName}; 1 +package ${basePackage}.modules.${table.moduleName}.service.${table.businessName};
2 2
3 import java.util.*; 3 import java.util.*;
4 import javax.validation.*; 4 import javax.validation.*;
5 -import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;  
6 -import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; 5 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  6 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
7 import ${PageResultClassName}; 7 import ${PageResultClassName};
8 8
9 /** 9 /**
src/main/resources/codegen/java/service/serviceImpl.vm
1 -package ${basePackage}.${table.moduleName}.service.${table.businessName}.impl; 1 +package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl;
2 2
3 import org.springframework.beans.factory.annotation.Autowired; 3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Service; 4 import org.springframework.stereotype.Service;
@@ -6,17 +6,17 @@ import javax.annotation.Resource; @@ -6,17 +6,17 @@ import javax.annotation.Resource;
6 import org.springframework.validation.annotation.Validated; 6 import org.springframework.validation.annotation.Validated;
7 7
8 import java.util.*; 8 import java.util.*;
9 -import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;  
10 -import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; 9 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  10 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
11 import ${PageResultClassName}; 11 import ${PageResultClassName};
12 12
13 -import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;  
14 -import ${basePackage}.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;  
15 -import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service; 13 +import ${basePackage}.modules.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
  14 +import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
  15 +import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service;
16 16
17 import ${ServiceExceptionUtilClassName}; 17 import ${ServiceExceptionUtilClassName};
18 18
19 -import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*; 19 +import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*;
20 20
21 /** 21 /**
22 * ${table.classComment} Service 实现类 22 * ${table.classComment} Service 实现类
src/main/resources/codegen/java/test/serviceTest.vm 0 → 100644
  1 +package ${basePackage}.modules.${table.moduleName}.service.${table.businessName};
  2 +
  3 +import ${basePackage}.BaseSpringBootUnitTest;
  4 +
  5 +import org.junit.jupiter.api.Test;
  6 +import org.springframework.boot.test.mock.mockito.MockBean;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +import cn.iocoder.dashboard.BaseSpringBootUnitTest;
  11 +import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl.${table.className}ServiceImpl;
  12 +import ${basePackage}.modules.${table.moduleName}.controller.${table.businessName}.vo.*;
  13 +import ${basePackage}.modules.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
  14 +import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
  15 +import ${basePackage}.util.object.ObjectUtils;
  16 +import ${PageResultClassName};
  17 +
  18 +import javax.annotation.Resource;
  19 +import java.util.*;
  20 +
  21 +import static cn.hutool.core.util.RandomUtil.*;
  22 +import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*;
  23 +import static ${basePackage}.util.AssertUtils.*;
  24 +import static ${basePackage}.util.RandomUtils.*;
  25 +import static ${basePackage}.util.date.DateUtils.*;
  26 +import static org.junit.jupiter.api.Assertions.*;
  27 +import static org.mockito.Mockito.*;
  28 +
  29 +## 字段模板
  30 +#macro(getPageCondition $VO)
  31 + // mock 数据
  32 + ${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class, o -> {); // 等会查询到
  33 + #foreach ($column in $columns)
  34 + #if (${column.listOperation})
  35 + #set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
  36 + o.set$JavaField(null);
  37 + #end
  38 + #end
  39 + });
  40 + ${classNameVar}Mapper.insert(db${simpleClassName});
  41 + #foreach ($column in $columns)
  42 + #if (${column.listOperation})
  43 + #set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
  44 + // 测试 ${column.javaField} 不匹配
  45 + ${classNameVar}Mapper.insert(ObjectUtils.clone(db${simpleClassName}, o -> o.set$JavaField(null)));
  46 + #end
  47 + #end
  48 + // 准备参数
  49 + ${table.className}${VO} reqVO = new ${table.className}${VO}();
  50 + #foreach ($column in $columns)
  51 + #if (${column.listOperation})
  52 + #set ($JavaField = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})##首字母大写
  53 + #if (${column.listOperationCondition} == "BETWEEN")## BETWEEN 的情况
  54 + reqVO.setBegin${JavaField}(null);
  55 + reqVO.setEnd${JavaField}(null);
  56 + #else
  57 + reqVO.set$JavaField(null);
  58 + #end
  59 + #end
  60 + #end
  61 +#end
  62 +/**
  63 +* {@link ${table.className}ServiceImpl} 的单元测试类
  64 +*
  65 +* @author ${table.author}
  66 +*/
  67 +public class ${table.className}ServiceTest extends BaseSpringBootUnitTest {
  68 +
  69 + @Resource
  70 + private ${table.className}ServiceImpl ${classNameVar}Service;
  71 +
  72 + @Resource
  73 + private ${table.className}Mapper ${classNameVar}Mapper;
  74 +
  75 + @Test
  76 + public void testCreate${simpleClassName}_success() {
  77 + // 准备参数
  78 + ${table.className}CreateReqVO reqVO = randomPojo(${table.className}CreateReqVO.class);
  79 +
  80 + // 调用
  81 + Long ${classNameVar}Id = ${classNameVar}Service.create${simpleClassName}(reqVO);
  82 + // 断言
  83 + assertNotNull(${classNameVar}Id);
  84 + // 校验记录的属性是否正确
  85 + ${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(${classNameVar}Id);
  86 + assertPojoEquals(reqVO, ${classNameVar});
  87 + }
  88 +
  89 + @Test
  90 + public void testUpdate${simpleClassName}_success() {
  91 + // mock 数据
  92 + ${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class);
  93 + ${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据
  94 + // 准备参数
  95 + ${table.className}UpdateReqVO reqVO = randomPojo(${table.className}UpdateReqVO.class, o -> {
  96 + o.setId(db${simpleClassName}.getId()); // 设置更新的 ID
  97 + });
  98 +
  99 + // 调用
  100 + ${classNameVar}Service.update${simpleClassName}(reqVO);
  101 + // 校验是否更新正确
  102 + ${table.className}DO ${classNameVar} = ${classNameVar}Mapper.selectById(reqVO.getId()); // 获取最新的
  103 + assertPojoEquals(reqVO, ${classNameVar});
  104 + }
  105 +
  106 + @Test
  107 + public void testUpdate${simpleClassName}_notExists() {
  108 + // 准备参数
  109 + ${table.className}UpdateReqVO reqVO = randomPojo(${table.className}UpdateReqVO.class);
  110 +
  111 + // 调用, 并断言异常
  112 + assertServiceException(() -> ${classNameVar}Service.update${simpleClassName}(reqVO), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
  113 + }
  114 +
  115 + @Test
  116 + public void testDelete${simpleClassName}_success() {
  117 + // mock 数据
  118 + ${table.className}DO db${simpleClassName} = randomPojo(${table.className}DO.class);
  119 + ${classNameVar}Mapper.insert(db${simpleClassName});// @Sql: 先插入出一条存在的数据
  120 + // 准备参数
  121 + Long id = db${simpleClassName}.getId();
  122 +
  123 + // 调用
  124 + ${classNameVar}Service.delete${simpleClassName}(id);
  125 + // 校验数据不存在了
  126 + assertNull(configMapper.selectById(id));
  127 + }
  128 +
  129 + @Test
  130 + public void testDelete${simpleClassName}_notExists() {
  131 + // 准备参数
  132 + Long id = randomLongId();
  133 +
  134 + // 调用, 并断言异常
  135 + assertServiceException(() -> ${classNameVar}Service.delete${simpleClassName}(id), ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
  136 + }
  137 +
  138 + @Test // TODO 请修改 null 为需要的值
  139 + public void testGet${simpleClassName}Page() {
  140 + #getPageCondition("PageReqVO")
  141 +
  142 + // 调用
  143 + PageResult<${table.className}DO> pageResult = configService.getConfigPage(reqVO);
  144 + // 断言
  145 + assertEquals(1, pageResult.getTotal());
  146 + assertEquals(1, pageResult.getList().size());
  147 + assertPojoEquals(db${simpleClassName}, pageResult.getList().get(0));
  148 + }
  149 +
  150 + @Test // TODO 请修改 null 为需要的值
  151 + public void testGet${simpleClassName}List() {
  152 + #getPageCondition("ExportReqVO")
  153 +
  154 + // 调用
  155 + PageResult<${table.className}DO> list = configService.getConfigPage(reqVO);
  156 + // 断言
  157 + assertEquals(1, list.size());
  158 + assertPojoEquals(db${simpleClassName}, list.get(0));
  159 + }
  160 +
  161 +}
src/test/java/cn/iocoder/dashboard/modules/infra/service/config/InfConfigServiceImplTest.java renamed to src/test/java/cn/iocoder/dashboard/modules/infra/service/config/InfConfigServiceTest.java
@@ -20,24 +20,26 @@ import javax.annotation.Resource; @@ -20,24 +20,26 @@ import javax.annotation.Resource;
20 import java.util.List; 20 import java.util.List;
21 import java.util.function.Consumer; 21 import java.util.function.Consumer;
22 22
23 -import static cn.hutool.core.util.RandomUtil.randomEle; 23 +import static cn.hutool.core.util.RandomUtil.*;
24 import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*; 24 import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*;
25 -import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;  
26 -import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;  
27 -import static cn.iocoder.dashboard.util.RandomUtils.randomPojo;  
28 -import static cn.iocoder.dashboard.util.date.DateUtils.buildTime; 25 +import static cn.iocoder.dashboard.util.AssertUtils.*;
  26 +import static cn.iocoder.dashboard.util.RandomUtils.*;
  27 +import static cn.iocoder.dashboard.util.date.DateUtils.*;
29 import static org.junit.jupiter.api.Assertions.*; 28 import static org.junit.jupiter.api.Assertions.*;
30 -import static org.mockito.Mockito.times;  
31 -import static org.mockito.Mockito.verify; 29 +import static org.mockito.Mockito.*;
32 30
33 -public class InfConfigServiceImplTest extends BaseSpringBootUnitTest { 31 +/**
  32 + * {@link InfConfigServiceImpl} 的单元测试类
  33 + *
  34 + * @author 芋道源码
  35 + */
  36 +public class InfConfigServiceTest extends BaseSpringBootUnitTest {
34 37
35 @Resource 38 @Resource
36 private InfConfigServiceImpl configService; 39 private InfConfigServiceImpl configService;
37 40
38 @Resource 41 @Resource
39 private InfConfigMapper configMapper; 42 private InfConfigMapper configMapper;
40 -  
41 @MockBean 43 @MockBean
42 private InfConfigProducer configProducer; 44 private InfConfigProducer configProducer;
43 45
@@ -213,6 +215,15 @@ public class InfConfigServiceImplTest extends BaseSpringBootUnitTest { @@ -213,6 +215,15 @@ public class InfConfigServiceImplTest extends BaseSpringBootUnitTest {
213 assertServiceException(() -> configService.deleteConfig(id), CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); 215 assertServiceException(() -> configService.deleteConfig(id), CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
214 } 216 }
215 217
  218 + @Test
  219 + public void testDeleteConfig_notExists() {
  220 + // 准备参数
  221 + Long id = randomLongId();
  222 +
  223 + // 调用, 并断言异常
  224 + assertServiceException(() -> configService.deleteConfig(id), CONFIG_NOT_EXISTS);
  225 + }
  226 +
216 // ========== 随机对象 ========== 227 // ========== 随机对象 ==========
217 228
218 @SafeVarargs 229 @SafeVarargs
src/test/java/cn/iocoder/dashboard/modules/system/service/auth/SysAuthServiceImplTest.java
@@ -61,7 +61,7 @@ public class SysAuthServiceImplTest extends BaseSpringBootUnitTest { @@ -61,7 +61,7 @@ public class SysAuthServiceImplTest extends BaseSpringBootUnitTest {
61 @Test 61 @Test
62 public void testMockLogin_success() { 62 public void testMockLogin_success() {
63 // 准备参数 63 // 准备参数
64 - Long userId = randomLong(); 64 + Long userId = randomLongId();
65 // mock 方法 01 65 // mock 方法 01
66 SysUserDO user = randomUserDO(o -> o.setId(userId)); 66 SysUserDO user = randomUserDO(o -> o.setId(userId));
67 when(userService.getUser(eq(userId))).thenReturn(user); 67 when(userService.getUser(eq(userId))).thenReturn(user);
@@ -80,7 +80,7 @@ public class SysAuthServiceImplTest extends BaseSpringBootUnitTest { @@ -80,7 +80,7 @@ public class SysAuthServiceImplTest extends BaseSpringBootUnitTest {
80 @Test 80 @Test
81 public void testMockLogin_userNotFound() { 81 public void testMockLogin_userNotFound() {
82 // 准备参数 82 // 准备参数
83 - Long userId = randomLong(); 83 + Long userId = randomLongId();
84 // mock 方法 84 // mock 方法
85 85
86 // 调用, 并断言异常 86 // 调用, 并断言异常
src/test/java/cn/iocoder/dashboard/util/RandomUtils.java
@@ -46,7 +46,7 @@ public class RandomUtils { @@ -46,7 +46,7 @@ public class RandomUtils {
46 return RandomUtil.randomString(RANDOM_STRING_LENGTH); 46 return RandomUtil.randomString(RANDOM_STRING_LENGTH);
47 } 47 }
48 48
49 - public static Long randomLong() { 49 + public static Long randomLongId() {
50 return RandomUtil.randomLong(0, Long.MAX_VALUE); 50 return RandomUtil.randomLong(0, Long.MAX_VALUE);
51 } 51 }
52 52