修改名称
This commit is contained in:
@@ -163,7 +163,7 @@ public class ConfigServiceImplTest extends BaseDbUnitTest {
|
||||
configMapper.insert(cloneIgnoreId(dbConfig, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||
// 准备参数
|
||||
ConfigPageReqVO reqVO = new ConfigPageReqVO();
|
||||
reqVO.setName("艿");
|
||||
reqVO.setName("鹭");
|
||||
reqVO.setKey("nai");
|
||||
reqVO.setType(ConfigTypeEnum.SYSTEM.getType());
|
||||
reqVO.setCreateTime(buildBetweenTime(2021, 1, 15, 2021, 2, 15));
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MailTemplatePageReqVO extends PageParam {
|
||||
@Schema(description = "标识,模糊匹配", example = "code_1024")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "名称,模糊匹配", example = "芋头")
|
||||
@Schema(description = "名称,模糊匹配", example = "鹭筑")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "账号编号", example = "2048")
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MailTemplateRespVO {
|
||||
@Schema(description = "发送的邮箱账号编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "发送人名称", example = "芋头")
|
||||
@Schema(description = "发送人名称", example = "鹭筑")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MailTemplateSaveReqVO {
|
||||
@NotNull(message = "发送的邮箱账号编号不能为空")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "发送人名称", example = "芋头")
|
||||
@Schema(description = "发送人名称", example = "鹭筑")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "注册成功")
|
||||
|
||||
@@ -1,352 +0,0 @@
|
||||
package cn.iocoder.lyzsys.module.system.service.dict;
|
||||
|
||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.lyzsys.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictTypeDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.dict.DictDataMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Import(DictDataServiceImpl.class)
|
||||
public class DictDataServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private DictDataServiceImpl dictDataService;
|
||||
|
||||
@Resource
|
||||
private DictDataMapper dictDataMapper;
|
||||
@MockBean
|
||||
private DictTypeService dictTypeService;
|
||||
|
||||
@Test
|
||||
public void testGetDictDataList() {
|
||||
// mock 数据
|
||||
DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2)
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO01);
|
||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1)
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO02);
|
||||
DictDataDO dictDataDO03 = randomDictDataDO().setDictType("yunai").setSort(3)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO03);
|
||||
DictDataDO dictDataDO04 = randomDictDataDO().setDictType("yunai2").setSort(3)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO04);
|
||||
// 准备参数
|
||||
Integer status = CommonStatusEnum.ENABLE.getStatus();
|
||||
String dictType = "yunai";
|
||||
|
||||
// 调用
|
||||
List<DictDataDO> dictDataDOList = dictDataService.getDictDataList(status, dictType);
|
||||
// 断言
|
||||
assertEquals(2, dictDataDOList.size());
|
||||
assertPojoEquals(dictDataDO02, dictDataDOList.get(0));
|
||||
assertPojoEquals(dictDataDO01, dictDataDOList.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictDataPage() {
|
||||
// mock 数据
|
||||
DictDataDO dbDictData = randomPojo(DictDataDO.class, o -> { // 等会查询到
|
||||
o.setLabel("鹭鹭");
|
||||
o.setDictType("yunai");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
});
|
||||
dictDataMapper.insert(dbDictData);
|
||||
// 测试 label 不匹配
|
||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setLabel("艿")));
|
||||
// 测试 dictType 不匹配
|
||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setDictType("nai")));
|
||||
// 测试 status 不匹配
|
||||
dictDataMapper.insert(cloneIgnoreId(dbDictData, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 准备参数
|
||||
DictDataPageReqVO reqVO = new DictDataPageReqVO();
|
||||
reqVO.setLabel("鹭");
|
||||
reqVO.setDictType("yunai");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
|
||||
// 调用
|
||||
PageResult<DictDataDO> pageResult = dictDataService.getDictDataPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbDictData, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictData() {
|
||||
// mock 数据
|
||||
DictDataDO dbDictData = randomDictDataDO();
|
||||
dictDataMapper.insert(dbDictData);
|
||||
// 准备参数
|
||||
Long id = dbDictData.getId();
|
||||
|
||||
// 调用
|
||||
DictDataDO dictData = dictDataService.getDictData(id);
|
||||
// 断言
|
||||
assertPojoEquals(dbDictData, dictData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDictData_success() {
|
||||
// 准备参数
|
||||
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class,
|
||||
o -> o.setStatus(randomCommonStatus()))
|
||||
.setId(null); // 防止 id 被赋值
|
||||
// mock 方法
|
||||
when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType()));
|
||||
|
||||
// 调用
|
||||
Long dictDataId = dictDataService.createDictData(reqVO);
|
||||
// 断言
|
||||
assertNotNull(dictDataId);
|
||||
// 校验记录的属性是否正确
|
||||
DictDataDO dictData = dictDataMapper.selectById(dictDataId);
|
||||
assertPojoEquals(reqVO, dictData, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDictData_success() {
|
||||
// mock 数据
|
||||
DictDataDO dbDictData = randomDictDataDO();
|
||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
DictDataSaveReqVO reqVO = randomPojo(DictDataSaveReqVO.class, o -> {
|
||||
o.setId(dbDictData.getId()); // 设置更新的 ID
|
||||
o.setStatus(randomCommonStatus());
|
||||
});
|
||||
// mock 方法,字典类型
|
||||
when(dictTypeService.getDictType(eq(reqVO.getDictType()))).thenReturn(randomDictTypeDO(reqVO.getDictType()));
|
||||
|
||||
// 调用
|
||||
dictDataService.updateDictData(reqVO);
|
||||
// 校验是否更新正确
|
||||
DictDataDO dictData = dictDataMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, dictData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDictData_success() {
|
||||
// mock 数据
|
||||
DictDataDO dbDictData = randomDictDataDO();
|
||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbDictData.getId();
|
||||
|
||||
// 调用
|
||||
dictDataService.deleteDictData(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(dictDataMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataExists_success() {
|
||||
// mock 数据
|
||||
DictDataDO dbDictData = randomDictDataDO();
|
||||
dictDataMapper.insert(dbDictData);// @Sql: 先插入出一条存在的数据
|
||||
|
||||
// 调用成功
|
||||
dictDataService.validateDictDataExists(dbDictData.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataExists_notExists() {
|
||||
assertServiceException(() -> dictDataService.validateDictDataExists(randomLongId()), DICT_DATA_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeExists_success() {
|
||||
// mock 方法,数据类型被禁用
|
||||
String type = randomString();
|
||||
when(dictTypeService.getDictType(eq(type))).thenReturn(randomDictTypeDO(type));
|
||||
|
||||
// 调用, 成功
|
||||
dictDataService.validateDictTypeExists(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeExists_notExists() {
|
||||
assertServiceException(() -> dictDataService.validateDictTypeExists(randomString()), DICT_TYPE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeExists_notEnable() {
|
||||
// mock 方法,数据类型被禁用
|
||||
String dictType = randomString();
|
||||
when(dictTypeService.getDictType(eq(dictType))).thenReturn(
|
||||
randomPojo(DictTypeDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> dictDataService.validateDictTypeExists(dictType), DICT_TYPE_NOT_ENABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataValueUnique_success() {
|
||||
// 调用,成功
|
||||
dictDataService.validateDictDataValueUnique(randomLongId(), randomString(), randomString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataValueUnique_valueDuplicateForCreate() {
|
||||
// 准备参数
|
||||
String dictType = randomString();
|
||||
String value = randomString();
|
||||
// mock 数据
|
||||
dictDataMapper.insert(randomDictDataDO(o -> {
|
||||
o.setDictType(dictType);
|
||||
o.setValue(value);
|
||||
}));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictDataService.validateDictDataValueUnique(null, dictType, value),
|
||||
DICT_DATA_VALUE_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataValueUnique_valueDuplicateForUpdate() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
String dictType = randomString();
|
||||
String value = randomString();
|
||||
// mock 数据
|
||||
dictDataMapper.insert(randomDictDataDO(o -> {
|
||||
o.setDictType(dictType);
|
||||
o.setValue(value);
|
||||
}));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictDataService.validateDictDataValueUnique(id, dictType, value),
|
||||
DICT_DATA_VALUE_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictDataCountByDictType() {
|
||||
// mock 数据
|
||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai")));
|
||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("tudou")));
|
||||
dictDataMapper.insert(randomDictDataDO(o -> o.setDictType("yunai")));
|
||||
// 准备参数
|
||||
String dictType = "yunai";
|
||||
|
||||
// 调用
|
||||
long count = dictDataService.getDictDataCountByDictType(dictType);
|
||||
// 校验
|
||||
assertEquals(2L, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataList_success() {
|
||||
// mock 数据
|
||||
DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO);
|
||||
// 准备参数
|
||||
String dictType = dictDataDO.getDictType();
|
||||
List<String> values = singletonList(dictDataDO.getValue());
|
||||
|
||||
// 调用,无需断言
|
||||
dictDataService.validateDictDataList(dictType, values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataList_notFound() {
|
||||
// 准备参数
|
||||
String dictType = randomString();
|
||||
List<String> values = singletonList(randomString());
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> dictDataService.validateDictDataList(dictType, values), DICT_DATA_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataList_notEnable() {
|
||||
// mock 数据
|
||||
DictDataDO dictDataDO = randomDictDataDO().setStatus(CommonStatusEnum.DISABLE.getStatus());
|
||||
dictDataMapper.insert(dictDataDO);
|
||||
// 准备参数
|
||||
String dictType = dictDataDO.getDictType();
|
||||
List<String> values = singletonList(dictDataDO.getValue());
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> dictDataService.validateDictDataList(dictType, values),
|
||||
DICT_DATA_NOT_ENABLE, dictDataDO.getLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictData_dictType() {
|
||||
// mock 数据
|
||||
DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setValue("1");
|
||||
dictDataMapper.insert(dictDataDO);
|
||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setValue("2");
|
||||
dictDataMapper.insert(dictDataDO02);
|
||||
// 准备参数
|
||||
String dictType = "yunai";
|
||||
String value = "1";
|
||||
|
||||
// 调用
|
||||
DictDataDO dbDictData = dictDataService.getDictData(dictType, value);
|
||||
// 断言
|
||||
assertEquals(dictDataDO, dbDictData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseDictData() {
|
||||
// mock 数据
|
||||
DictDataDO dictDataDO = randomDictDataDO().setDictType("yunai").setLabel("1");
|
||||
dictDataMapper.insert(dictDataDO);
|
||||
DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setLabel("2");
|
||||
dictDataMapper.insert(dictDataDO02);
|
||||
// 准备参数
|
||||
String dictType = "yunai";
|
||||
String label = "1";
|
||||
|
||||
// 调用
|
||||
DictDataDO dbDictData = dictDataService.parseDictData(dictType, label);
|
||||
// 断言
|
||||
assertEquals(dictDataDO, dbDictData);
|
||||
}
|
||||
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
private static DictDataDO randomDictDataDO(Consumer<DictDataDO>... consumers) {
|
||||
Consumer<DictDataDO> consumer = (o) -> {
|
||||
o.setStatus(randomCommonStatus()); // 保证 status 的范围
|
||||
};
|
||||
return randomPojo(DictDataDO.class, ArrayUtils.append(consumer, consumers));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个有效的字典类型
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @return DictTypeDO 对象
|
||||
*/
|
||||
private static DictTypeDO randomDictTypeDO(String type) {
|
||||
return randomPojo(DictTypeDO.class, o -> {
|
||||
o.setType(type);
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 保证 status 是开启
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
package cn.iocoder.lyzsys.module.system.service.dict;
|
||||
|
||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.lyzsys.framework.common.util.collection.ArrayUtils;
|
||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.dict.vo.type.DictTypeSaveReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dict.DictTypeDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.dict.DictTypeMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Import(DictTypeServiceImpl.class)
|
||||
public class DictTypeServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private DictTypeServiceImpl dictTypeService;
|
||||
|
||||
@Resource
|
||||
private DictTypeMapper dictTypeMapper;
|
||||
@MockBean
|
||||
private DictDataService dictDataService;
|
||||
|
||||
@Test
|
||||
public void testGetDictTypePage() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomPojo(DictTypeDO.class, o -> { // 等会查询到
|
||||
o.setName("yunai");
|
||||
o.setType("鹭鹭");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setCreateTime(buildTime(2021, 1, 15));
|
||||
});
|
||||
dictTypeMapper.insert(dbDictType);
|
||||
// 测试 name 不匹配
|
||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setName("tudou")));
|
||||
// 测试 type 不匹配
|
||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setType("土豆")));
|
||||
// 测试 status 不匹配
|
||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 createTime 不匹配
|
||||
dictTypeMapper.insert(cloneIgnoreId(dbDictType, o -> o.setCreateTime(buildTime(2021, 1, 1))));
|
||||
// 准备参数
|
||||
DictTypePageReqVO reqVO = new DictTypePageReqVO();
|
||||
reqVO.setName("nai");
|
||||
reqVO.setType("艿");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setCreateTime(buildBetweenTime(2021, 1, 10, 2021, 1, 20));
|
||||
|
||||
// 调用
|
||||
PageResult<DictTypeDO> pageResult = dictTypeService.getDictTypePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbDictType, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictType_id() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);
|
||||
// 准备参数
|
||||
Long id = dbDictType.getId();
|
||||
|
||||
// 调用
|
||||
DictTypeDO dictType = dictTypeService.getDictType(id);
|
||||
// 断言
|
||||
assertNotNull(dictType);
|
||||
assertPojoEquals(dbDictType, dictType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictType_type() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);
|
||||
// 准备参数
|
||||
String type = dbDictType.getType();
|
||||
|
||||
// 调用
|
||||
DictTypeDO dictType = dictTypeService.getDictType(type);
|
||||
// 断言
|
||||
assertNotNull(dictType);
|
||||
assertPojoEquals(dbDictType, dictType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateDictType_success() {
|
||||
// 准备参数
|
||||
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class,
|
||||
o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()))
|
||||
.setId(null); // 避免 id 被赋值
|
||||
|
||||
// 调用
|
||||
Long dictTypeId = dictTypeService.createDictType(reqVO);
|
||||
// 断言
|
||||
assertNotNull(dictTypeId);
|
||||
// 校验记录的属性是否正确
|
||||
DictTypeDO dictType = dictTypeMapper.selectById(dictTypeId);
|
||||
assertPojoEquals(reqVO, dictType, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDictType_success() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
DictTypeSaveReqVO reqVO = randomPojo(DictTypeSaveReqVO.class, o -> {
|
||||
o.setId(dbDictType.getId()); // 设置更新的 ID
|
||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus());
|
||||
});
|
||||
|
||||
// 调用
|
||||
dictTypeService.updateDictType(reqVO);
|
||||
// 校验是否更新正确
|
||||
DictTypeDO dictType = dictTypeMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, dictType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDictType_success() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbDictType.getId();
|
||||
|
||||
// 调用
|
||||
dictTypeService.deleteDictType(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(dictTypeMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteDictType_hasChildren() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbDictType.getId();
|
||||
// mock 方法
|
||||
when(dictDataService.getDictDataCountByDictType(eq(dbDictType.getType()))).thenReturn(1L);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> dictTypeService.deleteDictType(id), DICT_TYPE_HAS_CHILDREN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDictTypeList() {
|
||||
// 准备参数
|
||||
DictTypeDO dictTypeDO01 = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dictTypeDO01);
|
||||
DictTypeDO dictTypeDO02 = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dictTypeDO02);
|
||||
// mock 方法
|
||||
|
||||
// 调用
|
||||
List<DictTypeDO> dictTypeDOList = dictTypeService.getDictTypeList();
|
||||
// 断言
|
||||
assertEquals(2, dictTypeDOList.size());
|
||||
assertPojoEquals(dictTypeDO01, dictTypeDOList.get(0));
|
||||
assertPojoEquals(dictTypeDO02, dictTypeDOList.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataExists_success() {
|
||||
// mock 数据
|
||||
DictTypeDO dbDictType = randomDictTypeDO();
|
||||
dictTypeMapper.insert(dbDictType);// @Sql: 先插入出一条存在的数据
|
||||
|
||||
// 调用成功
|
||||
dictTypeService.validateDictTypeExists(dbDictType.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictDataExists_notExists() {
|
||||
assertServiceException(() -> dictTypeService.validateDictTypeExists(randomLongId()), DICT_TYPE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeUnique_success() {
|
||||
// 调用,成功
|
||||
dictTypeService.validateDictTypeUnique(randomLongId(), randomString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeUnique_valueDuplicateForCreate() {
|
||||
// 准备参数
|
||||
String type = randomString();
|
||||
// mock 数据
|
||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictTypeService.validateDictTypeUnique(null, type),
|
||||
DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeUnique_valueDuplicateForUpdate() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
String type = randomString();
|
||||
// mock 数据
|
||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setType(type)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictTypeService.validateDictTypeUnique(id, type),
|
||||
DICT_TYPE_TYPE_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypNameUnique_success() {
|
||||
// 调用,成功
|
||||
dictTypeService.validateDictTypeNameUnique(randomLongId(), randomString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeNameUnique_nameDuplicateForCreate() {
|
||||
// 准备参数
|
||||
String name = randomString();
|
||||
// mock 数据
|
||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(null, name),
|
||||
DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateDictTypeNameUnique_nameDuplicateForUpdate() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
String name = randomString();
|
||||
// mock 数据
|
||||
dictTypeMapper.insert(randomDictTypeDO(o -> o.setName(name)));
|
||||
|
||||
// 调用,校验异常
|
||||
assertServiceException(() -> dictTypeService.validateDictTypeNameUnique(id, name),
|
||||
DICT_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
|
||||
// ========== 随机对象 ==========
|
||||
|
||||
@SafeVarargs
|
||||
private static DictTypeDO randomDictTypeDO(Consumer<DictTypeDO>... consumers) {
|
||||
Consumer<DictTypeDO> consumer = (o) -> {
|
||||
o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围
|
||||
};
|
||||
return randomPojo(DictTypeDO.class, ArrayUtils.append(consumer, consumers));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
public void testGetNotifyTemplatePage() {
|
||||
// mock 数据
|
||||
NotifyTemplateDO dbNotifyTemplate = randomPojo(NotifyTemplateDO.class, o -> { // 等会查询到
|
||||
o.setName("芋头");
|
||||
o.setName("鹭筑");
|
||||
o.setCode("test_01");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setCreateTime(buildTime(2022, 2, 3));
|
||||
@@ -123,7 +123,7 @@ public class NotifyTemplateServiceImplTest extends BaseDbUnitTest {
|
||||
notifyTemplateMapper.insert(cloneIgnoreId(dbNotifyTemplate, o -> o.setCreateTime(buildTime(2022, 1, 5))));
|
||||
// 准备参数
|
||||
NotifyTemplatePageReqVO reqVO = new NotifyTemplatePageReqVO();
|
||||
reqVO.setName("芋");
|
||||
reqVO.setName("鹭");
|
||||
reqVO.setCode("est_01");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 5));
|
||||
|
||||
@@ -1,331 +0,0 @@
|
||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
||||
|
||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.MenuMapper;
|
||||
import cn.iocoder.lyzsys.module.system.enums.permission.MenuTypeEnum;
|
||||
import cn.iocoder.lyzsys.module.system.service.tenant.TenantService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.lyzsys.framework.common.util.collection.SetUtils.asSet;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
|
||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@Import(MenuServiceImpl.class)
|
||||
public class MenuServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private MenuServiceImpl menuService;
|
||||
|
||||
@Resource
|
||||
private MenuMapper menuMapper;
|
||||
|
||||
@MockBean
|
||||
private PermissionService permissionService;
|
||||
@MockBean
|
||||
private TenantService tenantService;
|
||||
|
||||
@Test
|
||||
public void testCreateMenu_success() {
|
||||
// mock 数据(构造父菜单)
|
||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.MENU,
|
||||
"parent", 0L);
|
||||
menuMapper.insert(menuDO);
|
||||
Long parentId = menuDO.getId();
|
||||
// 准备参数
|
||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> {
|
||||
o.setParentId(parentId);
|
||||
o.setName("testSonName");
|
||||
o.setType(MenuTypeEnum.MENU.getType());
|
||||
}).setId(null); // 防止 id 被赋值
|
||||
Long menuId = menuService.createMenu(reqVO);
|
||||
|
||||
// 校验记录的属性是否正确
|
||||
MenuDO dbMenu = menuMapper.selectById(menuId);
|
||||
assertPojoEquals(reqVO, dbMenu, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMenu_success() {
|
||||
// mock 数据(构造父子菜单)
|
||||
MenuDO sonMenuDO = createParentAndSonMenu();
|
||||
Long sonId = sonMenuDO.getId();
|
||||
// 准备参数
|
||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> {
|
||||
o.setId(sonId);
|
||||
o.setName("testSonName"); // 修改名字
|
||||
o.setParentId(sonMenuDO.getParentId());
|
||||
o.setType(MenuTypeEnum.MENU.getType());
|
||||
});
|
||||
|
||||
// 调用
|
||||
menuService.updateMenu(reqVO);
|
||||
// 校验记录的属性是否正确
|
||||
MenuDO dbMenu = menuMapper.selectById(sonId);
|
||||
assertPojoEquals(reqVO, dbMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMenu_sonIdNotExist() {
|
||||
// 准备参数
|
||||
MenuSaveVO reqVO = randomPojo(MenuSaveVO.class);
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> menuService.updateMenu(reqVO), MENU_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMenu_success() {
|
||||
// mock 数据
|
||||
MenuDO menuDO = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menuDO);
|
||||
// 准备参数
|
||||
Long id = menuDO.getId();
|
||||
|
||||
// 调用
|
||||
menuService.deleteMenu(id);
|
||||
// 断言
|
||||
MenuDO dbMenuDO = menuMapper.selectById(id);
|
||||
assertNull(dbMenuDO);
|
||||
verify(permissionService).processMenuDeleted(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMenu_menuNotExist() {
|
||||
assertServiceException(() -> menuService.deleteMenu(randomLongId()),
|
||||
MENU_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMenu_existChildren() {
|
||||
// mock 数据(构造父子菜单)
|
||||
MenuDO sonMenu = createParentAndSonMenu();
|
||||
// 准备参数
|
||||
Long parentId = sonMenu.getParentId();
|
||||
|
||||
// 调用并断言异常
|
||||
assertServiceException(() -> menuService.deleteMenu(parentId), MENU_EXISTS_CHILDREN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuList_all() {
|
||||
// mock 数据
|
||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu100);
|
||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu101);
|
||||
// 准备参数
|
||||
|
||||
// 调用
|
||||
List<MenuDO> list = menuService.getMenuList();
|
||||
// 断言
|
||||
assertEquals(2, list.size());
|
||||
assertPojoEquals(menu100, list.get(0));
|
||||
assertPojoEquals(menu101, list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuList() {
|
||||
// mock 数据
|
||||
MenuDO menuDO = randomPojo(MenuDO.class, o -> o.setName("鹭鹭").setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
menuMapper.insert(menuDO);
|
||||
// 测试 status 不匹配
|
||||
menuMapper.insert(cloneIgnoreId(menuDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 测试 name 不匹配
|
||||
menuMapper.insert(cloneIgnoreId(menuDO, o -> o.setName("艿")));
|
||||
// 准备参数
|
||||
MenuListReqVO reqVO = new MenuListReqVO().setName("鹭").setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
|
||||
// 调用
|
||||
List<MenuDO> result = menuService.getMenuList(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, result.size());
|
||||
assertPojoEquals(menuDO, result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuListByTenant() {
|
||||
// mock 数据
|
||||
MenuDO menu100 = randomPojo(MenuDO.class, o -> o.setId(100L).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
menuMapper.insert(menu100);
|
||||
MenuDO menu101 = randomPojo(MenuDO.class, o -> o.setId(101L).setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
menuMapper.insert(menu101);
|
||||
MenuDO menu102 = randomPojo(MenuDO.class, o -> o.setId(102L).setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
menuMapper.insert(menu102);
|
||||
// mock 过滤菜单
|
||||
Set<Long> menuIds = asSet(100L, 101L);
|
||||
doNothing().when(tenantService).handleTenantMenu(argThat(handler -> {
|
||||
handler.handle(menuIds);
|
||||
return true;
|
||||
}));
|
||||
// 准备参数
|
||||
MenuListReqVO reqVO = new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
|
||||
// 调用
|
||||
List<MenuDO> result = menuService.getMenuListByTenant(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, result.size());
|
||||
assertPojoEquals(menu100, result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuIdListByPermissionFromCache() {
|
||||
// mock 数据
|
||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu100);
|
||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu101);
|
||||
// 准备参数
|
||||
String permission = menu100.getPermission();
|
||||
|
||||
// 调用
|
||||
List<Long> ids = menuService.getMenuIdListByPermissionFromCache(permission);
|
||||
// 断言
|
||||
assertEquals(1, ids.size());
|
||||
assertEquals(menu100.getId(), ids.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuList_ids() {
|
||||
// mock 数据
|
||||
MenuDO menu100 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu100);
|
||||
MenuDO menu101 = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu101);
|
||||
// 准备参数
|
||||
Collection<Long> ids = Collections.singleton(menu100.getId());
|
||||
|
||||
// 调用
|
||||
List<MenuDO> list = menuService.getMenuList(ids);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(menu100, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenu() {
|
||||
// mock 数据
|
||||
MenuDO menu = randomPojo(MenuDO.class);
|
||||
menuMapper.insert(menu);
|
||||
// 准备参数
|
||||
Long id = menu.getId();
|
||||
|
||||
// 调用
|
||||
MenuDO dbMenu = menuService.getMenu(id);
|
||||
// 断言
|
||||
assertPojoEquals(menu, dbMenu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateParentMenu_success() {
|
||||
// mock 数据
|
||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.MENU, "parent", 0L);
|
||||
menuMapper.insert(menuDO);
|
||||
// 准备参数
|
||||
Long parentId = menuDO.getId();
|
||||
|
||||
// 调用,无需断言
|
||||
menuService.validateParentMenu(parentId, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateParentMenu_canNotSetSelfToBeParent() {
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> menuService.validateParentMenu(1L, 1L),
|
||||
MENU_PARENT_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateParentMenu_parentNotExist() {
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> menuService.validateParentMenu(randomLongId(), null),
|
||||
MENU_PARENT_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateParentMenu_parentTypeError() {
|
||||
// mock 数据
|
||||
MenuDO menuDO = buildMenuDO(MenuTypeEnum.BUTTON, "parent", 0L);
|
||||
menuMapper.insert(menuDO);
|
||||
// 准备参数
|
||||
Long parentId = menuDO.getId();
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> menuService.validateParentMenu(parentId, null),
|
||||
MENU_PARENT_NOT_DIR_OR_MENU);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateMenu_Name_success() {
|
||||
// mock 父子菜单
|
||||
MenuDO sonMenu = createParentAndSonMenu();
|
||||
// 准备参数
|
||||
Long parentId = sonMenu.getParentId();
|
||||
Long otherSonMenuId = randomLongId();
|
||||
String otherSonMenuName = randomString();
|
||||
|
||||
// 调用,无需断言
|
||||
menuService.validateMenuName(parentId, otherSonMenuName, otherSonMenuId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateMenu_sonMenuNameNameDuplicate() {
|
||||
// mock 父子菜单
|
||||
MenuDO sonMenu = createParentAndSonMenu();
|
||||
// 准备参数
|
||||
Long parentId = sonMenu.getParentId();
|
||||
Long otherSonMenuId = randomLongId();
|
||||
String otherSonMenuName = sonMenu.getName(); //相同名称
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> menuService.validateMenuName(parentId, otherSonMenuName, otherSonMenuId),
|
||||
MENU_NAME_DUPLICATE);
|
||||
}
|
||||
|
||||
// ====================== 初始化方法 ======================
|
||||
|
||||
/**
|
||||
* 插入父子菜单,返回子菜单
|
||||
*
|
||||
* @return 子菜单
|
||||
*/
|
||||
private MenuDO createParentAndSonMenu() {
|
||||
// 构造父子菜单
|
||||
MenuDO parentMenuDO = buildMenuDO(MenuTypeEnum.MENU, "parent", ID_ROOT);
|
||||
menuMapper.insert(parentMenuDO);
|
||||
// 构建子菜单
|
||||
MenuDO sonMenuDO = buildMenuDO(MenuTypeEnum.MENU, "testSonName",
|
||||
parentMenuDO.getParentId());
|
||||
menuMapper.insert(sonMenuDO);
|
||||
return sonMenuDO;
|
||||
}
|
||||
|
||||
private MenuDO buildMenuDO(MenuTypeEnum type, String name, Long parentId) {
|
||||
return buildMenuDO(type, name, parentId, randomCommonStatus());
|
||||
}
|
||||
|
||||
private MenuDO buildMenuDO(MenuTypeEnum type, String name, Long parentId, Integer status) {
|
||||
return randomPojo(MenuDO.class, o -> o.setId(null).setName(name).setParentId(parentId)
|
||||
.setType(type.getType()).setStatus(status));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,527 +0,0 @@
|
||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.lyzsys.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
|
||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.MenuDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleMenuDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.UserRoleDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.RoleMenuMapper;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.UserRoleMapper;
|
||||
import cn.iocoder.lyzsys.module.system.enums.permission.DataScopeEnum;
|
||||
import cn.iocoder.lyzsys.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.lyzsys.module.system.service.user.AdminUserService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.hutool.core.collection.ListUtil.toList;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.collection.SetUtils.asSet;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.randomLongId;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@Import({PermissionServiceImpl.class})
|
||||
public class PermissionServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private PermissionServiceImpl permissionService;
|
||||
|
||||
@Resource
|
||||
private RoleMenuMapper roleMenuMapper;
|
||||
@Resource
|
||||
private UserRoleMapper userRoleMapper;
|
||||
|
||||
@MockBean
|
||||
private RoleService roleService;
|
||||
@MockBean
|
||||
private MenuService menuService;
|
||||
@MockBean
|
||||
private DeptService deptService;
|
||||
@MockBean
|
||||
private AdminUserService userService;
|
||||
|
||||
@Test
|
||||
public void testHasAnyPermissions_superAdmin() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
String[] roles = new String[]{"system:user:query", "system:user:create"};
|
||||
// mock 用户登录的角色
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L)
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
||||
// mock 其它方法
|
||||
when(roleService.hasAnySuperAdmin(eq(asSet(100L)))).thenReturn(true);
|
||||
|
||||
// 调用,并断言
|
||||
assertTrue(permissionService.hasAnyPermissions(userId, roles));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasAnyPermissions_normal() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
String[] roles = new String[]{"system:user:query", "system:user:create"};
|
||||
// mock 用户登录的角色
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L)
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
||||
// mock 菜单
|
||||
Long menuId = 1000L;
|
||||
when(menuService.getMenuIdListByPermissionFromCache(
|
||||
eq("system:user:create"))).thenReturn(singletonList(menuId));
|
||||
roleMenuMapper.insert(randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1000L));
|
||||
|
||||
// 调用,并断言
|
||||
assertTrue(permissionService.hasAnyPermissions(userId, roles));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasAnyRoles() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
String[] roles = new String[]{"yunai", "tudou"};
|
||||
// mock 用户与角色的缓存
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
||||
RoleDO role = randomPojo(RoleDO.class, o -> o.setId(100L).setCode("tudou")
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(100L)))).thenReturn(toList(role));
|
||||
|
||||
// 调用,并断言
|
||||
assertTrue(permissionService.hasAnyRoles(userId, roles));
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 角色-菜单的相关方法 ==========
|
||||
|
||||
@Test
|
||||
public void testAssignRoleMenu() {
|
||||
// 准备参数
|
||||
Long roleId = 1L;
|
||||
Set<Long> menuIds = asSet(200L, 300L);
|
||||
// mock 数据
|
||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(1L).setMenuId(100L);
|
||||
roleMenuMapper.insert(roleMenu01);
|
||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(1L).setMenuId(200L);
|
||||
roleMenuMapper.insert(roleMenu02);
|
||||
|
||||
// 调用
|
||||
permissionService.assignRoleMenu(roleId, menuIds);
|
||||
// 断言
|
||||
List<RoleMenuDO> roleMenuList = roleMenuMapper.selectList();
|
||||
assertEquals(2, roleMenuList.size());
|
||||
assertEquals(1L, roleMenuList.get(0).getRoleId());
|
||||
assertEquals(200L, roleMenuList.get(0).getMenuId());
|
||||
assertEquals(1L, roleMenuList.get(1).getRoleId());
|
||||
assertEquals(300L, roleMenuList.get(1).getMenuId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessRoleDeleted() {
|
||||
// 准备参数
|
||||
Long roleId = randomLongId();
|
||||
// mock 数据 UserRole
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setRoleId(roleId)); // 被删除
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO userRoleDO02 = randomPojo(UserRoleDO.class); // 不被删除
|
||||
userRoleMapper.insert(userRoleDO02);
|
||||
// mock 数据 RoleMenu
|
||||
RoleMenuDO roleMenuDO01 = randomPojo(RoleMenuDO.class, o -> o.setRoleId(roleId)); // 被删除
|
||||
roleMenuMapper.insert(roleMenuDO01);
|
||||
RoleMenuDO roleMenuDO02 = randomPojo(RoleMenuDO.class); // 不被删除
|
||||
roleMenuMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
permissionService.processRoleDeleted(roleId);
|
||||
// 断言数据 RoleMenuDO
|
||||
List<RoleMenuDO> dbRoleMenus = roleMenuMapper.selectList();
|
||||
assertEquals(1, dbRoleMenus.size());
|
||||
assertPojoEquals(dbRoleMenus.get(0), roleMenuDO02);
|
||||
// 断言数据 UserRoleDO
|
||||
List<UserRoleDO> dbUserRoles = userRoleMapper.selectList();
|
||||
assertEquals(1, dbUserRoles.size());
|
||||
assertPojoEquals(dbUserRoles.get(0), userRoleDO02);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMenuDeleted() {
|
||||
// 准备参数
|
||||
Long menuId = randomLongId();
|
||||
// mock 数据
|
||||
RoleMenuDO roleMenuDO01 = randomPojo(RoleMenuDO.class, o -> o.setMenuId(menuId)); // 被删除
|
||||
roleMenuMapper.insert(roleMenuDO01);
|
||||
RoleMenuDO roleMenuDO02 = randomPojo(RoleMenuDO.class); // 不被删除
|
||||
roleMenuMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
permissionService.processMenuDeleted(menuId);
|
||||
// 断言数据
|
||||
List<RoleMenuDO> dbRoleMenus = roleMenuMapper.selectList();
|
||||
assertEquals(1, dbRoleMenus.size());
|
||||
assertPojoEquals(dbRoleMenus.get(0), roleMenuDO02);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleMenuIds_superAdmin() {
|
||||
// 准备参数
|
||||
Long roleId = 100L;
|
||||
// mock 方法
|
||||
when(roleService.hasAnySuperAdmin(eq(singleton(100L)))).thenReturn(true);
|
||||
List<MenuDO> menuList = singletonList(randomPojo(MenuDO.class).setId(1L));
|
||||
when(menuService.getMenuList()).thenReturn(menuList);
|
||||
|
||||
// 调用
|
||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(roleId);
|
||||
// 断言
|
||||
assertEquals(singleton(1L), menuIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleMenuIds_normal() {
|
||||
// 准备参数
|
||||
Long roleId = 100L;
|
||||
// mock 数据
|
||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1L);
|
||||
roleMenuMapper.insert(roleMenu01);
|
||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(2L);
|
||||
roleMenuMapper.insert(roleMenu02);
|
||||
|
||||
// 调用
|
||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(roleId);
|
||||
// 断言
|
||||
assertEquals(asSet(1L, 2L), menuIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMenuRoleIdListByMenuIdFromCache() {
|
||||
// 准备参数
|
||||
Long menuId = 1L;
|
||||
// mock 数据
|
||||
RoleMenuDO roleMenu01 = randomPojo(RoleMenuDO.class).setRoleId(100L).setMenuId(1L);
|
||||
roleMenuMapper.insert(roleMenu01);
|
||||
RoleMenuDO roleMenu02 = randomPojo(RoleMenuDO.class).setRoleId(200L).setMenuId(1L);
|
||||
roleMenuMapper.insert(roleMenu02);
|
||||
|
||||
// 调用
|
||||
Set<Long> roleIds = permissionService.getMenuRoleIdListByMenuIdFromCache(menuId);
|
||||
// 断言
|
||||
assertEquals(asSet(100L, 200L), roleIds);
|
||||
}
|
||||
|
||||
// ========== 用户-角色的相关方法 ==========
|
||||
|
||||
@Test
|
||||
public void testAssignUserRole() {
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
Set<Long> roleIds = asSet(200L, 300L);
|
||||
// mock 数据
|
||||
UserRoleDO userRole01 = randomPojo(UserRoleDO.class).setUserId(1L).setRoleId(100L);
|
||||
userRoleMapper.insert(userRole01);
|
||||
UserRoleDO userRole02 = randomPojo(UserRoleDO.class).setUserId(1L).setRoleId(200L);
|
||||
userRoleMapper.insert(userRole02);
|
||||
|
||||
// 调用
|
||||
permissionService.assignUserRole(userId, roleIds);
|
||||
// 断言
|
||||
List<UserRoleDO> userRoleDOList = userRoleMapper.selectList();
|
||||
assertEquals(2, userRoleDOList.size());
|
||||
assertEquals(1L, userRoleDOList.get(0).getUserId());
|
||||
assertEquals(200L, userRoleDOList.get(0).getRoleId());
|
||||
assertEquals(1L, userRoleDOList.get(1).getUserId());
|
||||
assertEquals(300L, userRoleDOList.get(1).getRoleId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessUserDeleted() {
|
||||
// 准备参数
|
||||
Long userId = randomLongId();
|
||||
// mock 数据
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(userId)); // 被删除
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO userRoleDO02 = randomPojo(UserRoleDO.class); // 不被删除
|
||||
userRoleMapper.insert(userRoleDO02);
|
||||
|
||||
// 调用
|
||||
permissionService.processUserDeleted(userId);
|
||||
// 断言数据
|
||||
List<UserRoleDO> dbUserRoles = userRoleMapper.selectList();
|
||||
assertEquals(1, dbUserRoles.size());
|
||||
assertPojoEquals(dbUserRoles.get(0), userRoleDO02);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserRoleIdListByUserId() {
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 数据
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
||||
userRoleMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
Set<Long> result = permissionService.getUserRoleIdListByUserId(userId);
|
||||
// 断言
|
||||
assertEquals(asSet(10L, 20L), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserRoleIdListByUserIdFromCache() {
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 数据
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
||||
userRoleMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
Set<Long> result = permissionService.getUserRoleIdListByUserIdFromCache(userId);
|
||||
// 断言
|
||||
assertEquals(asSet(10L, 20L), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserRoleIdsFromCache() {
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 数据
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(20L));
|
||||
userRoleMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
Set<Long> result = permissionService.getUserRoleIdListByUserIdFromCache(userId);
|
||||
// 断言
|
||||
assertEquals(asSet(10L, 20L), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserRoleIdListByRoleId() {
|
||||
// 准备参数
|
||||
Collection<Long> roleIds = asSet(10L, 20L);
|
||||
// mock 数据
|
||||
UserRoleDO userRoleDO01 = randomPojo(UserRoleDO.class, o -> o.setUserId(1L).setRoleId(10L));
|
||||
userRoleMapper.insert(userRoleDO01);
|
||||
UserRoleDO roleMenuDO02 = randomPojo(UserRoleDO.class, o -> o.setUserId(2L).setRoleId(20L));
|
||||
userRoleMapper.insert(roleMenuDO02);
|
||||
|
||||
// 调用
|
||||
Set<Long> result = permissionService.getUserRoleIdListByRoleId(roleIds);
|
||||
// 断言
|
||||
assertEquals(asSet(1L, 2L), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnableUserRoleListByUserIdFromCache() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户登录的角色
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(100L));
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(200L));
|
||||
RoleDO role01 = randomPojo(RoleDO.class, o -> o.setId(100L)
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
RoleDO role02 = randomPojo(RoleDO.class, o -> o.setId(200L)
|
||||
.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(asSet(100L, 200L))))
|
||||
.thenReturn(toList(role01, role02));
|
||||
|
||||
// 调用
|
||||
List<RoleDO> result = permissionService.getEnableUserRoleListByUserIdFromCache(userId);
|
||||
// 断言
|
||||
assertEquals(1, result.size());
|
||||
assertPojoEquals(role01, result.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 用户-部门的相关方法 ==========
|
||||
|
||||
@Test
|
||||
public void testAssignRoleDataScope() {
|
||||
// 准备参数
|
||||
Long roleId = 1L;
|
||||
Integer dataScope = 2;
|
||||
Set<Long> dataScopeDeptIds = asSet(10L, 20L);
|
||||
|
||||
// 调用
|
||||
permissionService.assignRoleDataScope(roleId, dataScope, dataScopeDeptIds);
|
||||
// 断言
|
||||
verify(roleService).updateRoleDataScope(eq(roleId), eq(dataScope), eq(dataScopeDeptIds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeptDataPermission_All() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户的角色编号
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
||||
// mock 获得用户的角色
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.ALL.getScope())
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
||||
|
||||
// 调用
|
||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
||||
// 断言
|
||||
assertTrue(result.getAll());
|
||||
assertFalse(result.getSelf());
|
||||
assertTrue(CollUtil.isEmpty(result.getDeptIds()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeptDataPermission_DeptCustom() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户的角色编号
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
||||
// mock 获得用户的角色
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_CUSTOM.getScope())
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
||||
// mock 部门的返回
|
||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
||||
|
||||
// 调用
|
||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
||||
// 断言
|
||||
assertFalse(result.getAll());
|
||||
assertFalse(result.getSelf());
|
||||
assertEquals(roleDO.getDataScopeDeptIds().size() + 1, result.getDeptIds().size());
|
||||
assertTrue(CollUtil.containsAll(result.getDeptIds(), roleDO.getDataScopeDeptIds()));
|
||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeptDataPermission_DeptOnly() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户的角色编号
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
||||
// mock 获得用户的角色
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_ONLY.getScope())
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
||||
// mock 部门的返回
|
||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
||||
|
||||
// 调用
|
||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
||||
// 断言
|
||||
assertFalse(result.getAll());
|
||||
assertFalse(result.getSelf());
|
||||
assertEquals(1, result.getDeptIds().size());
|
||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeptDataPermission_DeptAndChild() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户的角色编号
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
||||
// mock 获得用户的角色
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.DEPT_AND_CHILD.getScope())
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
||||
// mock 部门的返回
|
||||
when(userService.getUser(eq(1L))).thenReturn(new AdminUserDO().setDeptId(3L),
|
||||
null, null); // 最后返回 null 的目的,看看会不会重复调用
|
||||
// mock 方法(部门)
|
||||
DeptDO deptDO = randomPojo(DeptDO.class);
|
||||
when(deptService.getChildDeptIdListFromCache(eq(3L))).thenReturn(singleton(deptDO.getId()));
|
||||
|
||||
// 调用
|
||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
||||
// 断言
|
||||
assertFalse(result.getAll());
|
||||
assertFalse(result.getSelf());
|
||||
assertEquals(2, result.getDeptIds().size());
|
||||
assertTrue(CollUtil.contains(result.getDeptIds(), deptDO.getId()));
|
||||
assertTrue(CollUtil.contains(result.getDeptIds(), 3L));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeptDataPermission_Self() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(PermissionServiceImpl.class)))
|
||||
.thenReturn(permissionService);
|
||||
|
||||
// 准备参数
|
||||
Long userId = 1L;
|
||||
// mock 用户的角色编号
|
||||
userRoleMapper.insert(randomPojo(UserRoleDO.class).setUserId(userId).setRoleId(2L));
|
||||
// mock 获得用户的角色
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setDataScope(DataScopeEnum.SELF.getScope())
|
||||
.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
when(roleService.getRoleListFromCache(eq(singleton(2L)))).thenReturn(toList(roleDO));
|
||||
|
||||
// 调用
|
||||
DeptDataPermissionRespDTO result = permissionService.getDeptDataPermission(userId);
|
||||
// 断言
|
||||
assertFalse(result.getAll());
|
||||
assertTrue(result.getSelf());
|
||||
assertTrue(CollUtil.isEmpty(result.getDeptIds()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
package cn.iocoder.lyzsys.module.system.service.permission;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.lyzsys.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.lyzsys.framework.test.core.ut.BaseDbUnitTest;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.role.RolePageReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.controller.admin.permission.vo.role.RoleSaveReqVO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.dataobject.permission.RoleDO;
|
||||
import cn.iocoder.lyzsys.module.system.dal.mysql.permission.RoleMapper;
|
||||
import cn.iocoder.lyzsys.module.system.enums.permission.DataScopeEnum;
|
||||
import cn.iocoder.lyzsys.module.system.enums.permission.RoleTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomEle;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.date.LocalDateTimeUtils.buildTime;
|
||||
import static cn.iocoder.lyzsys.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static cn.iocoder.lyzsys.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.lyzsys.module.system.enums.ErrorCodeConstants.*;
|
||||
import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@Import(RoleServiceImpl.class)
|
||||
public class RoleServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private RoleServiceImpl roleService;
|
||||
|
||||
@Resource
|
||||
private RoleMapper roleMapper;
|
||||
|
||||
@MockBean
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Test
|
||||
public void testCreateRole() {
|
||||
// 准备参数
|
||||
RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class)
|
||||
.setId(null) // 防止 id 被赋值
|
||||
.setStatus(randomCommonStatus());
|
||||
|
||||
// 调用
|
||||
Long roleId = roleService.createRole(reqVO, null);
|
||||
// 断言
|
||||
RoleDO roleDO = roleMapper.selectById(roleId);
|
||||
assertPojoEquals(reqVO, roleDO, "id");
|
||||
assertEquals(RoleTypeEnum.CUSTOM.getType(), roleDO.getType());
|
||||
assertEquals(DataScopeEnum.ALL.getScope(), roleDO.getDataScope());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRole() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
Long id = roleDO.getId();
|
||||
RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class, o -> o.setId(id)
|
||||
.setStatus(randomCommonStatus()));
|
||||
|
||||
// 调用
|
||||
roleService.updateRole(reqVO);
|
||||
// 断言
|
||||
RoleDO newRoleDO = roleMapper.selectById(id);
|
||||
assertPojoEquals(reqVO, newRoleDO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateRoleDataScope() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
Long id = roleDO.getId();
|
||||
Integer dataScope = randomEle(DataScopeEnum.values()).getScope();
|
||||
Set<Long> dataScopeRoleIds = randomSet(Long.class);
|
||||
|
||||
// 调用
|
||||
roleService.updateRoleDataScope(id, dataScope, dataScopeRoleIds);
|
||||
// 断言
|
||||
RoleDO dbRoleDO = roleMapper.selectById(id);
|
||||
assertEquals(dataScope, dbRoleDO.getDataScope());
|
||||
assertEquals(dataScopeRoleIds, dbRoleDO.getDataScopeDeptIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteRole() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 参数准备
|
||||
Long id = roleDO.getId();
|
||||
|
||||
// 调用
|
||||
roleService.deleteRole(id);
|
||||
// 断言
|
||||
assertNull(roleMapper.selectById(id));
|
||||
// verify 删除相关数据
|
||||
verify(permissionService).processRoleDeleted(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleDuplicate_success() {
|
||||
// 调用,不会抛异常
|
||||
roleService.validateRoleDuplicate(randomString(), randomString(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleDuplicate_nameDuplicate() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setName("role_name"));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
String name = "role_name";
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> roleService.validateRoleDuplicate(name, randomString(), null),
|
||||
ROLE_NAME_DUPLICATE, name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleDuplicate_codeDuplicate() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setCode("code"));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
String code = "code";
|
||||
|
||||
// 调用,并断言异常
|
||||
assertServiceException(() -> roleService.validateRoleDuplicate(randomString(), code, null),
|
||||
ROLE_CODE_DUPLICATE, code);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUpdateRole_success() {
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.CUSTOM.getType()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
Long id = roleDO.getId();
|
||||
|
||||
// 调用,无异常
|
||||
roleService.validateRoleForUpdate(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUpdateRole_roleIdNotExist() {
|
||||
assertServiceException(() -> roleService.validateRoleForUpdate(randomLongId()), ROLE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUpdateRole_systemRoleCanNotBeUpdate() {
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setType(RoleTypeEnum.SYSTEM.getType()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
Long id = roleDO.getId();
|
||||
|
||||
assertServiceException(() -> roleService.validateRoleForUpdate(id),
|
||||
ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRole() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class);
|
||||
roleMapper.insert(roleDO);
|
||||
// 参数准备
|
||||
Long id = roleDO.getId();
|
||||
|
||||
// 调用
|
||||
RoleDO dbRoleDO = roleService.getRole(id);
|
||||
// 断言
|
||||
assertPojoEquals(roleDO, dbRoleDO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleFromCache() {
|
||||
// mock 数据(缓存)
|
||||
RoleDO roleDO = randomPojo(RoleDO.class);
|
||||
roleMapper.insert(roleDO);
|
||||
// 参数准备
|
||||
Long id = roleDO.getId();
|
||||
|
||||
// 调用
|
||||
RoleDO dbRoleDO = roleService.getRoleFromCache(id);
|
||||
// 断言
|
||||
assertPojoEquals(roleDO, dbRoleDO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleListByStatus() {
|
||||
// mock 数据
|
||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
roleMapper.insert(dbRole01);
|
||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
roleMapper.insert(dbRole02);
|
||||
|
||||
// 调用
|
||||
List<RoleDO> list = roleService.getRoleListByStatus(
|
||||
singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleList() {
|
||||
// mock 数据
|
||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
roleMapper.insert(dbRole01);
|
||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
roleMapper.insert(dbRole02);
|
||||
|
||||
// 调用
|
||||
List<RoleDO> list = roleService.getRoleList();
|
||||
// 断言
|
||||
assertEquals(2, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
assertPojoEquals(dbRole02, list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleList_ids() {
|
||||
// mock 数据
|
||||
RoleDO dbRole01 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
roleMapper.insert(dbRole01);
|
||||
RoleDO dbRole02 = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
roleMapper.insert(dbRole02);
|
||||
// 准备参数
|
||||
Collection<Long> ids = singleton(dbRole01.getId());
|
||||
|
||||
// 调用
|
||||
List<RoleDO> list = roleService.getRoleList(ids);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole01, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRoleListFromCache() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
||||
.thenReturn(roleService);
|
||||
|
||||
// mock 数据
|
||||
RoleDO dbRole = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
roleMapper.insert(dbRole);
|
||||
// 测试 id 不匹配
|
||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> {}));
|
||||
// 准备参数
|
||||
Collection<Long> ids = singleton(dbRole.getId());
|
||||
|
||||
// 调用
|
||||
List<RoleDO> list = roleService.getRoleListFromCache(ids);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbRole, list.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRolePage() {
|
||||
// mock 数据
|
||||
RoleDO dbRole = randomPojo(RoleDO.class, o -> { // 等会查询到
|
||||
o.setName("土豆");
|
||||
o.setCode("tudou");
|
||||
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
o.setCreateTime(buildTime(2022, 2, 8));
|
||||
});
|
||||
roleMapper.insert(dbRole);
|
||||
// 测试 name 不匹配
|
||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setName("红薯")));
|
||||
// 测试 code 不匹配
|
||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCode("hong")));
|
||||
// 测试 createTime 不匹配
|
||||
roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCreateTime(buildTime(2022, 2, 16))));
|
||||
// 准备参数
|
||||
RolePageReqVO reqVO = new RolePageReqVO();
|
||||
reqVO.setName("土豆");
|
||||
reqVO.setCode("tu");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12));
|
||||
|
||||
// 调用
|
||||
PageResult<RoleDO> pageResult = roleService.getRolePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbRole, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasAnySuperAdmin_true() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
||||
.thenReturn(roleService);
|
||||
|
||||
// mock 数据
|
||||
RoleDO dbRole = randomPojo(RoleDO.class).setCode("super_admin");
|
||||
roleMapper.insert(dbRole);
|
||||
// 准备参数
|
||||
Long id = dbRole.getId();
|
||||
|
||||
// 调用,并调用
|
||||
assertTrue(roleService.hasAnySuperAdmin(singletonList(id)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasAnySuperAdmin_false() {
|
||||
try (MockedStatic<SpringUtil> springUtilMockedStatic = mockStatic(SpringUtil.class)) {
|
||||
springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class)))
|
||||
.thenReturn(roleService);
|
||||
|
||||
// mock 数据
|
||||
RoleDO dbRole = randomPojo(RoleDO.class).setCode("tenant_admin");
|
||||
roleMapper.insert(dbRole);
|
||||
// 准备参数
|
||||
Long id = dbRole.getId();
|
||||
|
||||
// 调用,并调用
|
||||
assertFalse(roleService.hasAnySuperAdmin(singletonList(id)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleList_success() {
|
||||
// mock 数据
|
||||
RoleDO roleDO = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||
roleMapper.insert(roleDO);
|
||||
// 准备参数
|
||||
List<Long> ids = singletonList(roleDO.getId());
|
||||
|
||||
// 调用,无需断言
|
||||
roleService.validateRoleList(ids);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleList_notFound() {
|
||||
// 准备参数
|
||||
List<Long> ids = singletonList(randomLongId());
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> roleService.validateRoleList(ids), ROLE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateRoleList_notEnable() {
|
||||
// mock 数据
|
||||
RoleDO RoleDO = randomPojo(RoleDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||
roleMapper.insert(RoleDO);
|
||||
// 准备参数
|
||||
List<Long> ids = singletonList(RoleDO.getId());
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> roleService.validateRoleList(ids), ROLE_IS_DISABLE, RoleDO.getName());
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
|
||||
public void testGetSocialClientPage() {
|
||||
// mock 数据
|
||||
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class, o -> { // 等会查询到
|
||||
o.setName("芋头");
|
||||
o.setName("鹭筑");
|
||||
o.setSocialType(SocialTypeEnum.GITEE.getType());
|
||||
o.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
o.setClientId("lyzsys");
|
||||
@@ -455,7 +455,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
|
||||
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||
// 准备参数
|
||||
SocialClientPageReqVO reqVO = new SocialClientPageReqVO();
|
||||
reqVO.setName("芋");
|
||||
reqVO.setName("鹭");
|
||||
reqVO.setSocialType(SocialTypeEnum.GITEE.getType());
|
||||
reqVO.setUserType(UserTypeEnum.ADMIN.getValue());
|
||||
reqVO.setClientId("lyz");
|
||||
|
||||
@@ -308,7 +308,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
||||
// 准备参数
|
||||
TenantPageReqVO reqVO = new TenantPageReqVO();
|
||||
reqVO.setName("lyz");
|
||||
reqVO.setContactName("艿");
|
||||
reqVO.setContactName("鹭");
|
||||
reqVO.setContactMobile("1560");
|
||||
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24));
|
||||
|
||||
@@ -687,12 +687,12 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
@Test
|
||||
public void testGetUserListByNickname() {
|
||||
// mock 数据
|
||||
AdminUserDO user = randomAdminUserDO(o -> o.setNickname("芋头"));
|
||||
AdminUserDO user = randomAdminUserDO(o -> o.setNickname("鹭筑"));
|
||||
userMapper.insert(user);
|
||||
// 测试 nickname 不匹配
|
||||
userMapper.insert(randomAdminUserDO(o -> o.setNickname("源码")));
|
||||
// 准备参数
|
||||
String nickname = "芋";
|
||||
String nickname = "鹭";
|
||||
|
||||
// 调用
|
||||
List<AdminUserDO> result = userService.getUserListByNickname(nickname);
|
||||
|
||||
Reference in New Issue
Block a user