infra:完善 config 的单元测试

This commit is contained in:
YunaiV
2023-02-04 00:57:16 +08:00
parent df65b88fe9
commit f620bc3fec
6 changed files with 70 additions and 57 deletions

View File

@@ -31,6 +31,7 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
@@ -99,7 +100,7 @@ public class UserProfileController {
@ApiOperation("上传用户个人头像")
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
throw exception(FILE_IS_EMPTY);
}
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
return success(avatar);

View File

@@ -31,6 +31,7 @@ import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
@@ -118,7 +119,7 @@ public class MenuServiceImpl implements MenuService {
public void updateMenu(MenuUpdateReqVO reqVO) {
// 校验更新的菜单是否存在
if (menuMapper.selectById(reqVO.getId()) == null) {
throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS);
throw exception(MENU_NOT_EXISTS);
}
// 校验父菜单存在
validateParentMenu(reqVO.getParentId(), reqVO.getId());
@@ -138,11 +139,11 @@ public class MenuServiceImpl implements MenuService {
public void deleteMenu(Long menuId) {
// 校验是否还有子菜单
if (menuMapper.selectCountByParentId(menuId) > 0) {
throw ServiceExceptionUtil.exception(MENU_EXISTS_CHILDREN);
throw exception(MENU_EXISTS_CHILDREN);
}
// 校验删除的菜单是否存在
if (menuMapper.selectById(menuId) == null) {
throw ServiceExceptionUtil.exception(MENU_NOT_EXISTS);
throw exception(MENU_NOT_EXISTS);
}
// 标记删除
menuMapper.deleteById(menuId);
@@ -229,17 +230,17 @@ public class MenuServiceImpl implements MenuService {
}
// 不能设置自己为父菜单
if (parentId.equals(childId)) {
throw ServiceExceptionUtil.exception(MENU_PARENT_ERROR);
throw exception(MENU_PARENT_ERROR);
}
MenuDO menu = menuMapper.selectById(parentId);
// 父菜单不存在
if (menu == null) {
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_EXISTS);
throw exception(MENU_PARENT_NOT_EXISTS);
}
// 父菜单必须是目录或者菜单类型
if (!MenuTypeEnum.DIR.getType().equals(menu.getType())
&& !MenuTypeEnum.MENU.getType().equals(menu.getType())) {
throw ServiceExceptionUtil.exception(MENU_PARENT_NOT_DIR_OR_MENU);
throw exception(MENU_PARENT_NOT_DIR_OR_MENU);
}
}
@@ -260,10 +261,10 @@ public class MenuServiceImpl implements MenuService {
}
// 如果 id 为空,说明不用比较是否为相同 id 的菜单
if (id == null) {
throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE);
throw exception(MENU_NAME_DUPLICATE);
}
if (!menu.getId().equals(id)) {
throw ServiceExceptionUtil.exception(MENU_NAME_DUPLICATE);
throw exception(MENU_NAME_DUPLICATE);
}
}

View File

@@ -39,7 +39,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
* 短信模板 Service 实现类
*
* @author zzf
* @date 2021/1/25 9:25
*/
@Service
@Slf4j