|
|
|
@ -24,9 +24,9 @@ import io.metersphere.system.request.user.UserRoleBatchRelationRequest;
|
|
|
|
|
import io.metersphere.system.response.user.UserImportResponse;
|
|
|
|
|
import io.metersphere.system.response.user.UserSelectOption;
|
|
|
|
|
import io.metersphere.system.response.user.UserTableResponse;
|
|
|
|
|
import io.metersphere.system.response.user.UserTreeSelectOption;
|
|
|
|
|
import io.metersphere.system.service.GlobalUserRoleRelationService;
|
|
|
|
|
import io.metersphere.system.service.UserService;
|
|
|
|
|
import io.metersphere.system.service.UserToolService;
|
|
|
|
|
import io.metersphere.system.utils.user.UserParamUtils;
|
|
|
|
|
import io.metersphere.system.utils.user.UserRequestUtils;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
@ -58,6 +58,8 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
@Resource
|
|
|
|
|
private UserService userService;
|
|
|
|
|
@Resource
|
|
|
|
|
private UserToolService userToolService;
|
|
|
|
|
@Resource
|
|
|
|
|
private UserMapper userMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private GlobalUserRoleRelationService globalUserRoleRelationService;
|
|
|
|
@ -73,7 +75,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
private static final List<UserCreateInfo> USER_LIST = new ArrayList<>();
|
|
|
|
|
private static final List<UserSelectOption> USER_ROLE_LIST = new ArrayList<>();
|
|
|
|
|
private static final List<UserSelectOption> ORG_LIST = new ArrayList<>();
|
|
|
|
|
private static final List<UserTreeSelectOption> PROJECT_LIST = new ArrayList<>();
|
|
|
|
|
private static final List<BaseTreeNode> PROJECT_LIST = new ArrayList<>();
|
|
|
|
|
//默认数据
|
|
|
|
|
public static final String USER_DEFAULT_NAME = "tianyang.no.1";
|
|
|
|
|
public static final String USER_DEFAULT_EMAIL = "tianyang.no.1@126.com";
|
|
|
|
@ -95,7 +97,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
@Test
|
|
|
|
|
@Order(0)
|
|
|
|
|
public void testGetGlobalSystemUserRoleSuccess() throws Exception {
|
|
|
|
|
MvcResult mvcResult = userRequestUtils.responseGet(userRequestUtils.URL_GET_GLOBAL_SYSTEM);
|
|
|
|
|
MvcResult mvcResult = userRequestUtils.responseGet(UserRequestUtils.URL_GET_GLOBAL_SYSTEM);
|
|
|
|
|
this.setDefaultUserRoleList(mvcResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -119,7 +121,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}});
|
|
|
|
|
}}
|
|
|
|
|
);
|
|
|
|
|
MvcResult mvcResult = userRequestUtils.responsePost(userRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
MvcResult mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
this.addUser2List(mvcResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -136,7 +138,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
Collections.singletonList(USER_ROLE_LIST.get(0)),
|
|
|
|
|
userCreateInfoList
|
|
|
|
|
);
|
|
|
|
|
mvcResult = userRequestUtils.responsePost(userRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
this.addUser2List(mvcResult);
|
|
|
|
|
|
|
|
|
|
//含有重复的用户名称
|
|
|
|
@ -154,12 +156,10 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}});
|
|
|
|
|
}}
|
|
|
|
|
);
|
|
|
|
|
mvcResult = userRequestUtils.responsePost(userRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest);
|
|
|
|
|
this.addUser2List(mvcResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final String URL_GET_ORGANIZATION = "/system/user/get/organization";
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Order(2)
|
|
|
|
|
@Sql(scripts = {"/dml/init_user_controller_test.sql"},
|
|
|
|
@ -184,7 +184,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserDTO getUserByEmail(String email) throws Exception {
|
|
|
|
|
String url = String.format(userRequestUtils.URL_USER_GET, email);
|
|
|
|
|
String url = String.format(UserRequestUtils.URL_USER_GET, email);
|
|
|
|
|
return userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseGet(url), UserDTO.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -193,7 +193,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
public void testGetByEmailError() throws Exception {
|
|
|
|
|
//测试使用任意参数,不能获取到任何用户信息
|
|
|
|
|
this.checkUserList();
|
|
|
|
|
String url = userRequestUtils.URL_USER_GET + UUID.randomUUID();
|
|
|
|
|
String url = UserRequestUtils.URL_USER_GET + UUID.randomUUID();
|
|
|
|
|
MvcResult mvcResult = userRequestUtils.responseGet(url);
|
|
|
|
|
|
|
|
|
|
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
|
|
|
@ -207,7 +207,11 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
@Test
|
|
|
|
|
@Order(3)
|
|
|
|
|
public void testPageSuccess() throws Exception {
|
|
|
|
|
List<String> userRoleIdList = USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtils.isEmpty(USER_ROLE_LIST)) {
|
|
|
|
|
this.testGetGlobalSystemUserRoleSuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> userRoleIdList = USER_ROLE_LIST.stream().map(UserSelectOption::getId).toList();
|
|
|
|
|
this.checkUserList();
|
|
|
|
|
BasePageRequest basePageRequest = UserParamUtils.getDefaultPageRequest();
|
|
|
|
|
|
|
|
|
@ -222,9 +226,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//用户组不存在非全局用户组
|
|
|
|
|
for (UserTableResponse response : userList) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(response.getUserRoleList())) {
|
|
|
|
|
response.getUserRoleList().forEach(role -> {
|
|
|
|
|
Assertions.assertTrue(userRoleIdList.contains(role.getId()));
|
|
|
|
|
});
|
|
|
|
|
response.getUserRoleList().forEach(role -> Assertions.assertTrue(userRoleIdList.contains(role.getId())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -242,9 +244,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
userList = JSON.parseArray(JSON.toJSONString(returnPager.getList()), UserTableResponse.class);
|
|
|
|
|
for (UserTableResponse response : userList) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(response.getUserRoleList())) {
|
|
|
|
|
response.getUserRoleList().forEach(role -> {
|
|
|
|
|
Assertions.assertTrue(userRoleIdList.contains(role.getId()));
|
|
|
|
|
});
|
|
|
|
|
response.getUserRoleList().forEach(role -> Assertions.assertTrue(userRoleIdList.contains(role.getId())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -264,12 +264,20 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
userList = JSON.parseArray(JSON.toJSONString(returnPager.getList()), UserTableResponse.class);
|
|
|
|
|
for (UserTableResponse response : userList) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(response.getUserRoleList())) {
|
|
|
|
|
response.getUserRoleList().forEach(role -> {
|
|
|
|
|
Assertions.assertTrue(userRoleIdList.contains(role.getId()));
|
|
|
|
|
});
|
|
|
|
|
response.getUserRoleList().forEach(role -> Assertions.assertTrue(userRoleIdList.contains(role.getId())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查找不存在的用户
|
|
|
|
|
basePageRequest = UserParamUtils.getDefaultPageRequest();
|
|
|
|
|
basePageRequest.setKeyword(UUID.randomUUID().toString());
|
|
|
|
|
returnPager = userRequestUtils.selectUserPage(basePageRequest);
|
|
|
|
|
//返回值不为空
|
|
|
|
|
Assertions.assertNotNull(returnPager);
|
|
|
|
|
//返回值的页码和当前页码相同
|
|
|
|
|
Assertions.assertEquals(returnPager.getTotal(), 0);
|
|
|
|
|
//返回的数据量不超过规定要返回的数据量相同
|
|
|
|
|
Assertions.assertEquals(0, JSON.parseArray(JSON.toJSONString(returnPager.getList())).size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -278,15 +286,15 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//当前页码不大于0
|
|
|
|
|
BasePageRequest basePageRequest = new BasePageRequest();
|
|
|
|
|
basePageRequest.setPageSize(5);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//pageSize超过100
|
|
|
|
|
basePageRequest = UserParamUtils.getDefaultPageRequest();
|
|
|
|
|
basePageRequest.setPageSize(250);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//当前页数不大于5
|
|
|
|
|
basePageRequest = new BasePageRequest();
|
|
|
|
|
basePageRequest.setCurrent(1);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//排序字段不合法
|
|
|
|
|
basePageRequest = new BasePageRequest();
|
|
|
|
|
basePageRequest.setCurrent(1);
|
|
|
|
@ -294,7 +302,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
basePageRequest.setSort(new HashMap<>() {{
|
|
|
|
|
put("SELECT * FROM user", "asc");
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_PAGE, basePageRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -309,21 +317,21 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//更改名字
|
|
|
|
|
user.setName("TEST-UPDATE");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
|
//更改邮箱
|
|
|
|
|
user.setEmail("songtianyang-test-email@12138.com");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
|
//更改手机号
|
|
|
|
|
user.setPhone("18511112222");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
@ -331,13 +339,13 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user,
|
|
|
|
|
USER_ROLE_LIST.stream().filter(item -> StringUtils.equals(item.getId(), "member")).toList()
|
|
|
|
|
);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
|
//更改用户组(把上面的情况添加别的权限)
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
@ -345,7 +353,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
user = new UserCreateInfo();
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest), UserEditRequest.class);
|
|
|
|
|
checkLog(response.getId(), OperationLogType.UPDATE);
|
|
|
|
|
checkDTO = this.getUserByEmail(user.getEmail());
|
|
|
|
|
UserParamUtils.compareUserDTO(response, checkDTO);
|
|
|
|
@ -361,22 +369,22 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
user.setName("");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//email为空
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
user.setEmail("");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//手机号为空
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
user.setEmail("");
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//用户组为空
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, new ArrayList<>());
|
|
|
|
|
userMaintainRequest.setUserRoleIdList(new ArrayList<>());
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
|
|
|
|
|
// 500验证
|
|
|
|
|
//邮箱重复
|
|
|
|
@ -384,13 +392,13 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
user.setEmail(USER_LIST.get(USER_LIST.size() - 1).getEmail());
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user, USER_ROLE_LIST);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
//用户组不包含系统成员
|
|
|
|
|
BeanUtils.copyBean(user, USER_LIST.get(0));
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserUpdateDTO(user,
|
|
|
|
|
USER_ROLE_LIST.stream().filter(item -> !StringUtils.equals(item.getId(), "member")).toList()
|
|
|
|
|
);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -404,7 +412,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
this.add(userInfo.getId());
|
|
|
|
|
}});
|
|
|
|
|
userChangeEnableRequest.setEnable(false);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk());
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, status().isOk());
|
|
|
|
|
for (String item : userChangeEnableRequest.getSelectIds()) {
|
|
|
|
|
checkLog(item, OperationLogType.UPDATE);
|
|
|
|
|
}
|
|
|
|
@ -420,12 +428,12 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//用户不存在
|
|
|
|
|
UserChangeEnableRequest userChangeEnableRequest = new UserChangeEnableRequest();
|
|
|
|
|
userChangeEnableRequest.setEnable(false);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//含有非法用户
|
|
|
|
|
userChangeEnableRequest.setSelectIds(new ArrayList<>() {{
|
|
|
|
|
this.add("BCDEDIT");
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_UPDATE_ENABLE, userChangeEnableRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -441,7 +449,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_success.xlsx")).getPath();
|
|
|
|
|
MockMultipartFile file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
ExcelParseDTO<UserExcelRowDTO> userImportReportDTOByFile = userService.getUserExcelParseDTO(file);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);//检查返回值
|
|
|
|
|
List<UserDTO> userDTOList = this.checkImportUserInDb(userImportReportDTOByFile);//检查数据已入库
|
|
|
|
|
for (UserDTO item : userDTOList) {
|
|
|
|
@ -451,7 +459,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//导入空文件. 应当导入成功的数据为0
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_success_empty.xlsx")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
importSuccessData = 0;
|
|
|
|
|
errorDataIndex = new int[]{};
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);
|
|
|
|
@ -459,7 +467,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//文件内没有一条合格数据 应当导入成功的数据为0
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_error_all.xlsx")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
errorDataIndex = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);
|
|
|
|
|
|
|
|
|
@ -467,7 +475,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_error_email_repeat_db.xlsx")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
userImportReportDTOByFile = userService.getUserExcelParseDTO(file);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
importSuccessData = 8;
|
|
|
|
|
errorDataIndex = new int[]{1, 7};
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);
|
|
|
|
@ -480,7 +488,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_error_email_repeat_in_file.xlsx")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
userImportReportDTOByFile = userService.getUserExcelParseDTO(file);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
errorDataIndex = new int[]{9, 10};
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);
|
|
|
|
|
userDTOList = this.checkImportUserInDb(userImportReportDTOByFile);//检查数据已入库
|
|
|
|
@ -491,7 +499,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
//文件不符合规范 应当导入成功的数据为0
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/abcde.gif")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
importSuccessData = 0;
|
|
|
|
|
errorDataIndex = new int[]{};
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);
|
|
|
|
@ -500,7 +508,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_success_03.xls")).getPath();
|
|
|
|
|
file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath));
|
|
|
|
|
userImportReportDTOByFile = userService.getUserExcelParseDTO(file);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(userRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class);
|
|
|
|
|
importSuccessData = 10;//应该导入成功的数据数量
|
|
|
|
|
errorDataIndex = new int[]{};//出错数据的行数
|
|
|
|
|
UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);//检查返回值
|
|
|
|
@ -517,7 +525,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
{
|
|
|
|
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
|
|
|
|
request.setSelectIds(Collections.singletonList("none user"));
|
|
|
|
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -545,24 +553,24 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
*/
|
|
|
|
|
//所有参数都为空
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(null, null);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//用户组ID为空
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
null,
|
|
|
|
|
errorUserList);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//没有用户
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
|
null);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//用户组含有null
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
|
errorUserList);
|
|
|
|
|
userMaintainRequest.getUserRoleIdList().add(null);
|
|
|
|
|
userMaintainRequest.getUserRoleIdList().add("");
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//含有用户名称为空的数据
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
@ -571,7 +579,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
|
|
|
setEmail("tianyang.name.empty@126.com");
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//含有用户邮箱为空的数据
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
@ -580,7 +588,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
userMaintainRequest.getUserInfoList().add(new UserCreateInfo() {{
|
|
|
|
|
setName("tianyang.email.empty");
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
//用户邮箱不符合标准
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
@ -590,7 +598,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
setName("用户邮箱放飞自我");
|
|
|
|
|
setEmail("用户邮箱放飞自我");
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
/*
|
|
|
|
|
* 校验业务判断出错的反例 (500 error)
|
|
|
|
|
* 需要保证数据库有正常数据
|
|
|
|
@ -604,7 +612,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}});
|
|
|
|
|
}},
|
|
|
|
|
errorUserList);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
//含有重复的用户邮箱
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
@ -615,7 +623,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
setName("tianyang.no.error4");
|
|
|
|
|
setEmail(firstUserEmail);
|
|
|
|
|
}});
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
//测试请求参数中含有数据库中已存在的邮箱情况
|
|
|
|
|
userMaintainRequest = UserParamUtils.getUserCreateDTO(
|
|
|
|
|
USER_ROLE_LIST,
|
|
|
|
@ -629,7 +637,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}});
|
|
|
|
|
}}
|
|
|
|
|
);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_CREATE, userMaintainRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -640,7 +648,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
{
|
|
|
|
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
|
|
|
|
request.setSelectIds(Collections.singletonList("admin"));
|
|
|
|
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request);
|
|
|
|
|
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request);
|
|
|
|
|
//检查数据库
|
|
|
|
|
UserExample userExample = new UserExample();
|
|
|
|
|
userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtil.md5("metersphere"));
|
|
|
|
@ -657,11 +665,11 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
|
|
|
|
request.setSelectIds(Collections.singletonList(userId));
|
|
|
|
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
|
|
|
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
|
|
|
|
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request),
|
|
|
|
|
TableBatchProcessResponse.class
|
|
|
|
|
);
|
|
|
|
|
Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1);
|
|
|
|
|
List<User> userList = userService.selectByIdList(Collections.singletonList(userId));
|
|
|
|
|
List<User> userList = userToolService.selectByIdList(Collections.singletonList(userId));
|
|
|
|
|
for (User checkUser : userList) {
|
|
|
|
|
UserExample userExample = new UserExample();
|
|
|
|
|
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
|
|
|
@ -675,7 +683,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
request.setExcludeIds(Collections.singletonList("admin"));
|
|
|
|
|
request.setSelectAll(true);
|
|
|
|
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
|
|
|
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
|
|
|
|
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request),
|
|
|
|
|
TableBatchProcessResponse.class
|
|
|
|
|
);
|
|
|
|
|
UserExample example = new UserExample();
|
|
|
|
@ -705,9 +713,9 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
List<UserCreateInfo> last50Users = USER_LIST.subList(USER_LIST.size() - 50, USER_LIST.size());
|
|
|
|
|
//测试添加角色权限。 预期数据:每个用户都会增加对应的权限
|
|
|
|
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
|
|
|
|
//检查有权限的数据量是否一致
|
|
|
|
|
Assertions.assertEquals(
|
|
|
|
|
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(),
|
|
|
|
@ -719,7 +727,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//测试重复添加用户权限。预期结果:不会额外增加数据
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, null);
|
|
|
|
|
//检查有权限的数据量是否一致
|
|
|
|
|
Assertions.assertEquals(
|
|
|
|
|
globalUserRoleRelationService.selectByUserIdAndRuleId(request.getSelectIds(), request.getRoleIds()).size(),
|
|
|
|
@ -742,25 +750,25 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
// 用户ID为空
|
|
|
|
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(new ArrayList<>());
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 角色id为空
|
|
|
|
|
request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
request.setRoleIds(new ArrayList<>());
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 用户ID含有不存在的
|
|
|
|
|
request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
request.getSelectIds().add("none user");
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 角色ID含有不存在的
|
|
|
|
|
request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
request.setSelectIds(last50Users.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
request.setRoleIds(USER_ROLE_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
request.getRoleIds().add("none role");
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_USER_ROLE_RELATION, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -769,20 +777,20 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED),
|
|
|
|
|
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
|
|
|
|
public void testGetProjectAndOrganization() throws Exception {
|
|
|
|
|
String str = userRequestUtils.responseGet(userRequestUtils.URL_GET_PROJECT).getResponse().getContentAsString(StandardCharsets.UTF_8);
|
|
|
|
|
String str = userRequestUtils.responseGet(UserRequestUtils.URL_GET_PROJECT).getResponse().getContentAsString(StandardCharsets.UTF_8);
|
|
|
|
|
ResultHolder rh = JSON.parseObject(str, ResultHolder.class);
|
|
|
|
|
List<UserTreeSelectOption> userTreeSelectOptions = JSON.parseArray(
|
|
|
|
|
List<BaseTreeNode> userTreeSelectOptions = JSON.parseArray(
|
|
|
|
|
JSON.toJSONString(rh.getData()),
|
|
|
|
|
UserTreeSelectOption.class);
|
|
|
|
|
BaseTreeNode.class);
|
|
|
|
|
//返回值不为空
|
|
|
|
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(userTreeSelectOptions));
|
|
|
|
|
PROJECT_LIST.addAll(userTreeSelectOptions);
|
|
|
|
|
|
|
|
|
|
userTreeSelectOptions.forEach(item -> PROJECT_LIST.addAll(item.getChildren()));
|
|
|
|
|
|
|
|
|
|
List<UserSelectOption> userSelectOptions = JSON.parseArray(
|
|
|
|
|
JSON.toJSONString(
|
|
|
|
|
JSON.parseObject(
|
|
|
|
|
userRequestUtils.responseGet(userRequestUtils.URL_GET_ORGANIZATION).getResponse().getContentAsString(StandardCharsets.UTF_8),
|
|
|
|
|
userRequestUtils.responseGet(UserRequestUtils.URL_GET_ORGANIZATION).getResponse().getContentAsString(StandardCharsets.UTF_8),
|
|
|
|
|
ResultHolder.class).getData()),
|
|
|
|
|
UserSelectOption.class);
|
|
|
|
|
ORG_LIST.addAll(userSelectOptions);
|
|
|
|
@ -799,14 +807,12 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
this.testGetProjectAndOrganization();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> userIds = this.selectUserTableIds(50);
|
|
|
|
|
List<String> userIds = this.selectUserTableIds(100);
|
|
|
|
|
|
|
|
|
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(userIds);
|
|
|
|
|
request.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
//排除树结构中的组织ID
|
|
|
|
|
request.getRoleIds().removeAll(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
this.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, request);
|
|
|
|
|
request.setRoleIds(PROJECT_LIST.stream().map(BaseTreeNode::getId).toList());
|
|
|
|
|
this.requestPostWithOk(UserRequestUtils.URL_ADD_PROJECT_MEMBER, request);
|
|
|
|
|
//检查有权限的数据量是否一致
|
|
|
|
|
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
|
|
|
|
|
|
|
|
@ -850,8 +856,8 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
|
|
|
|
|
UserRoleBatchRelationRequest request = new UserRoleBatchRelationRequest();
|
|
|
|
|
request.setSelectIds(userIds);
|
|
|
|
|
request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
this.requestPostWithOk(userRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request);
|
|
|
|
|
request.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
this.requestPostWithOk(UserRequestUtils.URL_ADD_ORGANIZATION_MEMBER, request);
|
|
|
|
|
//检查有权限的数据量是否一致
|
|
|
|
|
UserRoleRelationExample checkExample = new UserRoleRelationExample();
|
|
|
|
|
for (String orgId : request.getRoleIds()) {
|
|
|
|
@ -881,45 +887,45 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
// 用户ID为空
|
|
|
|
|
UserRoleBatchRelationRequest addToProjectRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
addToProjectRequest.setSelectIds(new ArrayList<>());
|
|
|
|
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(BaseTreeNode::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 项目为空
|
|
|
|
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
addToProjectRequest.setRoleIds(new ArrayList<>());
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
// 用户ID含有不存在的
|
|
|
|
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
addToProjectRequest.setSelectIds(Collections.singletonList("none user"));
|
|
|
|
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
addToProjectRequest.setRoleIds(PROJECT_LIST.stream().map(BaseTreeNode::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 项目ID含有不存在的
|
|
|
|
|
addToProjectRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
addToProjectRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
addToProjectRequest.setRoleIds(Collections.singletonList("none role"));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, addToProjectRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 用户ID为空
|
|
|
|
|
UserRoleBatchRelationRequest orgRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
orgRequest.setSelectIds(new ArrayList<>());
|
|
|
|
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 项目为空
|
|
|
|
|
orgRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
orgRequest.setRoleIds(new ArrayList<>());
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, BAD_REQUEST_MATCHER);
|
|
|
|
|
// 用户ID含有不存在的
|
|
|
|
|
orgRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
orgRequest.setSelectIds(Collections.singletonList("none user"));
|
|
|
|
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).collect(Collectors.toList()));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
orgRequest.setRoleIds(ORG_LIST.stream().map(UserSelectOption::getId).toList());
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
// 项目ID含有不存在的
|
|
|
|
|
orgRequest = new UserRoleBatchRelationRequest();
|
|
|
|
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
orgRequest.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
orgRequest.setRoleIds(Collections.singletonList("none role"));
|
|
|
|
|
userRequestUtils.requestPost(userRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
userRequestUtils.requestPost(UserRequestUtils.URL_ADD_PROJECT_MEMBER, orgRequest, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//本测试类中会用到很多次用户数据。所以测试删除的方法放于最后
|
|
|
|
@ -929,9 +935,9 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
this.checkUserList();
|
|
|
|
|
//删除USER_LIST用户
|
|
|
|
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
|
|
|
|
request.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
|
|
|
|
request.setSelectIds(USER_LIST.stream().map(UserCreateInfo::getId).toList());
|
|
|
|
|
TableBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(
|
|
|
|
|
userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), TableBatchProcessResponse.class);
|
|
|
|
|
userRequestUtils.responsePost(UserRequestUtils.URL_USER_DELETE, request), TableBatchProcessResponse.class);
|
|
|
|
|
Assertions.assertEquals(request.getSelectIds().size(), response.getTotalCount());
|
|
|
|
|
Assertions.assertEquals(request.getSelectIds().size(), response.getSuccessCount());
|
|
|
|
|
//检查数据库
|
|
|
|
@ -950,21 +956,21 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
public void testUserDeleteError() throws Exception {
|
|
|
|
|
//参数为空
|
|
|
|
|
TableBatchProcessDTO request = new TableBatchProcessDTO();
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
//用户不存在
|
|
|
|
|
request.setSelectIds(Collections.singletonList("none user"));
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
//测试用户已经被删除的
|
|
|
|
|
if (CollectionUtils.isEmpty(DELETED_USER_ID_LIST)) {
|
|
|
|
|
this.testUserDeleteSuccess();
|
|
|
|
|
}
|
|
|
|
|
request.setSelectIds(DELETED_USER_ID_LIST);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
|
|
|
|
|
//测试包含Admin用户
|
|
|
|
|
request = new TableBatchProcessDTO();
|
|
|
|
|
request.setSelectAll(true);
|
|
|
|
|
this.requestPost(userRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
this.requestPost(UserRequestUtils.URL_USER_DELETE, request, ERROR_REQUEST_MATCHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -987,7 +993,7 @@ public class UserControllerTests extends BaseTest {
|
|
|
|
|
Pager<?> returnPager = userRequestUtils.selectUserPage(basePageRequest);
|
|
|
|
|
//用户组不存在非全局用户组
|
|
|
|
|
List<UserTableResponse> userList = JSON.parseArray(JSON.toJSONString(returnPager.getList()), UserTableResponse.class);
|
|
|
|
|
return userList.stream().map(User::getId).collect(Collectors.toList());
|
|
|
|
|
return userList.stream().map(User::getId).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//成功入库的用户保存内存中,其他用例会使用到
|
|
|
|
|