feat: 新增动态数据源单元测试
This commit is contained in:
@@ -4,6 +4,7 @@ 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.sample.DynamicDataSourceSample;
|
||||
import com.youlai.system.service.SysRoleService;
|
||||
import com.youlai.system.service.SysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -17,29 +18,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
class DynamicDataSourceTest {
|
||||
|
||||
@Autowired
|
||||
private SysUserService userService;
|
||||
private DynamicDataSourceSample dynamicDataSourceSample;
|
||||
|
||||
@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);
|
||||
void testDynamicDataSourceWithTransactional() {
|
||||
String newTypeCod = RandomUtil.randomString(RandomUtil.BASE_CHAR, 6).toUpperCase();
|
||||
boolean result = dynamicDataSourceSample.updateDictTypeCode(2L, newTypeCod);
|
||||
log.info("testDynamicDataSourceWithTransactional result:{}", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user