Commit b5b23b3d7ca2d19179130ba309b41e2ebc7f8db1
1 parent
10f7352e
infra:完善 config 的单元测试
Showing
7 changed files
with
71 additions
and
58 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/config/ConfigController.java
| 1 | package cn.iocoder.yudao.module.infra.controller.admin.config; | 1 | package cn.iocoder.yudao.module.infra.controller.admin.config; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -8,8 +7,8 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | @@ -8,8 +7,8 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||
| 8 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.*; | 7 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.*; |
| 9 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; | 8 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; |
| 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | 9 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 11 | -import cn.iocoder.yudao.module.infra.service.config.ConfigService; | ||
| 12 | import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants; | 10 | import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants; |
| 11 | +import cn.iocoder.yudao.module.infra.service.config.ConfigService; | ||
| 13 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 14 | import io.swagger.annotations.ApiImplicitParam; | 13 | import io.swagger.annotations.ApiImplicitParam; |
| 15 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
| @@ -23,6 +22,7 @@ import javax.validation.Valid; | @@ -23,6 +22,7 @@ import javax.validation.Valid; | ||
| 23 | import java.io.IOException; | 22 | import java.io.IOException; |
| 24 | import java.util.List; | 23 | import java.util.List; |
| 25 | 24 | ||
| 25 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 27 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 28 | 28 | ||
| @@ -76,7 +76,7 @@ public class ConfigController { | @@ -76,7 +76,7 @@ public class ConfigController { | ||
| 76 | return null; | 76 | return null; |
| 77 | } | 77 | } |
| 78 | if (!config.getVisible()) { | 78 | if (!config.getVisible()) { |
| 79 | - throw ServiceExceptionUtil.exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE); | 79 | + throw exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE); |
| 80 | } | 80 | } |
| 81 | return success(config.getValue()); | 81 | return success(config.getValue()); |
| 82 | } | 82 | } |
| @@ -93,8 +93,8 @@ public class ConfigController { | @@ -93,8 +93,8 @@ public class ConfigController { | ||
| 93 | @ApiOperation("导出参数配置") | 93 | @ApiOperation("导出参数配置") |
| 94 | @PreAuthorize("@ss.hasPermission('infra:config:export')") | 94 | @PreAuthorize("@ss.hasPermission('infra:config:export')") |
| 95 | @OperateLog(type = EXPORT) | 95 | @OperateLog(type = EXPORT) |
| 96 | - public void exportSysConfig(@Valid ConfigExportReqVO reqVO, | ||
| 97 | - HttpServletResponse response) throws IOException { | 96 | + public void exportConfig(@Valid ConfigExportReqVO reqVO, |
| 97 | + HttpServletResponse response) throws IOException { | ||
| 98 | List<ConfigDO> list = configService.getConfigList(reqVO); | 98 | List<ConfigDO> list = configService.getConfigList(reqVO); |
| 99 | // 拼接数据 | 99 | // 拼接数据 |
| 100 | List<ConfigExcelVO> datas = ConfigConvert.INSTANCE.convertList(list); | 100 | List<ConfigExcelVO> datas = ConfigConvert.INSTANCE.convertList(list); |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
| @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV | ||
| 9 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; | 9 | import cn.iocoder.yudao.module.infra.convert.config.ConfigConvert; |
| 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | 10 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 11 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | 11 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| 12 | -import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants; | ||
| 13 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; | 12 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; |
| 14 | import com.google.common.annotations.VisibleForTesting; | 13 | import com.google.common.annotations.VisibleForTesting; |
| 15 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
| @@ -20,6 +19,7 @@ import javax.annotation.Resource; | @@ -20,6 +19,7 @@ import javax.annotation.Resource; | ||
| 20 | import java.util.List; | 19 | import java.util.List; |
| 21 | 20 | ||
| 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 21 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | ||
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * 参数配置 Service 实现类 | 25 | * 参数配置 Service 实现类 |
| @@ -35,7 +35,7 @@ public class ConfigServiceImpl implements ConfigService { | @@ -35,7 +35,7 @@ public class ConfigServiceImpl implements ConfigService { | ||
| 35 | @Override | 35 | @Override |
| 36 | public Long createConfig(ConfigCreateReqVO reqVO) { | 36 | public Long createConfig(ConfigCreateReqVO reqVO) { |
| 37 | // 校验正确性 | 37 | // 校验正确性 |
| 38 | - checkCreateOrUpdate(null, reqVO.getKey()); | 38 | + validateConfigForCreateOrUpdate(null, reqVO.getKey()); |
| 39 | // 插入参数配置 | 39 | // 插入参数配置 |
| 40 | ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); | 40 | ConfigDO config = ConfigConvert.INSTANCE.convert(reqVO); |
| 41 | config.setType(ConfigTypeEnum.CUSTOM.getType()); | 41 | config.setType(ConfigTypeEnum.CUSTOM.getType()); |
| @@ -46,19 +46,19 @@ public class ConfigServiceImpl implements ConfigService { | @@ -46,19 +46,19 @@ public class ConfigServiceImpl implements ConfigService { | ||
| 46 | @Override | 46 | @Override |
| 47 | public void updateConfig(ConfigUpdateReqVO reqVO) { | 47 | public void updateConfig(ConfigUpdateReqVO reqVO) { |
| 48 | // 校验正确性 | 48 | // 校验正确性 |
| 49 | - checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key | 49 | + validateConfigForCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key |
| 50 | // 更新参数配置 | 50 | // 更新参数配置 |
| 51 | ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); | 51 | ConfigDO updateObj = ConfigConvert.INSTANCE.convert(reqVO); |
| 52 | - configMapper.updateById(updateObj);; | 52 | + configMapper.updateById(updateObj); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @Override | 55 | @Override |
| 56 | public void deleteConfig(Long id) { | 56 | public void deleteConfig(Long id) { |
| 57 | // 校验配置存在 | 57 | // 校验配置存在 |
| 58 | - ConfigDO config = checkConfigExists(id); | 58 | + ConfigDO config = validateConfigExists(id); |
| 59 | // 内置配置,不允许删除 | 59 | // 内置配置,不允许删除 |
| 60 | if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) { | 60 | if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) { |
| 61 | - throw exception(ErrorCodeConstants.CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); | 61 | + throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); |
| 62 | } | 62 | } |
| 63 | // 删除 | 63 | // 删除 |
| 64 | configMapper.deleteById(id); | 64 | configMapper.deleteById(id); |
| @@ -84,39 +84,39 @@ public class ConfigServiceImpl implements ConfigService { | @@ -84,39 +84,39 @@ public class ConfigServiceImpl implements ConfigService { | ||
| 84 | return configMapper.selectList(reqVO); | 84 | return configMapper.selectList(reqVO); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | - private void checkCreateOrUpdate(Long id, String key) { | 87 | + private void validateConfigForCreateOrUpdate(Long id, String key) { |
| 88 | // 校验自己存在 | 88 | // 校验自己存在 |
| 89 | - checkConfigExists(id); | 89 | + validateConfigExists(id); |
| 90 | // 校验参数配置 key 的唯一性 | 90 | // 校验参数配置 key 的唯一性 |
| 91 | if (StrUtil.isNotEmpty(key)) { | 91 | if (StrUtil.isNotEmpty(key)) { |
| 92 | - checkConfigKeyUnique(id, key); | 92 | + validateConfigKeyUnique(id, key); |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | @VisibleForTesting | 96 | @VisibleForTesting |
| 97 | - public ConfigDO checkConfigExists(Long id) { | 97 | + public ConfigDO validateConfigExists(Long id) { |
| 98 | if (id == null) { | 98 | if (id == null) { |
| 99 | return null; | 99 | return null; |
| 100 | } | 100 | } |
| 101 | ConfigDO config = configMapper.selectById(id); | 101 | ConfigDO config = configMapper.selectById(id); |
| 102 | if (config == null) { | 102 | if (config == null) { |
| 103 | - throw exception(ErrorCodeConstants.CONFIG_NOT_EXISTS); | 103 | + throw exception(CONFIG_NOT_EXISTS); |
| 104 | } | 104 | } |
| 105 | return config; | 105 | return config; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | @VisibleForTesting | 108 | @VisibleForTesting |
| 109 | - public void checkConfigKeyUnique(Long id, String key) { | 109 | + public void validateConfigKeyUnique(Long id, String key) { |
| 110 | ConfigDO config = configMapper.selectByKey(key); | 110 | ConfigDO config = configMapper.selectByKey(key); |
| 111 | if (config == null) { | 111 | if (config == null) { |
| 112 | return; | 112 | return; |
| 113 | } | 113 | } |
| 114 | // 如果 id 为空,说明不用比较是否为相同 id 的参数配置 | 114 | // 如果 id 为空,说明不用比较是否为相同 id 的参数配置 |
| 115 | if (id == null) { | 115 | if (id == null) { |
| 116 | - throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE); | 116 | + throw exception(CONFIG_KEY_DUPLICATE); |
| 117 | } | 117 | } |
| 118 | if (!config.getId().equals(id)) { | 118 | if (!config.getId().equals(id)) { |
| 119 | - throw exception(ErrorCodeConstants.CONFIG_KEY_DUPLICATE); | 119 | + throw exception(CONFIG_KEY_DUPLICATE); |
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | 122 |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceTest.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.config; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.config; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 5 | -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; | 6 | import cn.iocoder.yudao.framework.test.core.util.RandomUtils; |
| 8 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; | 7 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigCreateReqVO; |
| @@ -12,17 +11,17 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV | @@ -12,17 +11,17 @@ import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigUpdateReqV | ||
| 12 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; | 11 | import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; |
| 13 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; | 12 | import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper; |
| 14 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; | 13 | import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum; |
| 15 | -import org.junit.jupiter.api.Assertions; | ||
| 16 | import org.junit.jupiter.api.Test; | 14 | import org.junit.jupiter.api.Test; |
| 17 | import org.springframework.context.annotation.Import; | 15 | import org.springframework.context.annotation.Import; |
| 18 | 16 | ||
| 19 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 20 | -import java.time.LocalDateTime; | ||
| 21 | import java.util.List; | 18 | import java.util.List; |
| 22 | import java.util.function.Consumer; | 19 | import java.util.function.Consumer; |
| 23 | 20 | ||
| 24 | import static cn.hutool.core.util.RandomUtil.randomEle; | 21 | import static cn.hutool.core.util.RandomUtil.randomEle; |
| 22 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||
| 25 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | 23 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 24 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | ||
| 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 27 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 26 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| @@ -50,7 +49,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -50,7 +49,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 50 | // 校验记录的属性是否正确 | 49 | // 校验记录的属性是否正确 |
| 51 | ConfigDO config = configMapper.selectById(configId); | 50 | ConfigDO config = configMapper.selectById(configId); |
| 52 | assertPojoEquals(reqVO, config); | 51 | assertPojoEquals(reqVO, config); |
| 53 | - Assertions.assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); | 52 | + assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType()); |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | @Test | 55 | @Test |
| @@ -101,40 +100,40 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -101,40 +100,40 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | @Test | 102 | @Test |
| 104 | - public void testCheckConfigExists_success() { | 103 | + public void testValidateConfigExists_success() { |
| 105 | // mock 数据 | 104 | // mock 数据 |
| 106 | ConfigDO dbConfigDO = randomConfigDO(); | 105 | ConfigDO dbConfigDO = randomConfigDO(); |
| 107 | configMapper.insert(dbConfigDO);// @Sql: 先插入出一条存在的数据 | 106 | configMapper.insert(dbConfigDO);// @Sql: 先插入出一条存在的数据 |
| 108 | 107 | ||
| 109 | // 调用成功 | 108 | // 调用成功 |
| 110 | - configService.checkConfigExists(dbConfigDO.getId()); | 109 | + configService.validateConfigExists(dbConfigDO.getId()); |
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | @Test | 112 | @Test |
| 114 | - public void testCheckConfigExist_notExists() { | ||
| 115 | - assertServiceException(() -> configService.checkConfigExists(randomLongId()), CONFIG_NOT_EXISTS); | 113 | + public void testValidateConfigExist_notExists() { |
| 114 | + assertServiceException(() -> configService.validateConfigExists(randomLongId()), CONFIG_NOT_EXISTS); | ||
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | @Test | 117 | @Test |
| 119 | - public void testCheckConfigKeyUnique_success() { | 118 | + public void testValidateConfigKeyUnique_success() { |
| 120 | // 调用,成功 | 119 | // 调用,成功 |
| 121 | - configService.checkConfigKeyUnique(randomLongId(), randomString()); | 120 | + configService.validateConfigKeyUnique(randomLongId(), randomString()); |
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | @Test | 123 | @Test |
| 125 | - public void testCheckConfigKeyUnique_keyDuplicateForCreate() { | 124 | + public void testValidateConfigKeyUnique_keyDuplicateForCreate() { |
| 126 | // 准备参数 | 125 | // 准备参数 |
| 127 | String key = randomString(); | 126 | String key = randomString(); |
| 128 | // mock 数据 | 127 | // mock 数据 |
| 129 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); | 128 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); |
| 130 | 129 | ||
| 131 | // 调用,校验异常 | 130 | // 调用,校验异常 |
| 132 | - assertServiceException(() -> configService.checkConfigKeyUnique(null, key), | 131 | + assertServiceException(() -> configService.validateConfigKeyUnique(null, key), |
| 133 | CONFIG_KEY_DUPLICATE); | 132 | CONFIG_KEY_DUPLICATE); |
| 134 | } | 133 | } |
| 135 | 134 | ||
| 136 | @Test | 135 | @Test |
| 137 | - public void testCheckConfigKeyUnique_keyDuplicateForUpdate() { | 136 | + public void testValidateConfigKeyUnique_keyDuplicateForUpdate() { |
| 138 | // 准备参数 | 137 | // 准备参数 |
| 139 | Long id = randomLongId(); | 138 | Long id = randomLongId(); |
| 140 | String key = randomString(); | 139 | String key = randomString(); |
| @@ -142,7 +141,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -142,7 +141,7 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 142 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); | 141 | configMapper.insert(randomConfigDO(o -> o.setConfigKey(key))); |
| 143 | 142 | ||
| 144 | // 调用,校验异常 | 143 | // 调用,校验异常 |
| 145 | - assertServiceException(() -> configService.checkConfigKeyUnique(id, key), | 144 | + assertServiceException(() -> configService.validateConfigKeyUnique(id, key), |
| 146 | CONFIG_KEY_DUPLICATE); | 145 | CONFIG_KEY_DUPLICATE); |
| 147 | } | 146 | } |
| 148 | 147 | ||
| @@ -157,19 +156,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -157,19 +156,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 157 | }); | 156 | }); |
| 158 | configMapper.insert(dbConfig); | 157 | configMapper.insert(dbConfig); |
| 159 | // 测试 name 不匹配 | 158 | // 测试 name 不匹配 |
| 160 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | 159 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); |
| 161 | // 测试 key 不匹配 | 160 | // 测试 key 不匹配 |
| 162 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | 161 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); |
| 163 | // 测试 type 不匹配 | 162 | // 测试 type 不匹配 |
| 164 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | 163 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); |
| 165 | // 测试 createTime 不匹配 | 164 | // 测试 createTime 不匹配 |
| 166 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 165 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 167 | // 准备参数 | 166 | // 准备参数 |
| 168 | ConfigPageReqVO reqVO = new ConfigPageReqVO(); | 167 | ConfigPageReqVO reqVO = new ConfigPageReqVO(); |
| 169 | reqVO.setName("艿"); | 168 | reqVO.setName("艿"); |
| 170 | reqVO.setKey("nai"); | 169 | reqVO.setKey("nai"); |
| 171 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); | 170 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); |
| 172 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)})); | 171 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); |
| 173 | 172 | ||
| 174 | // 调用 | 173 | // 调用 |
| 175 | PageResult<ConfigDO> pageResult = configService.getConfigPage(reqVO); | 174 | PageResult<ConfigDO> pageResult = configService.getConfigPage(reqVO); |
| @@ -190,19 +189,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -190,19 +189,19 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 190 | }); | 189 | }); |
| 191 | configMapper.insert(dbConfig); | 190 | configMapper.insert(dbConfig); |
| 192 | // 测试 name 不匹配 | 191 | // 测试 name 不匹配 |
| 193 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); | 192 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆"))); |
| 194 | // 测试 key 不匹配 | 193 | // 测试 key 不匹配 |
| 195 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); | 194 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou"))); |
| 196 | // 测试 type 不匹配 | 195 | // 测试 type 不匹配 |
| 197 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); | 196 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType()))); |
| 198 | // 测试 createTime 不匹配 | 197 | // 测试 createTime 不匹配 |
| 199 | - configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); | 198 | + configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1)))); |
| 200 | // 准备参数 | 199 | // 准备参数 |
| 201 | ConfigExportReqVO reqVO = new ConfigExportReqVO(); | 200 | ConfigExportReqVO reqVO = new ConfigExportReqVO(); |
| 202 | reqVO.setName("艿"); | 201 | reqVO.setName("艿"); |
| 203 | reqVO.setKey("nai"); | 202 | reqVO.setKey("nai"); |
| 204 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); | 203 | reqVO.setType(ConfigTypeEnum.SYSTEM.getType()); |
| 205 | - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)})); | 204 | + reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15)); |
| 206 | 205 | ||
| 207 | // 调用 | 206 | // 调用 |
| 208 | List<ConfigDO> list = configService.getConfigList(reqVO); | 207 | List<ConfigDO> list = configService.getConfigList(reqVO); |
| @@ -212,6 +211,21 @@ public class ConfigServiceTest extends BaseDbUnitTest { | @@ -212,6 +211,21 @@ public class ConfigServiceTest extends BaseDbUnitTest { | ||
| 212 | } | 211 | } |
| 213 | 212 | ||
| 214 | @Test | 213 | @Test |
| 214 | + public void testGetConfig() { | ||
| 215 | + // mock 数据 | ||
| 216 | + ConfigDO dbConfig = randomConfigDO(); | ||
| 217 | + configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据 | ||
| 218 | + // 准备参数 | ||
| 219 | + Long id = dbConfig.getId(); | ||
| 220 | + | ||
| 221 | + // 调用 | ||
| 222 | + ConfigDO config = configService.getConfig(id); | ||
| 223 | + // 断言 | ||
| 224 | + assertNotNull(config); | ||
| 225 | + assertPojoEquals(dbConfig, config); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + @Test | ||
| 215 | public void testGetConfigByKey() { | 229 | public void testGetConfigByKey() { |
| 216 | // mock 数据 | 230 | // mock 数据 |
| 217 | ConfigDO dbConfig = randomConfigDO(); | 231 | ConfigDO dbConfig = randomConfigDO(); |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
| @@ -89,7 +89,6 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | @@ -89,7 +89,6 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest { | ||
| 89 | o.setId(dbDataSourceConfig.getId()); // 设置更新的 ID | 89 | o.setId(dbDataSourceConfig.getId()); // 设置更新的 ID |
| 90 | }); | 90 | }); |
| 91 | // mock 方法 | 91 | // mock 方法 |
| 92 | -// when(stringEncryptor.encrypt(eq(reqVO.getPassword()))).thenReturn("123456"); | ||
| 93 | databaseUtilsMock.when(() -> JdbcUtils.isConnectionOK(eq(reqVO.getUrl()), | 92 | databaseUtilsMock.when(() -> JdbcUtils.isConnectionOK(eq(reqVO.getUrl()), |
| 94 | eq(reqVO.getUsername()), eq(reqVO.getPassword()))).thenReturn(true); | 93 | eq(reqVO.getUsername()), eq(reqVO.getPassword()))).thenReturn(true); |
| 95 | 94 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.user; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.controller.admin.user; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 7 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | 6 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileRespVO; |
| @@ -31,6 +30,7 @@ import javax.annotation.Resource; | @@ -31,6 +30,7 @@ import javax.annotation.Resource; | ||
| 31 | import javax.validation.Valid; | 30 | import javax.validation.Valid; |
| 32 | import java.util.List; | 31 | import java.util.List; |
| 33 | 32 | ||
| 33 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 35 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 35 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 36 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; | 36 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; |
| @@ -99,7 +99,7 @@ public class UserProfileController { | @@ -99,7 +99,7 @@ public class UserProfileController { | ||
| 99 | @ApiOperation("上传用户个人头像") | 99 | @ApiOperation("上传用户个人头像") |
| 100 | public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { | 100 | public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { |
| 101 | if (file.isEmpty()) { | 101 | if (file.isEmpty()) { |
| 102 | - throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); | 102 | + throw exception(FILE_IS_EMPTY); |
| 103 | } | 103 | } |
| 104 | String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); | 104 | String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); |
| 105 | return success(avatar); | 105 | return success(avatar); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.permission; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.system.service.permission; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| @@ -31,6 +30,7 @@ import javax.annotation.Resource; | @@ -31,6 +30,7 @@ import javax.annotation.Resource; | ||
| 31 | import java.util.*; | 30 | import java.util.*; |
| 32 | import java.util.stream.Collectors; | 31 | import java.util.stream.Collectors; |
| 33 | 32 | ||
| 33 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 34 | import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; | 34 | import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT; |
| 35 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; | 35 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 36 | 36 | ||
| @@ -118,7 +118,7 @@ public class MenuServiceImpl implements MenuService { | @@ -118,7 +118,7 @@ public class MenuServiceImpl implements MenuService { | ||
| 118 | public void updateMenu(MenuUpdateReqVO reqVO) { | 118 | public void updateMenu(MenuUpdateReqVO reqVO) { |
| 119 | // 校验更新的菜单是否存在 | 119 | // 校验更新的菜单是否存在 |
| 120 | if (menuMapper.selectById(reqVO.getId()) == null) { | 120 | if (menuMapper.selectById(reqVO.getId()) == null) { |
| 121 | - throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); | 121 | + throw exception(MENU_NOT_EXISTS); |
| 122 | } | 122 | } |
| 123 | // 校验父菜单存在 | 123 | // 校验父菜单存在 |
| 124 | validateParentMenu(reqVO.getParentId(), reqVO.getId()); | 124 | validateParentMenu(reqVO.getParentId(), reqVO.getId()); |
| @@ -138,11 +138,11 @@ public class MenuServiceImpl implements MenuService { | @@ -138,11 +138,11 @@ public class MenuServiceImpl implements MenuService { | ||
| 138 | public void deleteMenu(Long menuId) { | 138 | public void deleteMenu(Long menuId) { |
| 139 | // 校验是否还有子菜单 | 139 | // 校验是否还有子菜单 |
| 140 | if (menuMapper.selectCountByParentId(menuId) > 0) { | 140 | if (menuMapper.selectCountByParentId(menuId) > 0) { |
| 141 | - throw ServiceExceptionUtil.exception(MENU_EXISTS_CHILDREN); | 141 | + throw exception(MENU_EXISTS_CHILDREN); |
| 142 | } | 142 | } |
| 143 | // 校验删除的菜单是否存在 | 143 | // 校验删除的菜单是否存在 |
| 144 | if (menuMapper.selectById(menuId) == null) { | 144 | if (menuMapper.selectById(menuId) == null) { |
| 145 | - throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS); | 145 | + throw exception(MENU_NOT_EXISTS); |
| 146 | } | 146 | } |
| 147 | // 标记删除 | 147 | // 标记删除 |
| 148 | menuMapper.deleteById(menuId); | 148 | menuMapper.deleteById(menuId); |
| @@ -229,17 +229,17 @@ public class MenuServiceImpl implements MenuService { | @@ -229,17 +229,17 @@ public class MenuServiceImpl implements MenuService { | ||
| 229 | } | 229 | } |
| 230 | // 不能设置自己为父菜单 | 230 | // 不能设置自己为父菜单 |
| 231 | if (parentId.equals(childId)) { | 231 | if (parentId.equals(childId)) { |
| 232 | - throw ServiceExceptionUtil.exception(MENU_PARENT_ERROR); | 232 | + throw exception(MENU_PARENT_ERROR); |
| 233 | } | 233 | } |
| 234 | MenuDO menu = menuMapper.selectById(parentId); | 234 | MenuDO menu = menuMapper.selectById(parentId); |
| 235 | // 父菜单不存在 | 235 | // 父菜单不存在 |
| 236 | if (menu == null) { | 236 | if (menu == null) { |
| 237 | - throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS); | 237 | + throw exception(MENU_PARENT_NOT_EXISTS); |
| 238 | } | 238 | } |
| 239 | // 父菜单必须是目录或者菜单类型 | 239 | // 父菜单必须是目录或者菜单类型 |
| 240 | if (!MenuTypeEnum.DIR.getType().equals(menu.getType()) | 240 | if (!MenuTypeEnum.DIR.getType().equals(menu.getType()) |
| 241 | && !MenuTypeEnum.MENU.getType().equals(menu.getType())) { | 241 | && !MenuTypeEnum.MENU.getType().equals(menu.getType())) { |
| 242 | - throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_DIR_OR_MENU); | 242 | + throw exception(MENU_PARENT_NOT_DIR_OR_MENU); |
| 243 | } | 243 | } |
| 244 | } | 244 | } |
| 245 | 245 | ||
| @@ -260,10 +260,10 @@ public class MenuServiceImpl implements MenuService { | @@ -260,10 +260,10 @@ public class MenuServiceImpl implements MenuService { | ||
| 260 | } | 260 | } |
| 261 | // 如果 id 为空,说明不用比较是否为相同 id 的菜单 | 261 | // 如果 id 为空,说明不用比较是否为相同 id 的菜单 |
| 262 | if (id == null) { | 262 | if (id == null) { |
| 263 | - throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE); | 263 | + throw exception(MENU_NAME_DUPLICATE); |
| 264 | } | 264 | } |
| 265 | if (!menu.getId().equals(id)) { | 265 | if (!menu.getId().equals(id)) { |
| 266 | - throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE); | 266 | + throw exception(MENU_NAME_DUPLICATE); |
| 267 | } | 267 | } |
| 268 | } | 268 | } |
| 269 | 269 |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImplTest.java
| @@ -34,6 +34,7 @@ import java.util.Collections; | @@ -34,6 +34,7 @@ import java.util.Collections; | ||
| 34 | import java.util.List; | 34 | import java.util.List; |
| 35 | 35 | ||
| 36 | import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; | 36 | import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; |
| 37 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||
| 37 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; | 38 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; |
| 38 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 39 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 39 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 40 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| @@ -310,7 +311,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | @@ -310,7 +311,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | ||
| 310 | reqVO.setContactName("艿"); | 311 | reqVO.setContactName("艿"); |
| 311 | reqVO.setContactMobile("1560"); | 312 | reqVO.setContactMobile("1560"); |
| 312 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 313 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 313 | - reqVO.setCreateTime(new LocalDateTime[]{buildTime(2020, 12, 1),buildTime(2020, 12, 24)}); | 314 | + reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); |
| 314 | 315 | ||
| 315 | // 调用 | 316 | // 调用 |
| 316 | PageResult<TenantDO> pageResult = tenantService.getTenantPage(reqVO); | 317 | PageResult<TenantDO> pageResult = tenantService.getTenantPage(reqVO); |
| @@ -347,7 +348,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | @@ -347,7 +348,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | ||
| 347 | reqVO.setContactName("艿"); | 348 | reqVO.setContactName("艿"); |
| 348 | reqVO.setContactMobile("1560"); | 349 | reqVO.setContactMobile("1560"); |
| 349 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | 350 | reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 350 | - reqVO.setCreateTime(new LocalDateTime[]{buildTime(2020, 12, 1),buildTime(2020, 12, 24)}); | 351 | + reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); |
| 351 | 352 | ||
| 352 | // 调用 | 353 | // 调用 |
| 353 | List<TenantDO> list = tenantService.getTenantList(reqVO); | 354 | List<TenantDO> list = tenantService.getTenantList(reqVO); |
| @@ -356,7 +357,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | @@ -356,7 +357,6 @@ public class TenantServiceImplTest extends BaseDbUnitTest { | ||
| 356 | assertPojoEquals(dbTenant, list.get(0)); | 357 | assertPojoEquals(dbTenant, list.get(0)); |
| 357 | } | 358 | } |
| 358 | 359 | ||
| 359 | - | ||
| 360 | @Test | 360 | @Test |
| 361 | public void testGetTenantByName() { | 361 | public void testGetTenantByName() { |
| 362 | // mock 数据 | 362 | // mock 数据 |