fix(系统设置): 组织部分功能移到社区版并补充测试用例
This commit is contained in:
parent
35199849c2
commit
119cad5d76
|
@ -6,18 +6,19 @@ import io.metersphere.sdk.constants.PermissionConstants;
|
|||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.system.dto.OrganizationDTO;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.request.OrganizationMemberRequest;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.OrganizationRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.annotation.Log;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.service.OrganizationService;
|
||||
import io.metersphere.system.service.SystemOrganizationLogService;
|
||||
import io.metersphere.system.service.SystemProjectService;
|
||||
import io.metersphere.system.service.UserService;
|
||||
import io.metersphere.system.utils.PageUtils;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
|
@ -56,6 +57,65 @@ public class SystemOrganizationController {
|
|||
return PageUtils.setPageInfo(page, organizationService.list(request));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-修改组织")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#organizationEditRequest)", msClass = SystemOrganizationLogService.class)
|
||||
public void update(@Validated({Updated.class}) @RequestBody OrganizationEditRequest organizationEditRequest) {
|
||||
OrganizationDTO organizationDTO = new OrganizationDTO();
|
||||
BeanUtils.copyBean(organizationDTO, organizationEditRequest);
|
||||
organizationDTO.setUpdateUser(SessionUtils.getUserId());
|
||||
organizationService.update(organizationDTO);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-修改组织名称")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateNameLog(#organizationEditRequest)", msClass = SystemOrganizationLogService.class)
|
||||
public void rename(@Validated({Updated.class}) @RequestBody OrganizationNameEditRequest organizationEditRequest) {
|
||||
OrganizationDTO organizationDTO = new OrganizationDTO();
|
||||
BeanUtils.copyBean(organizationDTO, organizationEditRequest);
|
||||
organizationDTO.setUpdateUser(SessionUtils.getUserId());
|
||||
organizationService.updateName(organizationDTO);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-删除组织")
|
||||
@Parameter(name = "id", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_DELETE)
|
||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = SystemOrganizationLogService.class)
|
||||
public void delete(@PathVariable String id) {
|
||||
OrganizationDeleteRequest organizationDeleteRequest = new OrganizationDeleteRequest();
|
||||
organizationDeleteRequest.setOrganizationId(id);
|
||||
organizationDeleteRequest.setDeleteUserId(SessionUtils.getUserId());
|
||||
organizationService.delete(organizationDeleteRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/recover/{id}")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-恢复组织")
|
||||
@Parameter(name = "id", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
|
||||
@Log(type = OperationLogType.RECOVER, expression = "#msClass.recoverLog(#id)", msClass = SystemOrganizationLogService.class)
|
||||
public void recover(@PathVariable String id) {
|
||||
organizationService.recover(id);
|
||||
}
|
||||
|
||||
@GetMapping("/enable/{id}")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-启用组织")
|
||||
@Parameter(name = "id", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
public void enable(@PathVariable String id) {
|
||||
organizationService.enable(id);
|
||||
}
|
||||
|
||||
@GetMapping("/disable/{id}")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-结束组织")
|
||||
@Parameter(name = "id", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||
public void disable(@PathVariable String id) {
|
||||
organizationService.disable(id);
|
||||
}
|
||||
|
||||
@PostMapping("/option/all")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-组织-获取系统所有组织下拉选项")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
|
|
|
@ -78,6 +78,7 @@ public class OrganizationService {
|
|||
private static final String ADD_MEMBER_PATH = "/system/organization/add-member";
|
||||
private static final String REMOVE_MEMBER_PATH = "/system/organization/remove-member";
|
||||
public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30;
|
||||
private static final Long DEFAULT_ORGANIZATION_NUM = 100001L;
|
||||
|
||||
/**
|
||||
* 分页获取系统下组织列表
|
||||
|
@ -104,6 +105,102 @@ public class OrganizationService {
|
|||
return organizations.stream().map(o -> new OptionDTO(o.getId(), o.getName())).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新组织名称
|
||||
* @param organizationDTO 组织请求参数
|
||||
*/
|
||||
public void updateName(OrganizationDTO organizationDTO) {
|
||||
checkOrganizationNotExist(organizationDTO.getId());
|
||||
checkOrganizationExist(organizationDTO);
|
||||
organizationDTO.setUpdateTime(System.currentTimeMillis());
|
||||
organizationDTO.setCreateUser(null);
|
||||
organizationDTO.setCreateTime(null);
|
||||
organizationMapper.updateByPrimaryKeySelective(organizationDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新组织
|
||||
* @param organizationDTO 组织请求参数
|
||||
*/
|
||||
public void update(OrganizationDTO organizationDTO) {
|
||||
checkOrganizationNotExist(organizationDTO.getId());
|
||||
checkOrganizationExist(organizationDTO);
|
||||
organizationDTO.setUpdateTime(System.currentTimeMillis());
|
||||
organizationDTO.setCreateUser(null);
|
||||
organizationDTO.setCreateTime(null);
|
||||
organizationMapper.updateByPrimaryKeySelective(organizationDTO);
|
||||
|
||||
// 新增的组织管理员ID
|
||||
List<String> addOrgAdmins = organizationDTO.getUserIds();
|
||||
// 旧的组织管理员ID
|
||||
List<String> oldOrgAdmins = getOrgAdminIds(organizationDTO.getId());
|
||||
if (CollectionUtils.isNotEmpty(addOrgAdmins)) {
|
||||
// 需要新增组织管理员ID
|
||||
List<String> addIds = addOrgAdmins.stream().filter(addOrgAdmin -> !oldOrgAdmins.contains(addOrgAdmin)).toList();
|
||||
// 需要删除的组织管理员ID
|
||||
List<String> deleteIds = oldOrgAdmins.stream().filter(oldOrgAdmin -> !addOrgAdmins.contains(oldOrgAdmin)).toList();
|
||||
// 添加组织管理员
|
||||
if (CollectionUtils.isNotEmpty(addIds)) {
|
||||
addIds.forEach(userId -> {
|
||||
// 添加组织管理员
|
||||
createAdmin(userId, organizationDTO.getId(), organizationDTO.getUpdateUser());
|
||||
});
|
||||
}
|
||||
// 删除组织管理员
|
||||
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
||||
UserRoleRelationExample deleteExample = new UserRoleRelationExample();
|
||||
deleteExample.createCriteria().andSourceIdEqualTo(organizationDTO.getId()).andRoleIdEqualTo(InternalUserRole.ORG_ADMIN.getValue()).andUserIdIn(deleteIds);
|
||||
userRoleRelationMapper.deleteByExample(deleteExample);
|
||||
}
|
||||
} else {
|
||||
// 前端传入的组织管理员ID为空,删除所有组织管理员
|
||||
if (CollectionUtils.isNotEmpty(oldOrgAdmins)) {
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria().andSourceIdEqualTo(organizationDTO.getId()).andRoleIdEqualTo(InternalUserRole.ORG_ADMIN.getValue());
|
||||
userRoleRelationMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除组织
|
||||
* @param organizationDeleteRequest 组织删除参数
|
||||
*/
|
||||
public void delete(OrganizationDeleteRequest organizationDeleteRequest) {
|
||||
// 默认组织不允许删除
|
||||
checkOrgDefault(organizationDeleteRequest.getOrganizationId());
|
||||
checkOrganizationNotExist(organizationDeleteRequest.getOrganizationId());
|
||||
organizationDeleteRequest.setDeleteTime(System.currentTimeMillis());
|
||||
extOrganizationMapper.delete(organizationDeleteRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复组织
|
||||
* @param id 组织ID
|
||||
*/
|
||||
public void recover(String id) {
|
||||
checkOrganizationNotExist(id);
|
||||
extOrganizationMapper.recover(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启组织
|
||||
* @param id 组织ID
|
||||
*/
|
||||
public void enable(String id) {
|
||||
checkOrganizationNotExist(id);
|
||||
extOrganizationMapper.updateEnable(id, Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束组织
|
||||
* @param id 组织ID
|
||||
*/
|
||||
public void disable(String id) {
|
||||
checkOrganizationNotExist(id);
|
||||
extOrganizationMapper.updateEnable(id, Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取组织成员列表
|
||||
*
|
||||
|
@ -935,4 +1032,73 @@ public class OrganizationService {
|
|||
int remainDayCount = DEFAULT_REMAIN_DAY_COUNT - (int) remainDays;
|
||||
return remainDayCount > 0 ? remainDayCount : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验组织不存在
|
||||
*
|
||||
* @param id 组织ID
|
||||
*/
|
||||
private void checkOrganizationNotExist(String id) {
|
||||
if (organizationMapper.selectByPrimaryKey(id) == null) {
|
||||
throw new MSException(Translator.get("organization_not_exist"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验组织存在
|
||||
*
|
||||
* @param organizationDTO 组织DTO
|
||||
*/
|
||||
private void checkOrganizationExist(OrganizationDTO organizationDTO) {
|
||||
OrganizationExample example = new OrganizationExample();
|
||||
OrganizationExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(organizationDTO.getName()).andIdNotEqualTo(organizationDTO.getId());
|
||||
if (organizationMapper.countByExample(example) > 0) {
|
||||
throw new MSException(Translator.get("organization_name_already_exists"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组织下所有管理员ID
|
||||
*
|
||||
* @param organizationId 组织ID
|
||||
* @return 管理员ID集合
|
||||
*/
|
||||
public List<String> getOrgAdminIds(String organizationId) {
|
||||
UserRoleRelationExample example = new UserRoleRelationExample();
|
||||
example.createCriteria().andSourceIdEqualTo(organizationId).andRoleIdEqualTo(InternalUserRole.ORG_ADMIN.getValue());
|
||||
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(example);
|
||||
return userRoleRelations.stream().map(UserRoleRelation::getUserId).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 成员添加组织管理员
|
||||
*
|
||||
* @param memberId 成员ID
|
||||
* @param organizationId 组织ID
|
||||
* @param createUser 创建用户
|
||||
*/
|
||||
public void createAdmin(String memberId, String organizationId, String createUser) {
|
||||
UserRoleRelation orgAdmin = new UserRoleRelation();
|
||||
orgAdmin.setId(IDGenerator.nextStr());
|
||||
orgAdmin.setUserId(memberId);
|
||||
orgAdmin.setRoleId(InternalUserRole.ORG_ADMIN.getValue());
|
||||
orgAdmin.setSourceId(organizationId);
|
||||
orgAdmin.setCreateTime(System.currentTimeMillis());
|
||||
orgAdmin.setCreateUser(createUser);
|
||||
orgAdmin.setOrganizationId(organizationId);
|
||||
userRoleRelationMapper.insertSelective(orgAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验组织是否为默认组织
|
||||
*
|
||||
* @param id 组织ID
|
||||
*/
|
||||
private void checkOrgDefault(String id) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(id);
|
||||
if (organization.getNum().equals(DEFAULT_ORGANIZATION_NUM)) {
|
||||
throw new MSException(Translator.get("default_organization_not_allow_delete"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||
import io.metersphere.sdk.constants.OperationLogConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.domain.Organization;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.domain.UserExample;
|
||||
import io.metersphere.system.dto.request.OrganizationEditRequest;
|
||||
import io.metersphere.system.dto.request.OrganizationNameEditRequest;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.mapper.OrganizationMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class SystemOrganizationLogService {
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private OrganizationMapper organizationMapper;
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
|
||||
/**
|
||||
* 更新组织
|
||||
*
|
||||
* @param request 接口请求参数
|
||||
* @return 日志详情
|
||||
*/
|
||||
public LogDTO updateNameLog(OrganizationNameEditRequest request) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(request.getId());
|
||||
if (organization != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
request.getId(),
|
||||
null,
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
organization.getName());
|
||||
dto.setPath("/system/organization/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新组织
|
||||
*
|
||||
* @param request 接口请求参数
|
||||
* @return 日志详情
|
||||
*/
|
||||
public LogDTO updateLog(OrganizationEditRequest request) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(request.getId());
|
||||
if (organization != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
request.getId(),
|
||||
null,
|
||||
OperationLogType.UPDATE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
organization.getName());
|
||||
dto.setPath("/system/organization/update");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
// 新增的组织管理员ID
|
||||
List<String> newUserIds = request.getUserIds();
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andIdIn(newUserIds);
|
||||
List<User> newOrgUsers = userMapper.selectByExample(example);
|
||||
// 旧的组织管理员ID
|
||||
List<String> oldUserIds = organizationService.getOrgAdminIds(request.getId());
|
||||
example.clear();
|
||||
example.createCriteria().andIdIn(oldUserIds);
|
||||
List<User> oldOrgUsers = userMapper.selectByExample(example);
|
||||
dto.setOriginalValue(JSON.toJSONBytes(oldOrgUsers));
|
||||
dto.setModifiedValue(JSON.toJSONBytes(newOrgUsers));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除组织
|
||||
*
|
||||
* @param id 接口请求参数
|
||||
* @return 日志详情
|
||||
*/
|
||||
public LogDTO deleteLog(String id) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(id);
|
||||
if (organization != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
id,
|
||||
null,
|
||||
OperationLogType.DELETE.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
organization.getName());
|
||||
dto.setPath("/system/organization/delete");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(organization));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复组织
|
||||
*
|
||||
* @param id 接口请求参数
|
||||
* @return 日志详情
|
||||
*/
|
||||
public LogDTO recoverLog(String id) {
|
||||
Organization organization = organizationMapper.selectByPrimaryKey(id);
|
||||
if (organization != null) {
|
||||
LogDTO dto = new LogDTO(
|
||||
OperationLogConstants.SYSTEM,
|
||||
OperationLogConstants.SYSTEM,
|
||||
id,
|
||||
null,
|
||||
OperationLogType.RECOVER.name(),
|
||||
OperationLogModule.SETTING_SYSTEM_ORGANIZATION,
|
||||
organization.getName());
|
||||
dto.setPath("/system/organization/recover");
|
||||
dto.setMethod(HttpMethodConstants.GET.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(organization));
|
||||
return dto;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -7,9 +7,7 @@ import io.metersphere.system.base.BaseTest;
|
|||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.dto.OrganizationDTO;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.request.OrganizationMemberRequest;
|
||||
import io.metersphere.system.dto.request.OrganizationRequest;
|
||||
import io.metersphere.system.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.dto.request.*;
|
||||
import io.metersphere.system.dto.user.UserExtendDTO;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
|
@ -41,6 +39,12 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
private MockMvc mockMvc;
|
||||
|
||||
public static final String ORGANIZATION_LIST = "/system/organization/list";
|
||||
public static final String ORGANIZATION_UPDATE = "/system/organization/update";
|
||||
public static final String ORGANIZATION_RENAME = "/system/organization/rename";
|
||||
public static final String ORGANIZATION_DELETE = "/system/organization/delete";
|
||||
public static final String ORGANIZATION_RECOVER = "/system/organization/recover";
|
||||
public static final String ORGANIZATION_ENABLE = "/system/organization/enable";
|
||||
public static final String ORGANIZATION_DISABLE = "/system/organization/disable";
|
||||
public static final String ORGANIZATION_LIST_OPTION_ALL = "/system/organization/option/all";
|
||||
public static final String ORGANIZATION_DEFAULT = "/system/organization/default";
|
||||
public static final String ORGANIZATION_LIST_MEMBER = "/system/organization/list-member";
|
||||
|
@ -132,6 +136,69 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testUpdateOrganizationSuccess() throws Exception {
|
||||
OrganizationEditRequest request = new OrganizationEditRequest();
|
||||
request.setId("default-organization-5");
|
||||
request.setName("default-5");
|
||||
request.setUserIds(List.of("user-id1", "user-id2"));
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().isOk());
|
||||
request.setUserIds(List.of("user-id1"));
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().isOk());
|
||||
request.setUserIds(List.of());
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().isOk());
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testUpdateOrganizationError() throws Exception {
|
||||
OrganizationEditRequest request = new OrganizationEditRequest();
|
||||
request.setName("default-4");
|
||||
// 组织不存在
|
||||
request.setId("default-organization-x");
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().is5xxServerError());
|
||||
// 组织存在, 但是名称重复
|
||||
request.setId("default-organization-5");
|
||||
this.requestPost(ORGANIZATION_UPDATE, request).andExpect(status().is5xxServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
public void testOrganizationRename() throws Exception {
|
||||
OrganizationNameEditRequest request = new OrganizationNameEditRequest();
|
||||
request.setName("default-x");
|
||||
request.setId("default-organization-5");
|
||||
this.requestPost(ORGANIZATION_RENAME, request).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
public void testDeleteOrganization() throws Exception {
|
||||
this.requestGetWithOk(ORGANIZATION_DELETE + "/default-organization-5");
|
||||
// 删除默认组织
|
||||
this.requestGet(ORGANIZATION_DELETE + "/100001").andExpect(status().is5xxServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
public void testRecoverOrganization() throws Exception {
|
||||
this.requestGetWithOk(ORGANIZATION_RECOVER + "/default-organization-5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void testDisableOrganization() throws Exception {
|
||||
this.requestGetWithOk(ORGANIZATION_DISABLE + "/default-organization-5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void testEnableOrganization() throws Exception {
|
||||
this.requestGetWithOk(ORGANIZATION_ENABLE + "/default-organization-5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void testListAllOrganizationSuccess() throws Exception {
|
||||
MvcResult mvcResult = this.responsePost(ORGANIZATION_LIST_OPTION_ALL, null);
|
||||
// 获取返回值
|
||||
|
@ -144,13 +211,13 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@Order(11)
|
||||
public void testListAllOrganizationError() throws Exception {
|
||||
this.requestGet(ORGANIZATION_LIST_OPTION_ALL, status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@Order(12)
|
||||
public void testListOrganizationMemberSuccess() throws Exception {
|
||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
||||
organizationRequest.setCurrent(1);
|
||||
|
@ -193,7 +260,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(13)
|
||||
public void testListOrganizationMemberError() throws Exception {
|
||||
// 页码有误
|
||||
OrganizationRequest organizationRequest = new OrganizationRequest();
|
||||
|
@ -213,7 +280,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
@Order(14)
|
||||
public void testAddOrganizationMemberSuccess() throws Exception {
|
||||
OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest();
|
||||
organizationMemberRequest.setOrganizationId("default-organization-3");
|
||||
|
@ -251,7 +318,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
@Order(15)
|
||||
public void testAddOrganizationMemberSuccessWithRepeatUser() throws Exception {
|
||||
OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest();
|
||||
organizationMemberRequest.setOrganizationId("default-organization-3");
|
||||
|
@ -284,7 +351,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@Order(16)
|
||||
public void testAddOrganizationMemberError() throws Exception {
|
||||
// 成员选择为空
|
||||
OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest();
|
||||
|
@ -309,7 +376,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
@Order(17)
|
||||
public void testRemoveOrganizationMemberSuccess() throws Exception {
|
||||
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-3/admin", status().isOk());
|
||||
// 日志校验
|
||||
|
@ -319,14 +386,14 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@Order(17)
|
||||
public void testRemoveOrganizationMemberError() throws Exception {
|
||||
// 组织不存在
|
||||
this.requestGet(ORGANIZATION_REMOVE_MEMBER + "/default-organization-x/admin-x", status().is5xxServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
@Order(19)
|
||||
public void testGetOrganizationProjectSuccess() throws Exception {
|
||||
ProjectRequest projectRequest = new ProjectRequest();
|
||||
projectRequest.setCurrent(1);
|
||||
|
@ -363,7 +430,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
@Order(20)
|
||||
public void testGetOrganizationProjectError() throws Exception {
|
||||
// 页码有误
|
||||
ProjectRequest projectRequest = new ProjectRequest();
|
||||
|
@ -380,7 +447,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
@Order(21)
|
||||
public void testGetDefaultOrganizationSuccess() throws Exception {
|
||||
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_DEFAULT);
|
||||
// 获取返回值
|
||||
|
@ -399,13 +466,13 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
@Order(22)
|
||||
public void testGetDefaultOrganizationError() throws Exception {
|
||||
this.requestPost(ORGANIZATION_DEFAULT, null, status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
@Order(23)
|
||||
public void testGetOrganizationMemberOption() throws Exception {
|
||||
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
|
||||
// 获取返回值
|
||||
|
@ -419,7 +486,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
@Order(24)
|
||||
public void testGetTotal() throws Exception {
|
||||
// 组织不存在
|
||||
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_TOTAL + "?organizationId=default-organization-2");
|
||||
|
|
Loading…
Reference in New Issue