Merge branch 'master' of gitee.com:zhijiantianya/ruoyi-vue-pro into feature/ut-job
commit
08bc389ba5
@ -0,0 +1,4 @@
|
||||
config.stopBubbling = true
|
||||
lombok.tostring.callsuper=true
|
||||
lombok.equalsandhashcode.callsuper=true
|
||||
lombok.accessors.chain=true
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,92 +1,80 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user;
|
||||
|
||||
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserProfileUpdateReqVO;
|
||||
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
|
||||
import cn.iocoder.dashboard.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
|
||||
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
|
||||
import cn.iocoder.dashboard.modules.system.service.user.SysUserService;
|
||||
import cn.iocoder.dashboard.util.collection.CollectionUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
/**
|
||||
* @author niudehua
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/user/profile")
|
||||
@Api(tags = "用户个人中心")
|
||||
@Slf4j
|
||||
public class SysUserProfileController {
|
||||
|
||||
// /**
|
||||
// * 个人信息
|
||||
// */
|
||||
// @GetMapping
|
||||
// public AjaxResult profile()
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// SysUser user = loginUser.getUser();
|
||||
// AjaxResult ajax = AjaxResult.success(user);
|
||||
// ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
|
||||
// ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
|
||||
// return ajax;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改用户
|
||||
// */
|
||||
// @Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
// @PutMapping
|
||||
// public AjaxResult updateProfile(@RequestBody SysUser user)
|
||||
// {
|
||||
// if (userService.updateUserProfile(user) > 0)
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// // 更新缓存用户信息
|
||||
// loginUser.getUser().setNickName(user.getNickName());
|
||||
// loginUser.getUser().setPhonenumber(user.getPhonenumber());
|
||||
// loginUser.getUser().setEmail(user.getEmail());
|
||||
// loginUser.getUser().setSex(user.getSex());
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return AjaxResult.success();
|
||||
// }
|
||||
// return AjaxResult.error("修改个人信息异常,请联系管理员");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 重置密码
|
||||
// */
|
||||
// @Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
// @PutMapping("/updatePwd")
|
||||
// public AjaxResult updatePwd(String oldPassword, String newPassword)
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// String userName = loginUser.getUsername();
|
||||
// String password = loginUser.getPassword();
|
||||
// if (!SecurityUtils.matchesPassword(oldPassword, password))
|
||||
// {
|
||||
// return AjaxResult.error("修改密码失败,旧密码错误");
|
||||
// }
|
||||
// if (SecurityUtils.matchesPassword(newPassword, password))
|
||||
// {
|
||||
// return AjaxResult.error("新密码不能与旧密码相同");
|
||||
// }
|
||||
// if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0)
|
||||
// {
|
||||
// // 更新缓存用户密码
|
||||
// loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return AjaxResult.success();
|
||||
// }
|
||||
// return AjaxResult.error("修改密码异常,请联系管理员");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 头像上传
|
||||
// */
|
||||
// @Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||
// @PostMapping("/avatar")
|
||||
// public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
||||
// {
|
||||
// if (!file.isEmpty())
|
||||
// {
|
||||
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
// String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
||||
// if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||
// {
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// ajax.put("imgUrl", avatar);
|
||||
// // 更新缓存用户头像
|
||||
// loginUser.getUser().setAvatar(avatar);
|
||||
// tokenService.setLoginUser(loginUser);
|
||||
// return ajax;
|
||||
// }
|
||||
// }
|
||||
// return AjaxResult.error("上传图片异常,请联系管理员");
|
||||
// }
|
||||
@Resource
|
||||
private SysUserService userService;
|
||||
@Resource
|
||||
private SysPermissionService permissionService;
|
||||
@Resource
|
||||
private SysRoleService roleService;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得登录用户信息")
|
||||
public CommonResult<SysUserProfileRespVO> profile() {
|
||||
// 获取用户信息
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
SysUserDO user = userService.getUser(userId);
|
||||
SysUserProfileRespVO userProfileRespVO = SysUserConvert.INSTANCE.convert03(user);
|
||||
List<SysRoleDO> userRoles = roleService.listRolesFromCache(permissionService.listUserRoleIs(userId));
|
||||
userProfileRespVO.setRoles(CollectionUtils.convertSet(userRoles, SysUserConvert.INSTANCE::convert));
|
||||
return success(userProfileRespVO);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改用户个人信息")
|
||||
public CommonResult<Boolean> updateProfile(@RequestBody SysUserProfileUpdateReqVO reqVO, HttpServletRequest request) {
|
||||
userService.updateUserProfile(reqVO);
|
||||
SecurityFrameworkUtils.setLoginUser(SysAuthConvert.INSTANCE.convert(reqVO), request);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/upload-avatar")
|
||||
@ApiOperation("上传用户个人头像")
|
||||
public CommonResult<Boolean> uploadAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
|
||||
}
|
||||
userService.updateAvatar(SecurityFrameworkUtils.getLoginUserId(), file.getInputStream());
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user.vo.user;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@ApiModel("用户个人中心信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysUserProfileRespVO extends SysUserRespVO {
|
||||
|
||||
/**
|
||||
* 所属角色
|
||||
*/
|
||||
@ApiModelProperty(value = "所属角色", required = true, example = "123456")
|
||||
private Set<Role> roles;
|
||||
|
||||
@ApiModel("角色")
|
||||
@Data
|
||||
public static class Role {
|
||||
|
||||
@ApiModelProperty(value = "角色编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "角色名称", required = true, example = "普通角色")
|
||||
private String name;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.user.vo.user;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@ApiModel("用户个人信息更新 Request VO")
|
||||
@Data
|
||||
public class SysUserProfileUpdateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "1024")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "用户昵称", required = true, example = "芋艿")
|
||||
@Size(max = 30, message = "用户昵称长度不能超过30个字符")
|
||||
private String nickname;
|
||||
|
||||
@ApiModelProperty(value = "用户邮箱", example = "yudao@iocoder.cn")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(max = 50, message = "邮箱长度不能超过50个字符")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "手机号码", example = "15601691300")
|
||||
@Size(max = 11, message = "手机号码长度不能超过11个字符")
|
||||
private String mobile;
|
||||
|
||||
@ApiModelProperty(value = "用户性别", example = "1", notes = "参见 SysSexEnum 枚举类")
|
||||
private Integer sex;
|
||||
|
||||
@ApiModelProperty(value = "用户头像", example = "http://www.iocoder.cn/xxx.png")
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty(value = "旧密码", required = true, example = "123456")
|
||||
private String oldPassword;
|
||||
|
||||
@ApiModelProperty(value = "新密码", required = true, example = "654321")
|
||||
private String newPassword;
|
||||
|
||||
}
|
||||
@ -0,0 +1,177 @@
|
||||
package cn.iocoder.dashboard.modules.infra.service.logger;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.logger.apilog.core.service.dto.ApiAccessLogCreateDTO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogExportReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.controller.logger.vo.apiaccesslog.InfApiAccessLogPageReqVO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
|
||||
import cn.iocoder.dashboard.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
|
||||
import cn.iocoder.dashboard.modules.infra.service.logger.impl.InfApiAccessLogServiceImpl;
|
||||
import cn.iocoder.dashboard.util.RandomUtils;
|
||||
import cn.iocoder.dashboard.util.object.ObjectUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static cn.iocoder.dashboard.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.buildTime;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* {@link InfApiAccessLogServiceImpl} 单元测试
|
||||
*/
|
||||
@Import(InfApiAccessLogServiceImpl.class)
|
||||
public class InfApiAccessLogServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogService infApiAccessLogServiceImpl;
|
||||
|
||||
@Resource
|
||||
private InfApiAccessLogMapper infApiAccessLogMapper;
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateApiAccessLogAsync() throws Exception {
|
||||
ApiAccessLogCreateDTO createDTO = RandomUtils.randomPojo(
|
||||
ApiAccessLogCreateDTO.class,
|
||||
dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue())
|
||||
);
|
||||
|
||||
// 执行service方法
|
||||
Future<Boolean> future = infApiAccessLogServiceImpl.createApiAccessLogAsync(createDTO);
|
||||
|
||||
// 等异步执行完
|
||||
future.get();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = infApiAccessLogMapper.selectOne(null);
|
||||
// 断言
|
||||
assertNotNull(infApiAccessLogDO);
|
||||
// 断言,忽略基本字段
|
||||
assertPojoEquals(createDTO, infApiAccessLogDO);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogPage() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogPageReqVO reqVO = new InfApiAccessLogPageReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
PageResult<InfApiAccessLogDO> pageResult = infApiAccessLogServiceImpl.getApiAccessLogPage(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(infApiAccessLogDO, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApiAccessLogList() {
|
||||
// 构造测试数据
|
||||
long userId = 2233L;
|
||||
int userType = UserTypeEnum.ADMIN.getValue();
|
||||
String applicationName = "ruoyi-test";
|
||||
String requestUrl = "foo";
|
||||
Date beginTime = buildTime(2021, 3, 13);
|
||||
int duration = 1000;
|
||||
int resultCode = GlobalErrorCodeConstants.SUCCESS.getCode();
|
||||
|
||||
InfApiAccessLogDO infApiAccessLogDO = RandomUtils.randomPojo(InfApiAccessLogDO.class, dto -> {
|
||||
dto.setUserId(userId);
|
||||
dto.setUserType(userType);
|
||||
dto.setApplicationName(applicationName);
|
||||
dto.setRequestUrl(requestUrl);
|
||||
dto.setBeginTime(beginTime);
|
||||
dto.setDuration(duration);
|
||||
dto.setResultCode(resultCode);
|
||||
});
|
||||
infApiAccessLogMapper.insert(infApiAccessLogDO);
|
||||
|
||||
// 下面几个都是不匹配的数据
|
||||
// userId 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserId(3344L)));
|
||||
// userType
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setUserType(UserTypeEnum.MEMBER.getValue())));
|
||||
// applicationName 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setApplicationName("test")));
|
||||
// requestUrl 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setRequestUrl("bar")));
|
||||
// 构造一个早期时间 2021-02-06 00:00:00
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setBeginTime(buildTime(2021, 2, 6))));
|
||||
// duration 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setDuration(100)));
|
||||
// resultCode 不同的
|
||||
infApiAccessLogMapper.insert(ObjectUtils.clone(infApiAccessLogDO, logDO -> logDO.setResultCode(2)));
|
||||
|
||||
// 构造调用参数
|
||||
InfApiAccessLogExportReqVO reqVO = new InfApiAccessLogExportReqVO();
|
||||
reqVO.setUserId(userId);
|
||||
reqVO.setUserType(userType);
|
||||
reqVO.setApplicationName(applicationName);
|
||||
reqVO.setRequestUrl(requestUrl);
|
||||
reqVO.setBeginBeginTime(buildTime(2021, 3, 12));
|
||||
reqVO.setEndBeginTime(buildTime(2021, 3, 14));
|
||||
reqVO.setDuration(duration);
|
||||
reqVO.setResultCode(resultCode);
|
||||
|
||||
// 调用service方法
|
||||
List<InfApiAccessLogDO> list = infApiAccessLogServiceImpl.getApiAccessLogList(reqVO);
|
||||
|
||||
// 断言,只查到了一条符合条件的
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(infApiAccessLogDO, list.get(0));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package cn.iocoder.dashboard.modules.system.service.common;
|
||||
|
||||
import cn.iocoder.dashboard.BaseRedisUnitTest;
|
||||
import cn.iocoder.dashboard.framework.captcha.config.CaptchaProperties;
|
||||
import cn.iocoder.dashboard.modules.system.controller.common.vo.SysCaptchaImageRespVO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.redis.common.SysCaptchaRedisDAO;
|
||||
import cn.iocoder.dashboard.modules.system.service.common.impl.SysCaptchaServiceImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Import({SysCaptchaServiceImpl.class, CaptchaProperties.class, SysCaptchaRedisDAO.class})
|
||||
public class SysCaptchaServiceTest extends BaseRedisUnitTest {
|
||||
|
||||
@Resource
|
||||
private SysCaptchaServiceImpl captchaService;
|
||||
|
||||
@Resource
|
||||
private SysCaptchaRedisDAO captchaRedisDAO;
|
||||
@Resource
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaImage() {
|
||||
// 调用
|
||||
SysCaptchaImageRespVO respVO = captchaService.getCaptchaImage();
|
||||
// 断言
|
||||
assertNotNull(respVO.getUuid());
|
||||
assertNotNull(respVO.getImg());
|
||||
String captchaCode = captchaRedisDAO.get(respVO.getUuid());
|
||||
assertNotNull(captchaCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
String resultCode = captchaService.getCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertEquals(code, resultCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCaptchaCode() {
|
||||
// 准备参数
|
||||
String uuid = randomString();
|
||||
String code = randomString();
|
||||
// mock 数据
|
||||
captchaRedisDAO.set(uuid, code, captchaProperties.getTimeout());
|
||||
|
||||
// 调用
|
||||
captchaService.deleteCaptchaCode(uuid);
|
||||
// 断言
|
||||
assertNull(captchaRedisDAO.get(uuid));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue