feat: 新增动态数据源单元测试
This commit is contained in:
@@ -100,7 +100,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
//@DS("slave")
|
|
||||||
public boolean saveRole(RoleForm roleForm) {
|
public boolean saveRole(RoleForm roleForm) {
|
||||||
|
|
||||||
Long roleId = roleForm.getId();
|
Long roleId = roleForm.getId();
|
||||||
|
|||||||
@@ -154,9 +154,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
boolean result = this.updateById(entity);
|
boolean result = this.updateById(entity);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
/* RoleForm roleForm = roleService.getRoleForm(12l);
|
|
||||||
roleForm.setName("测试角色_" + RandomUtil.randomString(RandomUtil.BASE_CHAR, 1));
|
|
||||||
roleService.saveRole(roleForm);*/
|
|
||||||
// 保存用户角色
|
// 保存用户角色
|
||||||
userRoleService.saveUserRoles(entity.getId(), userForm.getRoleIds());
|
userRoleService.saveUserRoles(entity.getId(), userForm.getRoleIds());
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/test/java/com/youlai/system/DynamicDataSourceTest.java
Normal file
45
src/test/java/com/youlai/system/DynamicDataSourceTest.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package com.youlai.system;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.youlai.system.pojo.form.RoleForm;
|
||||||
|
import com.youlai.system.pojo.form.UserForm;
|
||||||
|
import com.youlai.system.service.SysRoleService;
|
||||||
|
import com.youlai.system.service.SysUserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
|
class DynamicDataSourceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysUserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleService roleService;
|
||||||
|
|
||||||
|
private static Long userId = 3L; // 测试用户
|
||||||
|
private static Long roleId = 3L;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
void updateUser() {
|
||||||
|
UserForm userForm = userService.getUserFormData(userId);
|
||||||
|
userForm.setNickname("测试用户_" + RandomUtil.randomString(RandomUtil.BASE_CHAR, 1));
|
||||||
|
userService.updateUser(userId, userForm);
|
||||||
|
|
||||||
|
this.updateRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DS("slave")
|
||||||
|
void updateRole() {
|
||||||
|
RoleForm roleForm = roleService.getRoleForm(roleId);
|
||||||
|
roleForm.setName("访问游客_" + RandomUtil.randomString(RandomUtil.BASE_CHAR, 1));
|
||||||
|
roleService.saveRole(roleForm);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.youlai.system.service.impl;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import com.youlai.system.converter.UserConverter;
|
|
||||||
import com.youlai.system.pojo.entity.SysUser;
|
|
||||||
import com.youlai.system.pojo.form.UserForm;
|
|
||||||
import com.youlai.system.service.SysUserService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@Slf4j
|
|
||||||
class SysUserServiceImplTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysUserService userService;
|
|
||||||
@Autowired
|
|
||||||
private UserConverter userConverter;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void updateUser() {
|
|
||||||
Long userId = 3L;
|
|
||||||
SysUser entity = userService.getById(userId);
|
|
||||||
UserForm userForm = userConverter.entity2Form(entity);
|
|
||||||
String nickname = "测试小用户_" + RandomUtil.randomString(RandomUtil.BASE_CHAR, 1);
|
|
||||||
userForm.setNickname(nickname);
|
|
||||||
|
|
||||||
userService.updateUser(userId, userForm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user