refactor(系统设置): 优化项目返回的参数
This commit is contained in:
parent
7c5792d539
commit
809af2ddd4
|
@ -12,9 +12,11 @@ import java.util.List;
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ProjectDTO extends Project {
|
public class ProjectDTO extends Project {
|
||||||
@Schema(description = "项目成员数量", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "项目成员数量", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
private String number;
|
private long memberCount;
|
||||||
@Schema(description = "所属组织", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "所属组织", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
private String organizationName;
|
private String organizationName;
|
||||||
@Schema(description = "管理员", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
@Schema(description = "管理员", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
private List<User> adminList;
|
private List<User> adminList;
|
||||||
|
@Schema(description = "创建人是否是管理员", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||||
|
private boolean projectCreateUserIsAdmin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,24 @@ public class OrganizationProjectController {
|
||||||
return organizationProjectService.revoke(id);
|
return organizationProjectService.revoke(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/enable/{id}")
|
||||||
|
@Operation(summary = "启用项目")
|
||||||
|
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = OrganizationProjectLogService.class)
|
||||||
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE)
|
||||||
|
public void enable(@PathVariable String id) {
|
||||||
|
organizationProjectService.enable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/disable/{id}")
|
||||||
|
@Operation(summary = "禁用项目")
|
||||||
|
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE)
|
||||||
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = OrganizationProjectLogService.class)
|
||||||
|
public void disable(@PathVariable String id) {
|
||||||
|
organizationProjectService.disable(id);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/member-list")
|
@PostMapping("/member-list")
|
||||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||||
@Operation(summary = "获取项目下成员列表")
|
@Operation(summary = "获取项目下成员列表")
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author song-cc-rock
|
* @author song-cc-rock
|
||||||
|
@ -103,4 +104,11 @@ public class SystemOrganizationController {
|
||||||
BeanUtils.copyBean(projectRequest, request);
|
BeanUtils.copyBean(projectRequest, request);
|
||||||
return PageUtils.setPageInfo(page, systemProjectService.getProjectList(projectRequest));
|
return PageUtils.setPageInfo(page, systemProjectService.getProjectList(projectRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/total")
|
||||||
|
@Operation(summary = "获取组织和项目总数")
|
||||||
|
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||||
|
public Map<String, Long> getTotal(@RequestParam(value = "organizationId",required = false) String organizationId) {
|
||||||
|
return organizationService.getTotal(organizationId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class SystemProjectController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/revoke/{id}")
|
@GetMapping("/revoke/{id}")
|
||||||
|
@Operation(summary = "撤销项目")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
|
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_RECOVER)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.recoverLog(#id)", msClass = SystemProjectLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.recoverLog(#id)", msClass = SystemProjectLogService.class)
|
||||||
@Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
@Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
|
@ -93,6 +94,24 @@ public class SystemProjectController {
|
||||||
return systemProjectService.revoke(id);
|
return systemProjectService.revoke(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/enable/{id}")
|
||||||
|
@Operation(summary = "启用项目")
|
||||||
|
@Parameter(name = "id", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class)
|
||||||
|
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE)
|
||||||
|
public void enable(@PathVariable String id) {
|
||||||
|
systemProjectService.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)
|
||||||
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#id)", msClass = SystemProjectLogService.class)
|
||||||
|
public void disable(@PathVariable String id) {
|
||||||
|
systemProjectService.disable(id);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/member-list")
|
@PostMapping("/member-list")
|
||||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||||
@Operation(summary = "获取项目下成员列表")
|
@Operation(summary = "获取项目下成员列表")
|
||||||
|
|
|
@ -43,4 +43,10 @@ public class OrganizationDTO extends Organization {
|
||||||
@Schema(description = "组织管理员ID集合")
|
@Schema(description = "组织管理员ID集合")
|
||||||
@NotEmpty(groups = {Created.class, Updated.class}, message = "{member.id.not_empty}")
|
@NotEmpty(groups = {Created.class, Updated.class}, message = "{member.id.not_empty}")
|
||||||
private List<String> memberIds;
|
private List<String> memberIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人是否是管理员
|
||||||
|
*/
|
||||||
|
@Schema(description = "创建人是否是管理员")
|
||||||
|
private boolean orgCreateUserIsAdmin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
p.deleted,
|
p.deleted,
|
||||||
p.delete_user,
|
p.delete_user,
|
||||||
p.enable,
|
p.enable,
|
||||||
count(distinct u.id) as number,
|
count(distinct u.id) as memberCount,
|
||||||
o.name as organizationName
|
o.name as organizationName
|
||||||
FROM project p
|
FROM project p
|
||||||
LEFT JOIN user_role_relation u on p.id = u.source_id
|
LEFT JOIN user_role_relation u on p.id = u.source_id
|
||||||
|
|
|
@ -185,6 +185,11 @@ public class CommonProjectService {
|
||||||
projectList.forEach(projectDTO -> {
|
projectList.forEach(projectDTO -> {
|
||||||
List<User> users = extSystemProjectMapper.getProjectAdminList(projectDTO.getId());
|
List<User> users = extSystemProjectMapper.getProjectAdminList(projectDTO.getId());
|
||||||
projectDTO.setAdminList(users);
|
projectDTO.setAdminList(users);
|
||||||
|
List<String> userIds = users.stream().map(User::getId).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(projectDTO.getCreateUser())) {
|
||||||
|
projectDTO.setProjectCreateUserIsAdmin(true);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return projectList;
|
return projectList;
|
||||||
}
|
}
|
||||||
|
@ -463,4 +468,22 @@ public class CommonProjectService {
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(StringUtils.EMPTY));
|
dto.setOriginalValue(JSON.toJSONBytes(StringUtils.EMPTY));
|
||||||
logDTOList.add(dto);
|
logDTOList.add(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enable(String id) {
|
||||||
|
checkProjectNotExist(id);
|
||||||
|
Project project = new Project();
|
||||||
|
project.setId(id);
|
||||||
|
project.setEnable(true);
|
||||||
|
project.setUpdateTime(System.currentTimeMillis());
|
||||||
|
projectMapper.updateByPrimaryKeySelective(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable(String id) {
|
||||||
|
checkProjectNotExist(id);
|
||||||
|
Project project = new Project();
|
||||||
|
project.setId(id);
|
||||||
|
project.setEnable(false);
|
||||||
|
project.setUpdateTime(System.currentTimeMillis());
|
||||||
|
projectMapper.updateByPrimaryKeySelective(project);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.system.service;
|
||||||
|
|
||||||
import io.metersphere.project.domain.Project;
|
import io.metersphere.project.domain.Project;
|
||||||
import io.metersphere.project.mapper.ProjectMapper;
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||||
import io.metersphere.sdk.dto.LogDTO;
|
import io.metersphere.sdk.dto.LogDTO;
|
||||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||||
|
@ -60,6 +61,24 @@ public class OrganizationProjectLogService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LogDTO updateLog(String id) {
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(id);
|
||||||
|
if (project != null) {
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
|
project.getId(),
|
||||||
|
project.getOrganizationId(),
|
||||||
|
project.getId(),
|
||||||
|
project.getCreateUser(),
|
||||||
|
OperationLogType.UPDATE.name(),
|
||||||
|
OperationLogModule.SYSTEM_PROJECT,
|
||||||
|
project.getName());
|
||||||
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
|
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除接口日志
|
* 删除接口日志
|
||||||
|
|
|
@ -93,4 +93,11 @@ public class OrganizationProjectService {
|
||||||
return commonProjectService.revoke(id);
|
return commonProjectService.revoke(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enable(String id) {
|
||||||
|
commonProjectService.enable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable(String id) {
|
||||||
|
commonProjectService.disable(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -772,6 +772,10 @@ public class OrganizationService {
|
||||||
organizationDTOS.forEach(organizationDTO -> {
|
organizationDTOS.forEach(organizationDTO -> {
|
||||||
List<User> orgAdminList = extOrganizationMapper.getOrgAdminList(organizationDTO.getId());
|
List<User> orgAdminList = extOrganizationMapper.getOrgAdminList(organizationDTO.getId());
|
||||||
organizationDTO.setOrgAdmins(orgAdminList);
|
organizationDTO.setOrgAdmins(orgAdminList);
|
||||||
|
List<String> userIds = orgAdminList.stream().map(User::getId).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(organizationDTO.getCreateUser())) {
|
||||||
|
organizationDTO.setOrgCreateUserIsAdmin(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return organizationDTOS;
|
return organizationDTOS;
|
||||||
}
|
}
|
||||||
|
@ -810,4 +814,22 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
return extOrganizationMapper.getOptionsByIds(orgIds);
|
return extOrganizationMapper.getOptionsByIds(orgIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, Long> getTotal(String organizationId) {
|
||||||
|
Map<String, Long> total = new HashMap<>();
|
||||||
|
ProjectExample projectExample = new ProjectExample();
|
||||||
|
OrganizationExample organizationExample = new OrganizationExample();
|
||||||
|
if (StringUtils.isBlank(organizationId)) {
|
||||||
|
// 统计所有项目
|
||||||
|
total.put("projectTotal", projectMapper.countByExample(projectExample));
|
||||||
|
total.put("organizationTotal", organizationMapper.countByExample(organizationExample));
|
||||||
|
} else {
|
||||||
|
// 统计组织下的项目
|
||||||
|
projectExample.createCriteria().andOrganizationIdEqualTo(organizationId);
|
||||||
|
total.put("projectTotal", projectMapper.countByExample(projectExample));
|
||||||
|
total.put("organizationTotal", 1L);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.system.service;
|
||||||
|
|
||||||
import io.metersphere.project.domain.Project;
|
import io.metersphere.project.domain.Project;
|
||||||
import io.metersphere.project.mapper.ProjectMapper;
|
import io.metersphere.project.mapper.ProjectMapper;
|
||||||
|
import io.metersphere.sdk.constants.HttpMethodConstants;
|
||||||
import io.metersphere.sdk.dto.AddProjectRequest;
|
import io.metersphere.sdk.dto.AddProjectRequest;
|
||||||
import io.metersphere.sdk.dto.LogDTO;
|
import io.metersphere.sdk.dto.LogDTO;
|
||||||
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
import io.metersphere.sdk.dto.UpdateProjectRequest;
|
||||||
|
@ -60,6 +61,25 @@ public class SystemProjectLogService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LogDTO updateLog(String id) {
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(id);
|
||||||
|
if (project != null) {
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
|
project.getId(),
|
||||||
|
project.getOrganizationId(),
|
||||||
|
project.getId(),
|
||||||
|
project.getCreateUser(),
|
||||||
|
OperationLogType.UPDATE.name(),
|
||||||
|
OperationLogModule.SYSTEM_PROJECT,
|
||||||
|
project.getName());
|
||||||
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
|
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(project));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除接口日志
|
* 删除接口日志
|
||||||
|
|
|
@ -98,4 +98,12 @@ public class SystemProjectService {
|
||||||
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
|
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
|
||||||
return extSystemProjectMapper.selectProjectOptions();
|
return extSystemProjectMapper.selectProjectOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enable(String id) {
|
||||||
|
commonProjectService.enable(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable(String id) {
|
||||||
|
commonProjectService.disable(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,8 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
private final static String getProjectMemberList = prefix + "/member-list";
|
private final static String getProjectMemberList = prefix + "/member-list";
|
||||||
private final static String addProjectMember = prefix + "/add-members";
|
private final static String addProjectMember = prefix + "/add-members";
|
||||||
private final static String removeProjectMember = prefix + "/remove-member/";
|
private final static String removeProjectMember = prefix + "/remove-member/";
|
||||||
|
private final static String disableProject = prefix + "/disable/";
|
||||||
|
private final static String enableProject = prefix + "/enable/";
|
||||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||||
|
|
||||||
|
@ -665,4 +667,42 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
||||||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
public void disableSuccess() throws Exception {
|
||||||
|
String id = "projectId";
|
||||||
|
this.responseGet(disableProject + id,status().isOk());
|
||||||
|
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||||
|
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||||
|
checkLog(id, OperationLogType.UPDATE);
|
||||||
|
// @@校验权限
|
||||||
|
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE, disableProject + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
public void disableError() throws Exception {
|
||||||
|
String id = "1111";
|
||||||
|
this.responseGet(disableProject + id, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
public void enableSuccess() throws Exception {
|
||||||
|
String id = "projectId";
|
||||||
|
this.responseGet(enableProject + id,status().isOk());
|
||||||
|
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||||
|
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||||
|
checkLog(id, OperationLogType.UPDATE);
|
||||||
|
// @@校验权限
|
||||||
|
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ_UPDATE, enableProject + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
public void enableError() throws Exception {
|
||||||
|
String id = "1111";
|
||||||
|
this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@ -49,6 +48,7 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
||||||
public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member";
|
public static final String ORGANIZATION_REMOVE_MEMBER = "/system/organization/remove-member";
|
||||||
public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project";
|
public static final String ORGANIZATION_LIST_PROJECT = "/system/organization/list-project";
|
||||||
public static final String ORGANIZATION_MEMBER_OPTION = "/system/user/get-option";
|
public static final String ORGANIZATION_MEMBER_OPTION = "/system/user/get-option";
|
||||||
|
public static final String ORGANIZATION_TOTAL = "/system/organization/total";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(0)
|
@Order(0)
|
||||||
|
@ -415,6 +415,23 @@ public class SystemOrganizationControllerTests extends BaseTest{
|
||||||
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_READ, SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
|
requestGetPermissionTest(PermissionConstants.SYSTEM_USER_READ, SystemOrganizationControllerTests.ORGANIZATION_MEMBER_OPTION + "/default-organization-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(17)
|
||||||
|
public void testGetTotal() throws Exception {
|
||||||
|
// 组织不存在
|
||||||
|
MvcResult mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_TOTAL + "?organizationId=default-organization-2");
|
||||||
|
// 获取返回值
|
||||||
|
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
Map<String, Integer> resultHolder = JSON.parseObject(returnData, Map.class);
|
||||||
|
|
||||||
|
mvcResult = this.responseGet(SystemOrganizationControllerTests.ORGANIZATION_TOTAL);
|
||||||
|
// 获取返回值
|
||||||
|
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
resultHolder = JSON.parseObject(returnData, Map.class);
|
||||||
|
// 返回请求正常
|
||||||
|
Assertions.assertNotNull(resultHolder);
|
||||||
|
}
|
||||||
|
|
||||||
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
private void requestPost(String url, Object param, ResultMatcher resultMatcher) throws Exception {
|
||||||
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
mockMvc.perform(MockMvcRequestBuilders.post(url)
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
|
|
|
@ -66,6 +66,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
private final static String getProjectMemberList = prefix + "/member-list";
|
private final static String getProjectMemberList = prefix + "/member-list";
|
||||||
private final static String addProjectMember = prefix + "/add-member";
|
private final static String addProjectMember = prefix + "/add-member";
|
||||||
private final static String removeProjectMember = prefix + "/remove-member/";
|
private final static String removeProjectMember = prefix + "/remove-member/";
|
||||||
|
private final static String disableProject = prefix + "/disable/";
|
||||||
|
private final static String enableProject = prefix + "/enable/";
|
||||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||||
|
|
||||||
|
@ -484,6 +486,8 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
this.responseGet(revokeProject + id, ERROR_REQUEST_MATCHER);
|
this.responseGet(revokeProject + id, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(13)
|
@Order(13)
|
||||||
public void testAddProjectMember() throws Exception{
|
public void testAddProjectMember() throws Exception{
|
||||||
|
@ -627,4 +631,42 @@ public class SystemProjectControllerTests extends BaseTest {
|
||||||
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
this.responseGet(removeProjectMember + projectId + "/" + userId, ERROR_REQUEST_MATCHER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
public void disableSuccess() throws Exception {
|
||||||
|
String id = "projectId";
|
||||||
|
this.responseGet(disableProject + id,status().isOk());
|
||||||
|
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||||
|
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||||
|
checkLog(id, OperationLogType.UPDATE);
|
||||||
|
// @@校验权限
|
||||||
|
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE, disableProject + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
public void disableError() throws Exception {
|
||||||
|
String id = "1111";
|
||||||
|
this.responseGet(disableProject + id, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(19)
|
||||||
|
public void enableSuccess() throws Exception {
|
||||||
|
String id = "projectId";
|
||||||
|
this.responseGet(enableProject + id,status().isOk());
|
||||||
|
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||||
|
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||||
|
checkLog(id, OperationLogType.UPDATE);
|
||||||
|
// @@校验权限
|
||||||
|
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_UPDATE, enableProject + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(20)
|
||||||
|
public void enableError() throws Exception {
|
||||||
|
String id = "1111";
|
||||||
|
this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue