refactor(系统设置): 优化项目查询资源池

This commit is contained in:
wxg0103 2024-01-31 18:31:31 +08:00 committed by 刘瑞斌
parent 015065282f
commit 83e8f78e6c
8 changed files with 141 additions and 95 deletions

View File

@ -4,23 +4,20 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectNameRequest; import io.metersphere.system.dto.UpdateProjectNameRequest;
import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.dto.UpdateProjectRequest;
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.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.dto.request.OrganizationProjectRequest; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.service.OrganizationProjectLogService; import io.metersphere.system.service.OrganizationProjectLogService;
import io.metersphere.system.service.OrganizationProjectService; import io.metersphere.system.service.OrganizationProjectService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
@ -164,15 +161,15 @@ public class OrganizationProjectController {
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
public List<UserExtendDTO> getUserMemberList(@PathVariable String organizationId, @PathVariable String projectId, public List<UserExtendDTO> getUserMemberList(@PathVariable String organizationId, @PathVariable String projectId,
@Schema(description = "查询关键字,根据邮箱和用户名查询") @Schema(description = "查询关键字,根据邮箱和用户名查询")
@RequestParam(value = "keyword", required = false) String keyword) { @RequestParam(value = "keyword", required = false) String keyword) {
return organizationProjectService.getUserMemberList(organizationId, projectId, keyword); return organizationProjectService.getUserMemberList(organizationId, projectId, keyword);
} }
@GetMapping("/pool-options/{organizationId}") @PostMapping("/pool-options")
@Operation(summary = "系统设置-组织-项目-获取资源池下拉选项") @Operation(summary = "系统设置-组织-项目-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) { public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
return organizationProjectService.getTestResourcePoolOptions(organizationId); return organizationProjectService.getTestResourcePoolOptions(request);
} }
@PostMapping("/rename") @PostMapping("/rename")

View File

@ -4,25 +4,22 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectNameRequest; import io.metersphere.system.dto.UpdateProjectNameRequest;
import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.dto.UpdateProjectRequest;
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.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import io.metersphere.system.service.SystemProjectLogService; import io.metersphere.system.service.SystemProjectLogService;
import io.metersphere.system.service.SystemProjectService; import io.metersphere.system.service.SystemProjectService;
import io.metersphere.system.service.UserService; 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.system.utils.SessionUtils;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
@ -101,7 +98,7 @@ public class SystemProjectController {
@Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) @Parameter(name = "id", description = "项目", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
@CheckOwner(resourceId = "#id", resourceType = "project") @CheckOwner(resourceId = "#id", resourceType = "project")
public int revokeProject(@PathVariable String id) { public int revokeProject(@PathVariable String id) {
return systemProjectService.revoke(id, SessionUtils.getUserId()); return systemProjectService.revoke(id, SessionUtils.getUserId());
} }
@GetMapping("/enable/{id}") @GetMapping("/enable/{id}")
@ -160,15 +157,15 @@ public class SystemProjectController {
@Operation(summary = "系统设置-系统-组织与项目-项目-系统-组织及项目, 获取管理员下拉选项") @Operation(summary = "系统设置-系统-组织与项目-项目-系统-组织及项目, 获取管理员下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<User> getUserList(@Schema(description = "查询关键字,根据邮箱和用户名查询") public List<User> getUserList(@Schema(description = "查询关键字,根据邮箱和用户名查询")
@RequestParam(value = "keyword", required = false) String keyword) { @RequestParam(value = "keyword", required = false) String keyword) {
return userService.getUserList(keyword); return userService.getUserList(keyword);
} }
@GetMapping("/pool-options") @PostMapping("/pool-options")
@Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项") @Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项")
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
public List<OptionDTO> getProjectOptions(@RequestParam(value = "organizationId",required = false) String organizationId) { public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
return systemProjectService.getTestResourcePoolOptions(organizationId); return systemProjectService.getTestResourcePoolOptions(request);
} }
@PostMapping("/rename") @PostMapping("/rename")

View File

@ -0,0 +1,20 @@
package io.metersphere.system.dto.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class ProjectPoolRequest implements Serializable {
@Schema(description = "组织id")
@Size(min = 0, max = 50, message = "project.organization_id.length_range")
private String organizationId;
@Schema(description = "项目开启的模块id集合")
@NotEmpty
private List<String> modulesIds;
}

View File

@ -18,6 +18,7 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.*; import io.metersphere.system.dto.*;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest; import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectPoolRequest;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.invoker.ProjectServiceInvoker; import io.metersphere.system.invoker.ProjectServiceInvoker;
@ -74,6 +75,9 @@ public class CommonProjectService {
@Resource @Resource
private TestResourcePoolService testResourcePoolService; private TestResourcePoolService testResourcePoolService;
public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30; public static final Integer DEFAULT_REMAIN_DAY_COUNT = 30;
public static final String API_TEST = "apiTest";
public static final String UI_TEST = "uiTest";
public static final String LOAD_TEST = "loadTest";
@Autowired @Autowired
public CommonProjectService(ProjectServiceInvoker serviceInvoker) { public CommonProjectService(ProjectServiceInvoker serviceInvoker) {
@ -612,12 +616,13 @@ public class CommonProjectService {
projectMapper.updateByPrimaryKeySelective(project); projectMapper.updateByPrimaryKeySelective(project);
} }
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) { public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
List<OptionDTO> optionDTOS = new ArrayList<>();
//获取制定组织的资源池 和全部组织的资源池 //获取制定组织的资源池 和全部组织的资源池
List<TestResourcePool> testResourcePools = new ArrayList<>(); List<TestResourcePool> testResourcePools = new ArrayList<>();
if (StringUtils.isNotBlank(organizationId)) { if (StringUtils.isNotBlank(request.getOrganizationId())) {
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample(); TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
example.createCriteria().andOrgIdEqualTo(organizationId); example.createCriteria().andOrgIdEqualTo(request.getOrganizationId());
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example); List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(orgPools)) { if (CollectionUtils.isNotEmpty(orgPools)) {
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList(); List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
@ -632,9 +637,19 @@ public class CommonProjectService {
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample)); testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()); testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
return testResourcePools.stream().map(testResourcePool -> //这里需要获取项目开启的模块 判断资源池开启的使用范围的模块是否在项目开启的模块中
new OptionDTO(testResourcePool.getId(), testResourcePool.getName()) List<String> moduleIds = request.getModulesIds();
).toList(); testResourcePools.forEach(pool -> {
if ((moduleIds.contains(API_TEST) && pool.getApiTest()) ||
(moduleIds.contains(LOAD_TEST) && pool.getLoadTest()) ||
(moduleIds.contains(UI_TEST) && pool.getUiTest())) {
OptionDTO optionDTO = new OptionDTO();
optionDTO.setId(pool.getId());
optionDTO.setName(pool.getName());
optionDTOS.add(optionDTO);
}
});
return optionDTOS;
} }
public void rename(UpdateProjectNameRequest request, String userId) { public void rename(UpdateProjectNameRequest request, String userId) {
@ -653,6 +668,7 @@ public class CommonProjectService {
/** /**
* 校验该项目是否有权限使用该资源池 * 校验该项目是否有权限使用该资源池
*
* @param resourcePool * @param resourcePool
* @return * @return
*/ */
@ -683,6 +699,7 @@ public class CommonProjectService {
/** /**
* 剩余天数 * 剩余天数
*
* @param deleteTime 删除时间 * @param deleteTime 删除时间
* @return 剩余天数 * @return 剩余天数
*/ */

View File

@ -1,7 +1,5 @@
package io.metersphere.system.service; package io.metersphere.system.service;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
@ -11,15 +9,14 @@ import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.UpdateProjectNameRequest; import io.metersphere.system.dto.UpdateProjectNameRequest;
import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.dto.UpdateProjectRequest;
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.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.OrganizationMapper; import io.metersphere.system.mapper.OrganizationMapper;
import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.dto.request.OrganizationProjectRequest;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -131,8 +128,8 @@ public class OrganizationProjectService {
} }
} }
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) { public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
return commonProjectService.getTestResourcePoolOptions(organizationId); return commonProjectService.getTestResourcePoolOptions(request);
} }
public void rename(UpdateProjectNameRequest project, String userId) { public void rename(UpdateProjectNameRequest project, String userId) {

View File

@ -1,16 +1,17 @@
package io.metersphere.system.service; package io.metersphere.system.service;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.*; import io.metersphere.system.dto.*;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.dto.request.ProjectPoolRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.dto.request.ProjectRequest;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -96,8 +97,8 @@ public class SystemProjectService {
commonProjectService.disable(id, updateUser); commonProjectService.disable(id, updateUser);
} }
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) { public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
return commonProjectService.getTestResourcePoolOptions(organizationId); return commonProjectService.getTestResourcePoolOptions(request);
} }

View File

@ -19,6 +19,7 @@ import io.metersphere.system.dto.*;
import io.metersphere.system.dto.request.OrganizationProjectRequest; import io.metersphere.system.dto.request.OrganizationProjectRequest;
import io.metersphere.system.dto.request.ProjectAddMemberRequest; import io.metersphere.system.dto.request.ProjectAddMemberRequest;
import io.metersphere.system.dto.request.ProjectMemberRequest; import io.metersphere.system.dto.request.ProjectMemberRequest;
import io.metersphere.system.dto.request.ProjectPoolRequest;
import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.invoker.ProjectServiceInvoker; import io.metersphere.system.invoker.ProjectServiceInvoker;
@ -50,7 +51,7 @@ import java.util.List;
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;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class OrganizationProjectControllerTests extends BaseTest { public class OrganizationProjectControllerTests extends BaseTest {
@ -128,8 +129,9 @@ public class OrganizationProjectControllerTests extends BaseTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
} }
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception { private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(url) mockMvc.perform(MockMvcRequestBuilders.get(url)
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
@ -148,6 +150,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
} }
return null; return null;
} }
public static void compareProjectDTO(Project currentProject, Project result) { public static void compareProjectDTO(Project currentProject, Project result) {
Assertions.assertNotNull(currentProject); Assertions.assertNotNull(currentProject);
Assertions.assertNotNull(result); Assertions.assertNotNull(result);
@ -173,6 +176,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
addProjectDTO.setUserIds(userIds); addProjectDTO.setUserIds(userIds);
return addProjectDTO; return addProjectDTO;
} }
public UpdateProjectRequest generatorUpdate(String organizationId, public UpdateProjectRequest generatorUpdate(String organizationId,
String projectId, String projectId,
String name, String name,
@ -285,6 +289,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
serviceInvoker.invokeCreateServices(initProject.getId()); serviceInvoker.invokeCreateServices(initProject.getId());
} }
} }
@Test @Test
@Order(1) @Order(1)
@Sql(scripts = {"/dml/init_org_project.sql"}, @Sql(scripts = {"/dml/init_org_project.sql"},
@ -295,7 +300,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
*/ */
public void testAddProjectSuccess() throws Exception { public void testAddProjectSuccess() throws Exception {
initData(); initData();
AddProjectRequest project = this.generatorAdd("organizationId","organization-name", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd("organizationId", "organization-name", "description", true, List.of("admin"));
MvcResult mvcResult = this.responsePost(addProject, project); MvcResult mvcResult = this.responsePost(addProject, project);
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
ProjectExample projectExample = new ProjectExample(); ProjectExample projectExample = new ProjectExample();
@ -312,7 +317,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin")); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
userRoleRelationExample.createCriteria().andSourceIdEqualTo("organizationId").andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue()); userRoleRelationExample.createCriteria().andSourceIdEqualTo("organizationId").andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue());
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin")); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
projectId = result.getId(); projectId = result.getId();
Project projectExtend = projectMapper.selectByPrimaryKey(projectId); Project projectExtend = projectMapper.selectByPrimaryKey(projectId);
@ -321,7 +326,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
checkLog(projectId, OperationLogType.ADD); checkLog(projectId, OperationLogType.ADD);
//userId为空的时候 //userId为空的时候
project = this.generatorAdd("organizationId","organization-userIdIsNull", "description", true, new ArrayList<>()); project = this.generatorAdd("organizationId", "organization-userIdIsNull", "description", true, new ArrayList<>());
mvcResult = this.responsePost(addProject, project); mvcResult = this.responsePost(addProject, project);
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
projectExample = new ProjectExample(); projectExample = new ProjectExample();
@ -391,7 +396,6 @@ public class OrganizationProjectControllerTests extends BaseTest {
Assertions.assertTrue(projectTestResourcePools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList().contains("resourcePoolId")); Assertions.assertTrue(projectTestResourcePools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList().contains("resourcePoolId"));
project.setName("organization-testAddProjectSuccess1"); project.setName("organization-testAddProjectSuccess1");
project.setOrganizationId(getDefault().getId()); project.setOrganizationId(getDefault().getId());
// @@校验权限 // @@校验权限
@ -404,10 +408,10 @@ public class OrganizationProjectControllerTests extends BaseTest {
* 测试添加项目失败的用例 * 测试添加项目失败的用例
*/ */
public void testAddProjectError() throws Exception { public void testAddProjectError() throws Exception {
AddProjectRequest project = this.generatorAdd("organizationId","organization-nameError", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd("organizationId", "organization-nameError", "description", true, List.of("admin"));
this.responsePost(addProject, project); this.responsePost(addProject, project);
//项目名称存在 500 //项目名称存在 500
project = this.generatorAdd("organizationId","organization-nameError", "description", true, List.of("admin")); project = this.generatorAdd("organizationId", "organization-nameError", "description", true, List.of("admin"));
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER); this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
//参数组织Id为空 //参数组织Id为空
project = this.generatorAdd(null, null, null, true, List.of("admin")); project = this.generatorAdd(null, null, null, true, List.of("admin"));
@ -424,10 +428,11 @@ public class OrganizationProjectControllerTests extends BaseTest {
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER); this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
} }
@Test @Test
@Order(3) @Order(3)
public void testGetProject() throws Exception { public void testGetProject() throws Exception {
AddProjectRequest project = this.generatorAdd("organizationId","organization-getName", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd("organizationId", "organization-getName", "description", true, List.of("admin"));
MvcResult mvcResult = this.responsePost(addProject, project); MvcResult mvcResult = this.responsePost(addProject, project);
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
assert result != null; assert result != null;
@ -448,6 +453,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getProject + projectId); requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getProject + projectId);
} }
@Test @Test
@Order(4) @Order(4)
public void testGetProjectError() throws Exception { public void testGetProjectError() throws Exception {
@ -565,7 +571,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(7) @Order(7)
public void testUpdateProject() throws Exception { public void testUpdateProject() throws Exception {
UpdateProjectRequest project = this.generatorUpdate("organizationId", projectId,"organization-TestName", "Edit name", true, List.of("admin1")); UpdateProjectRequest project = this.generatorUpdate("organizationId", projectId, "organization-TestName", "Edit name", true, List.of("admin1"));
Project projectExtend = projectMapper.selectByPrimaryKey(projectId); Project projectExtend = projectMapper.selectByPrimaryKey(projectId);
List<String> moduleIds = new ArrayList<>(); List<String> moduleIds = new ArrayList<>();
if (StringUtils.isNotBlank(projectExtend.getModuleSetting())) { if (StringUtils.isNotBlank(projectExtend.getModuleSetting())) {
@ -625,7 +631,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
//设置资源池 //设置资源池
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId3", "org-updatePools", "org-updatePools", true, new ArrayList<>()); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId3", "org-updatePools", "org-updatePools", true, new ArrayList<>());
project.setResourcePoolIds(List.of("resourcePoolId","resourcePoolId1")); project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
mvcResult = this.responsePost(updateProject, project); mvcResult = this.responsePost(updateProject, project);
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
currentProject = projectMapper.selectByPrimaryKey(project.getId()); currentProject = projectMapper.selectByPrimaryKey(project.getId());
@ -650,7 +656,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "org-Module", "description", true, List.of("admin")); UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "org-Module", "description", true, List.of("admin"));
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER); this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
//参数组织Id为空 //参数组织Id为空
project = this.generatorUpdate(null, "projectId",null, null, true , List.of("admin")); project = this.generatorUpdate(null, "projectId", null, null, true, List.of("admin"));
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER); this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
//项目Id为空 //项目Id为空
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null, null, null, true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null, null, null, true, List.of("admin"));
@ -714,7 +720,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(13) @Order(13)
public void testAddProjectMember() throws Exception{ public void testAddProjectMember() throws Exception {
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest(); ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
projectAddMemberRequest.setProjectId(projectId); projectAddMemberRequest.setProjectId(projectId);
List<String> userIds = List.of("admin1", "admin2"); List<String> userIds = List.of("admin1", "admin2");
@ -725,7 +731,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(userIds)); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(userIds));
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(userIds)); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().containsAll(userIds));
userRoleRelations.forEach(item ->{ userRoleRelations.forEach(item -> {
try { try {
checkLog(item.getId(), OperationLogType.ADD); checkLog(item.getId(), OperationLogType.ADD);
} catch (Exception e) { } catch (Exception e) {
@ -738,7 +744,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(14) @Order(14)
public void testAddProjectMemberError() throws Exception{ public void testAddProjectMemberError() throws Exception {
//项目Id为空 //项目Id为空
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest(); ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
projectAddMemberRequest.setProjectId(null); projectAddMemberRequest.setProjectId(null);
@ -831,7 +837,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(17) @Order(17)
public void testRemoveProjectMember() throws Exception{ public void testRemoveProjectMember() throws Exception {
String userId = "admin1"; String userId = "admin1";
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
userRoleRelationExample.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId); userRoleRelationExample.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId);
@ -847,7 +853,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(18) @Order(18)
public void testRemoveProjectMemberError() throws Exception{ public void testRemoveProjectMemberError() throws Exception {
String userId = "admin1"; String userId = "admin1";
MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId); MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId);
int count = parseObjectFromMvcResult(mvcResult, Integer.class); int count = parseObjectFromMvcResult(mvcResult, Integer.class);
@ -867,7 +873,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Order(19) @Order(19)
public void disableSuccess() throws Exception { public void disableSuccess() throws Exception {
String id = "projectId"; String id = "projectId";
this.responseGet(disableProject + id,status().isOk()); this.responseGet(disableProject + id, status().isOk());
Project currentProject = projectMapper.selectByPrimaryKey(id); Project currentProject = projectMapper.selectByPrimaryKey(id);
Assertions.assertEquals(currentProject.getEnable(), false); Assertions.assertEquals(currentProject.getEnable(), false);
checkLog(id, OperationLogType.UPDATE); checkLog(id, OperationLogType.UPDATE);
@ -886,7 +892,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Order(19) @Order(19)
public void enableSuccess() throws Exception { public void enableSuccess() throws Exception {
String id = "projectId"; String id = "projectId";
this.responseGet(enableProject + id,status().isOk()); this.responseGet(enableProject + id, status().isOk());
Project currentProject = projectMapper.selectByPrimaryKey(id); Project currentProject = projectMapper.selectByPrimaryKey(id);
Assertions.assertEquals(currentProject.getEnable(), true); Assertions.assertEquals(currentProject.getEnable(), true);
checkLog(id, OperationLogType.UPDATE); checkLog(id, OperationLogType.UPDATE);
@ -959,9 +965,12 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Test @Test
@Order(23) @Order(23)
public void testGetOptions() throws Exception { public void testGetOptions() throws Exception {
this.requestGetWithOkAndReturn(getPoolOptions + "organizationId"); ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
this.responsePost(getPoolOptions, projectPoolRequest);
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions + DEFAULT_ORGANIZATION_ID); requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
} }
@Test @Test

View File

@ -54,7 +54,7 @@ import java.util.stream.Collectors;
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;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class SystemProjectControllerTests extends BaseTest { public class SystemProjectControllerTests extends BaseTest {
@ -149,8 +149,9 @@ public class SystemProjectControllerTests extends BaseTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
} }
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception { private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(url) mockMvc.perform(MockMvcRequestBuilders.get(url)
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
@ -169,6 +170,7 @@ public class SystemProjectControllerTests extends BaseTest {
} }
return null; return null;
} }
public static void compareProjectDTO(Project currentProject, Project result) { public static void compareProjectDTO(Project currentProject, Project result) {
Assertions.assertNotNull(currentProject); Assertions.assertNotNull(currentProject);
Assertions.assertNotNull(result); Assertions.assertNotNull(result);
@ -194,6 +196,7 @@ public class SystemProjectControllerTests extends BaseTest {
addProjectDTO.setUserIds(userIds); addProjectDTO.setUserIds(userIds);
return addProjectDTO; return addProjectDTO;
} }
public UpdateProjectRequest generatorUpdate(String organizationId, public UpdateProjectRequest generatorUpdate(String organizationId,
String projectId, String projectId,
String name, String name,
@ -308,6 +311,7 @@ public class SystemProjectControllerTests extends BaseTest {
serviceInvoker.invokeCreateServices(initProject.getId()); serviceInvoker.invokeCreateServices(initProject.getId());
} }
} }
@Test @Test
@Order(1) @Order(1)
/** /**
@ -319,7 +323,7 @@ public class SystemProjectControllerTests extends BaseTest {
public void testAddProjectSuccess() throws Exception { public void testAddProjectSuccess() throws Exception {
initData(); initData();
addMultipleCustomField(); addMultipleCustomField();
AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"name", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "name", "description", true, List.of("admin"));
MvcResult mvcResult = this.responsePost(addProject, project); MvcResult mvcResult = this.responsePost(addProject, project);
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
ProjectExample projectExample = new ProjectExample(); ProjectExample projectExample = new ProjectExample();
@ -336,7 +340,7 @@ public class SystemProjectControllerTests extends BaseTest {
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin")); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
userRoleRelationExample.createCriteria().andSourceIdEqualTo(DEFAULT_ORGANIZATION_ID).andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue()); userRoleRelationExample.createCriteria().andSourceIdEqualTo(DEFAULT_ORGANIZATION_ID).andRoleIdEqualTo(InternalUserRole.ORG_MEMBER.getValue());
userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin")); Assertions.assertTrue(userRoleRelations.stream().map(UserRoleRelation::getUserId).toList().contains("admin"));
Project currentProject = projectMapper.selectByPrimaryKey(projectId); Project currentProject = projectMapper.selectByPrimaryKey(projectId);
Assertions.assertNull(currentProject.getModuleSetting()); Assertions.assertNull(currentProject.getModuleSetting());
@ -345,7 +349,7 @@ public class SystemProjectControllerTests extends BaseTest {
assertionsRefStatusFlowSetting(projectId); assertionsRefStatusFlowSetting(projectId);
//userId为空的时候 //userId为空的时候
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"userIdIsNull", "description", true, new ArrayList<>()); project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "userIdIsNull", "description", true, new ArrayList<>());
// 开启项目模板 // 开启项目模板
changeOrgTemplateEnable(false); changeOrgTemplateEnable(false);
mvcResult = this.responsePost(addProject, project); mvcResult = this.responsePost(addProject, project);
@ -604,10 +608,10 @@ public class SystemProjectControllerTests extends BaseTest {
* 测试添加项目失败的用例 * 测试添加项目失败的用例
*/ */
public void testAddProjectError() throws Exception { public void testAddProjectError() throws Exception {
AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"nameError", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "nameError", "description", true, List.of("admin"));
this.responsePost(addProject, project); this.responsePost(addProject, project);
//项目名称存在 500 //项目名称存在 500
project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"nameError", "description", true, List.of("admin")); project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "nameError", "description", true, List.of("admin"));
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER); this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
//参数组织Id为空 //参数组织Id为空
project = this.generatorAdd(null, null, null, true, List.of("admin")); project = this.generatorAdd(null, null, null, true, List.of("admin"));
@ -624,10 +628,11 @@ public class SystemProjectControllerTests extends BaseTest {
this.requestPost(addProject, project, ERROR_REQUEST_MATCHER); this.requestPost(addProject, project, ERROR_REQUEST_MATCHER);
} }
@Test @Test
@Order(3) @Order(3)
public void testGetProject() throws Exception { public void testGetProject() throws Exception {
AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID,"getName", "description", true, List.of("admin")); AddProjectRequest project = this.generatorAdd(DEFAULT_ORGANIZATION_ID, "getName", "description", true, List.of("admin"));
List<String> moduleIds = new ArrayList<>(); List<String> moduleIds = new ArrayList<>();
moduleIds.add("apiTest"); moduleIds.add("apiTest");
moduleIds.add("uiTest"); moduleIds.add("uiTest");
@ -643,6 +648,7 @@ public class SystemProjectControllerTests extends BaseTest {
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProject + projectId); requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProject + projectId);
} }
@Test @Test
@Order(4) @Order(4)
public void testGetProjectError() throws Exception { public void testGetProjectError() throws Exception {
@ -760,7 +766,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(7) @Order(7)
public void testUpdateProject() throws Exception { public void testUpdateProject() throws Exception {
UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1","TestName", "Edit name", true, List.of("admin", "admin1")); UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId1", "TestName", "Edit name", true, List.of("admin", "admin1"));
MvcResult mvcResult = this.responsePost(updateProject, project); MvcResult mvcResult = this.responsePost(updateProject, project);
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
Project currentProject = projectMapper.selectByPrimaryKey(project.getId()); Project currentProject = projectMapper.selectByPrimaryKey(project.getId());
@ -809,7 +815,7 @@ public class SystemProjectControllerTests extends BaseTest {
//设置资源池 //设置资源池
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId5", "updatePools", "updatePools", true, new ArrayList<>()); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId5", "updatePools", "updatePools", true, new ArrayList<>());
project.setResourcePoolIds(List.of("resourcePoolId","resourcePoolId1")); project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
mvcResult = this.responsePost(updateProject, project); mvcResult = this.responsePost(updateProject, project);
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class); result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
currentProject = projectMapper.selectByPrimaryKey(project.getId()); currentProject = projectMapper.selectByPrimaryKey(project.getId());
@ -830,22 +836,22 @@ public class SystemProjectControllerTests extends BaseTest {
@Order(8) @Order(8)
public void testUpdateProjectError() throws Exception { public void testUpdateProjectError() throws Exception {
//项目名称存在 500 //项目名称存在 500
UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2","TestName2", "description", true, List.of("admin")); UpdateProjectRequest project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "TestName2", "description", true, List.of("admin"));
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER); this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
//参数组织Id为空 //参数组织Id为空
project = this.generatorUpdate(null, "projectId",null, null, true , List.of("admin")); project = this.generatorUpdate(null, "projectId", null, null, true, List.of("admin"));
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER); this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
//项目Id为空 //项目Id为空
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null,null, null, true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null, null, null, true, List.of("admin"));
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER); this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
//项目名称为空 //项目名称为空
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId",null, null, true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", null, null, true, List.of("admin"));
this.requestPost(updateProject, project, BAD_REQUEST_MATCHER); this.requestPost(updateProject, project, BAD_REQUEST_MATCHER);
//项目不存在 //项目不存在
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "1111","123", null, true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "1111", "123", null, true, List.of("admin"));
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER); this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
//资源池不存在 //资源池不存在
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2","pool-edit", "description", true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "pool-edit", "description", true, List.of("admin"));
project.setResourcePoolIds(List.of("resourcePoolId3")); project.setResourcePoolIds(List.of("resourcePoolId3"));
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER); this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
@ -894,10 +900,9 @@ public class SystemProjectControllerTests extends BaseTest {
} }
@Test @Test
@Order(13) @Order(13)
public void testAddProjectMember() throws Exception{ public void testAddProjectMember() throws Exception {
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest(); ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
projectAddMemberRequest.setProjectId("projectId"); projectAddMemberRequest.setProjectId("projectId");
List<String> userIds = List.of("admin1", "admin2"); List<String> userIds = List.of("admin1", "admin2");
@ -914,7 +919,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(14) @Order(14)
public void testAddProjectMemberError() throws Exception{ public void testAddProjectMemberError() throws Exception {
//项目Id为空 //项目Id为空
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest(); ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
projectAddMemberRequest.setProjectId(null); projectAddMemberRequest.setProjectId(null);
@ -1008,7 +1013,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(17) @Order(17)
public void testRemoveProjectMember() throws Exception{ public void testRemoveProjectMember() throws Exception {
String projectId = "projectId1"; String projectId = "projectId1";
String userId = "admin1"; String userId = "admin1";
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
@ -1023,7 +1028,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(18) @Order(18)
public void testRemoveProjectMemberError() throws Exception{ public void testRemoveProjectMemberError() throws Exception {
String projectId = "projectId1"; String projectId = "projectId1";
String userId = "admin1"; String userId = "admin1";
MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId); MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId);
@ -1044,7 +1049,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Order(19) @Order(19)
public void disableSuccess() throws Exception { public void disableSuccess() throws Exception {
String id = "projectId"; String id = "projectId";
this.responseGet(disableProject + id,status().isOk()); this.responseGet(disableProject + id, status().isOk());
Project currentProject = projectMapper.selectByPrimaryKey(id); Project currentProject = projectMapper.selectByPrimaryKey(id);
Assertions.assertEquals(currentProject.getEnable(), false); Assertions.assertEquals(currentProject.getEnable(), false);
checkLog(id, OperationLogType.UPDATE); checkLog(id, OperationLogType.UPDATE);
@ -1063,7 +1068,7 @@ public class SystemProjectControllerTests extends BaseTest {
@Order(19) @Order(19)
public void enableSuccess() throws Exception { public void enableSuccess() throws Exception {
String id = "projectId"; String id = "projectId";
this.responseGet(enableProject + id,status().isOk()); this.responseGet(enableProject + id, status().isOk());
Project currentProject = projectMapper.selectByPrimaryKey(id); Project currentProject = projectMapper.selectByPrimaryKey(id);
Assertions.assertEquals(currentProject.getEnable(), true); Assertions.assertEquals(currentProject.getEnable(), true);
checkLog(id, OperationLogType.UPDATE); checkLog(id, OperationLogType.UPDATE);
@ -1091,10 +1096,13 @@ public class SystemProjectControllerTests extends BaseTest {
@Test @Test
@Order(22) @Order(22)
public void testGetOptions() throws Exception { public void testGetOptions() throws Exception {
this.requestGetWithOkAndReturn(getPoolOptions); ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
this.requestGetWithOkAndReturn(getPoolOptions + "?organizationId=" + DEFAULT_ORGANIZATION_ID); projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest"));
this.responsePost(getPoolOptions, projectPoolRequest);
projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID);
this.responsePost(getPoolOptions, projectPoolRequest);
// @@校验权限 // @@校验权限
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions + "?organizationId=" + DEFAULT_ORGANIZATION_ID); requestPostPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest);
} }
@Test @Test