|
@@ -1,16 +1,16 @@
|
|
|
-package cn.iocoder.dashboard.modules.infra.service.errorcode;
|
|
|
+package cn.iocoder.dashboard.modules.system.service.errorcode;
|
|
|
|
|
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
|
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
|
|
-import cn.iocoder.dashboard.modules.infra.controller.errorcode.vo.InfErrorCodeCreateReqVO;
|
|
|
-import cn.iocoder.dashboard.modules.infra.controller.errorcode.vo.InfErrorCodeExportReqVO;
|
|
|
-import cn.iocoder.dashboard.modules.infra.controller.errorcode.vo.InfErrorCodePageReqVO;
|
|
|
-import cn.iocoder.dashboard.modules.infra.controller.errorcode.vo.InfErrorCodeUpdateReqVO;
|
|
|
-import cn.iocoder.dashboard.modules.infra.dal.dataobject.errorcode.InfErrorCodeDO;
|
|
|
-import cn.iocoder.dashboard.modules.infra.dal.mysql.errorcode.InfErrorCodeMapper;
|
|
|
+import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.SysErrorCodeCreateReqVO;
|
|
|
+import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.SysErrorCodeExportReqVO;
|
|
|
+import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.SysErrorCodePageReqVO;
|
|
|
+import cn.iocoder.dashboard.modules.system.controller.errorcode.vo.SysErrorCodeUpdateReqVO;
|
|
|
+import cn.iocoder.dashboard.modules.system.dal.dataobject.errorcode.SysErrorCodeDO;
|
|
|
+import cn.iocoder.dashboard.modules.system.dal.mysql.errorcode.SysErrorCodeMapper;
|
|
|
import cn.iocoder.dashboard.modules.infra.enums.config.InfConfigTypeEnum;
|
|
|
-import cn.iocoder.dashboard.modules.infra.enums.errorcode.InfErrorCodeTypeEnum;
|
|
|
-import cn.iocoder.dashboard.modules.infra.service.errorcode.impl.InfErrorCodeServiceImpl;
|
|
|
+import cn.iocoder.dashboard.modules.system.enums.errorcode.SysErrorCodeTypeEnum;
|
|
|
+import cn.iocoder.dashboard.modules.system.service.errorcode.impl.SysErrorCodeServiceImpl;
|
|
|
import cn.iocoder.dashboard.util.collection.ArrayUtils;
|
|
|
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -21,8 +21,7 @@ import java.util.List;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
|
|
-import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.ERROR_CODE_DUPLICATE;
|
|
|
-import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.ERROR_CODE_NOT_EXISTS;
|
|
|
+import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
|
|
|
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
|
|
import static cn.iocoder.dashboard.util.AssertUtils.assertServiceException;
|
|
|
import static cn.iocoder.dashboard.util.RandomUtils.*;
|
|
@@ -30,56 +29,56 @@ import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
/**
|
|
|
-* {@link InfErrorCodeServiceImpl} 的单元测试类
|
|
|
+* {@link SysErrorCodeServiceImpl} 的单元测试类
|
|
|
*
|
|
|
* @author 芋道源码
|
|
|
*/
|
|
|
-@Import(InfErrorCodeServiceImpl.class)
|
|
|
-public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
+@Import(SysErrorCodeServiceImpl.class)
|
|
|
+public class SysErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
|
|
|
@Resource
|
|
|
- private InfErrorCodeServiceImpl errorCodeService;
|
|
|
+ private SysErrorCodeServiceImpl errorCodeService;
|
|
|
|
|
|
@Resource
|
|
|
- private InfErrorCodeMapper errorCodeMapper;
|
|
|
+ private SysErrorCodeMapper errorCodeMapper;
|
|
|
|
|
|
@Test
|
|
|
public void testCreateErrorCode_success() {
|
|
|
// 准备参数
|
|
|
- InfErrorCodeCreateReqVO reqVO = randomPojo(InfErrorCodeCreateReqVO.class);
|
|
|
+ SysErrorCodeCreateReqVO reqVO = randomPojo(SysErrorCodeCreateReqVO.class);
|
|
|
|
|
|
// 调用
|
|
|
Long errorCodeId = errorCodeService.createErrorCode(reqVO);
|
|
|
// 断言
|
|
|
assertNotNull(errorCodeId);
|
|
|
// 校验记录的属性是否正确
|
|
|
- InfErrorCodeDO errorCode = errorCodeMapper.selectById(errorCodeId);
|
|
|
+ SysErrorCodeDO errorCode = errorCodeMapper.selectById(errorCodeId);
|
|
|
assertPojoEquals(reqVO, errorCode);
|
|
|
- assertEquals(InfErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType());
|
|
|
+ assertEquals(SysErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testUpdateErrorCode_success() {
|
|
|
// mock 数据
|
|
|
- InfErrorCodeDO dbErrorCode = randomInfErrorCodeDO();
|
|
|
+ SysErrorCodeDO dbErrorCode = randomInfErrorCodeDO();
|
|
|
errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据
|
|
|
// 准备参数
|
|
|
- InfErrorCodeUpdateReqVO reqVO = randomPojo(InfErrorCodeUpdateReqVO.class, o -> {
|
|
|
+ SysErrorCodeUpdateReqVO reqVO = randomPojo(SysErrorCodeUpdateReqVO.class, o -> {
|
|
|
o.setId(dbErrorCode.getId()); // 设置更新的 ID
|
|
|
});
|
|
|
|
|
|
// 调用
|
|
|
errorCodeService.updateErrorCode(reqVO);
|
|
|
// 校验是否更新正确
|
|
|
- InfErrorCodeDO errorCode = errorCodeMapper.selectById(reqVO.getId()); // 获取最新的
|
|
|
+ SysErrorCodeDO errorCode = errorCodeMapper.selectById(reqVO.getId()); // 获取最新的
|
|
|
assertPojoEquals(reqVO, errorCode);
|
|
|
- assertEquals(InfErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType());
|
|
|
+ assertEquals(SysErrorCodeTypeEnum.MANUAL_OPERATION.getType(), errorCode.getType());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDeleteErrorCode_success() {
|
|
|
// mock 数据
|
|
|
- InfErrorCodeDO dbErrorCode = randomInfErrorCodeDO();
|
|
|
+ SysErrorCodeDO dbErrorCode = randomInfErrorCodeDO();
|
|
|
errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据
|
|
|
// 准备参数
|
|
|
Long id = dbErrorCode.getId();
|
|
@@ -93,10 +92,10 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
@Test
|
|
|
public void testGetErrorCodePage() {
|
|
|
// mock 数据
|
|
|
- InfErrorCodeDO dbErrorCode = initGetErrorCodePage();
|
|
|
+ SysErrorCodeDO dbErrorCode = initGetErrorCodePage();
|
|
|
// 准备参数
|
|
|
- InfErrorCodePageReqVO reqVO = new InfErrorCodePageReqVO();
|
|
|
- reqVO.setType(InfErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
+ SysErrorCodePageReqVO reqVO = new SysErrorCodePageReqVO();
|
|
|
+ reqVO.setType(SysErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
reqVO.setApplicationName("yudao");
|
|
|
reqVO.setCode(1);
|
|
|
reqVO.setMessage("yu");
|
|
@@ -104,7 +103,7 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
reqVO.setEndCreateTime(buildTime(2020, 11, 30));
|
|
|
|
|
|
// 调用
|
|
|
- PageResult<InfErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO);
|
|
|
+ PageResult<SysErrorCodeDO> pageResult = errorCodeService.getErrorCodePage(reqVO);
|
|
|
// 断言
|
|
|
assertEquals(1, pageResult.getTotal());
|
|
|
assertEquals(1, pageResult.getList().size());
|
|
@@ -114,9 +113,9 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
/**
|
|
|
* 初始化 getErrorCodePage 方法的测试数据
|
|
|
*/
|
|
|
- private InfErrorCodeDO initGetErrorCodePage() {
|
|
|
- InfErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到
|
|
|
- o.setType(InfErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
+ private SysErrorCodeDO initGetErrorCodePage() {
|
|
|
+ SysErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到
|
|
|
+ o.setType(SysErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
o.setApplicationName("yudaoyuanma");
|
|
|
o.setCode(1);
|
|
|
o.setMessage("yudao");
|
|
@@ -124,7 +123,7 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
});
|
|
|
errorCodeMapper.insert(dbErrorCode);
|
|
|
// 测试 type 不匹配
|
|
|
- errorCodeMapper.insert(ObjectUtils.clone(dbErrorCode, o -> o.setType(InfErrorCodeTypeEnum.MANUAL_OPERATION.getType())));
|
|
|
+ errorCodeMapper.insert(ObjectUtils.clone(dbErrorCode, o -> o.setType(SysErrorCodeTypeEnum.MANUAL_OPERATION.getType())));
|
|
|
// 测试 applicationName 不匹配
|
|
|
errorCodeMapper.insert(ObjectUtils.clone(dbErrorCode, o -> o.setApplicationName("yunai")));
|
|
|
// 测试 code 不匹配
|
|
@@ -139,10 +138,10 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
@Test
|
|
|
public void testGetErrorCodeList() {
|
|
|
// mock 数据
|
|
|
- InfErrorCodeDO dbErrorCode = initGetErrorCodePage();
|
|
|
+ SysErrorCodeDO dbErrorCode = initGetErrorCodePage();
|
|
|
// 准备参数
|
|
|
- InfErrorCodeExportReqVO reqVO = new InfErrorCodeExportReqVO();
|
|
|
- reqVO.setType(InfErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
+ SysErrorCodeExportReqVO reqVO = new SysErrorCodeExportReqVO();
|
|
|
+ reqVO.setType(SysErrorCodeTypeEnum.AUTO_GENERATION.getType());
|
|
|
reqVO.setApplicationName("yudao");
|
|
|
reqVO.setCode(1);
|
|
|
reqVO.setMessage("yu");
|
|
@@ -150,7 +149,7 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
reqVO.setEndCreateTime(buildTime(2020, 11, 30));
|
|
|
|
|
|
// 调用
|
|
|
- List<InfErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO);
|
|
|
+ List<SysErrorCodeDO> list = errorCodeService.getErrorCodeList(reqVO);
|
|
|
// 断言
|
|
|
assertEquals(1, list.size());
|
|
|
assertPojoEquals(dbErrorCode, list.get(0));
|
|
@@ -190,11 +189,11 @@ public class InfErrorCodeServiceTest extends BaseDbUnitTest {
|
|
|
// ========== 随机对象 ==========
|
|
|
|
|
|
@SafeVarargs
|
|
|
- private static InfErrorCodeDO randomInfErrorCodeDO(Consumer<InfErrorCodeDO>... consumers) {
|
|
|
- Consumer<InfErrorCodeDO> consumer = (o) -> {
|
|
|
+ private static SysErrorCodeDO randomInfErrorCodeDO(Consumer<SysErrorCodeDO>... consumers) {
|
|
|
+ Consumer<SysErrorCodeDO> consumer = (o) -> {
|
|
|
o.setType(randomEle(InfConfigTypeEnum.values()).getType()); // 保证 key 的范围
|
|
|
};
|
|
|
- return randomPojo(InfErrorCodeDO.class, ArrayUtils.append(consumer, consumers));
|
|
|
+ return randomPojo(SysErrorCodeDO.class, ArrayUtils.append(consumer, consumers));
|
|
|
}
|
|
|
|
|
|
}
|