|
@@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.config;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
|
|
|
-import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
|
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
|
|
import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
|
|
|
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
|
|
|
import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
|
|
|
import cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigMapper;
|
|
|
import cn.iocoder.yudao.module.infra.enums.config.ConfigTypeEnum;
|
|
|
-import org.junit.jupiter.api.Assertions;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
import static cn.hutool.core.util.RandomUtil.randomEle;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
|
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
|
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
|
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
|
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
|
@@ -50,7 +49,7 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
// 校验记录的属性是否正确
|
|
|
ConfigDO config = configMapper.selectById(configId);
|
|
|
assertPojoEquals(reqVO, config);
|
|
|
- Assertions.assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType());
|
|
|
+ assertEquals(ConfigTypeEnum.CUSTOM.getType(), config.getType());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -101,40 +100,40 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testCheckConfigExists_success() {
|
|
|
+ public void testValidateConfigExists_success() {
|
|
|
// mock 数据
|
|
|
ConfigDO dbConfigDO = randomConfigDO();
|
|
|
configMapper.insert(dbConfigDO);// @Sql: 先插入出一条存在的数据
|
|
|
|
|
|
// 调用成功
|
|
|
- configService.checkConfigExists(dbConfigDO.getId());
|
|
|
+ configService.validateConfigExists(dbConfigDO.getId());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testCheckConfigExist_notExists() {
|
|
|
- assertServiceException(() -> configService.checkConfigExists(randomLongId()), CONFIG_NOT_EXISTS);
|
|
|
+ public void testValidateConfigExist_notExists() {
|
|
|
+ assertServiceException(() -> configService.validateConfigExists(randomLongId()), CONFIG_NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testCheckConfigKeyUnique_success() {
|
|
|
+ public void testValidateConfigKeyUnique_success() {
|
|
|
// 调用,成功
|
|
|
- configService.checkConfigKeyUnique(randomLongId(), randomString());
|
|
|
+ configService.validateConfigKeyUnique(randomLongId(), randomString());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testCheckConfigKeyUnique_keyDuplicateForCreate() {
|
|
|
+ public void testValidateConfigKeyUnique_keyDuplicateForCreate() {
|
|
|
// 准备参数
|
|
|
String key = randomString();
|
|
|
// mock 数据
|
|
|
configMapper.insert(randomConfigDO(o -> o.setConfigKey(key)));
|
|
|
|
|
|
// 调用,校验异常
|
|
|
- assertServiceException(() -> configService.checkConfigKeyUnique(null, key),
|
|
|
+ assertServiceException(() -> configService.validateConfigKeyUnique(null, key),
|
|
|
CONFIG_KEY_DUPLICATE);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testCheckConfigKeyUnique_keyDuplicateForUpdate() {
|
|
|
+ public void testValidateConfigKeyUnique_keyDuplicateForUpdate() {
|
|
|
// 准备参数
|
|
|
Long id = randomLongId();
|
|
|
String key = randomString();
|
|
@@ -142,7 +141,7 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
configMapper.insert(randomConfigDO(o -> o.setConfigKey(key)));
|
|
|
|
|
|
// 调用,校验异常
|
|
|
- assertServiceException(() -> configService.checkConfigKeyUnique(id, key),
|
|
|
+ assertServiceException(() -> configService.validateConfigKeyUnique(id, key),
|
|
|
CONFIG_KEY_DUPLICATE);
|
|
|
}
|
|
|
|
|
@@ -157,19 +156,19 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
});
|
|
|
configMapper.insert(dbConfig);
|
|
|
// 测试 name 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
|
|
// 测试 key 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
|
|
|
// 测试 type 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
|
|
|
// 测试 createTime 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
|
|
// 准备参数
|
|
|
ConfigPageReqVO reqVO = new ConfigPageReqVO();
|
|
|
reqVO.setName("艿");
|
|
|
reqVO.setKey("nai");
|
|
|
reqVO.setType(ConfigTypeEnum.SYSTEM.getType());
|
|
|
- reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)}));
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15));
|
|
|
|
|
|
// 调用
|
|
|
PageResult<ConfigDO> pageResult = configService.getConfigPage(reqVO);
|
|
@@ -190,19 +189,19 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
});
|
|
|
configMapper.insert(dbConfig);
|
|
|
// 测试 name 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setName("土豆")));
|
|
|
// 测试 key 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setConfigKey("tudou")));
|
|
|
// 测试 type 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setType(ConfigTypeEnum.CUSTOM.getType())));
|
|
|
// 测试 createTime 不匹配
|
|
|
- configMapper.insert(ObjectUtils.cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
|
|
+ configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
|
|
// 准备参数
|
|
|
ConfigExportReqVO reqVO = new ConfigExportReqVO();
|
|
|
reqVO.setName("艿");
|
|
|
reqVO.setKey("nai");
|
|
|
reqVO.setType(ConfigTypeEnum.SYSTEM.getType());
|
|
|
- reqVO.setCreateTime((new LocalDateTime[]{buildTime(2021, 1, 15),buildTime(2021, 2, 15)}));
|
|
|
+ reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15));
|
|
|
|
|
|
// 调用
|
|
|
List<ConfigDO> list = configService.getConfigList(reqVO);
|
|
@@ -212,6 +211,21 @@ public class ConfigServiceTest extends BaseDbUnitTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
+ public void testGetConfig() {
|
|
|
+ // mock 数据
|
|
|
+ ConfigDO dbConfig = randomConfigDO();
|
|
|
+ configMapper.insert(dbConfig);// @Sql: 先插入出一条存在的数据
|
|
|
+ // 准备参数
|
|
|
+ Long id = dbConfig.getId();
|
|
|
+
|
|
|
+ // 调用
|
|
|
+ ConfigDO config = configService.getConfig(id);
|
|
|
+ // 断言
|
|
|
+ assertNotNull(config);
|
|
|
+ assertPojoEquals(dbConfig, config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
public void testGetConfigByKey() {
|
|
|
// mock 数据
|
|
|
ConfigDO dbConfig = randomConfigDO();
|