refactor(系统设置): 优化项目查询资源池
This commit is contained in:
parent
015065282f
commit
83e8f78e6c
|
@ -4,23 +4,20 @@ package io.metersphere.system.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
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.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
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.constants.OperationLogType;
|
||||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
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.security.CheckOwner;
|
||||
import io.metersphere.system.service.OrganizationProjectLogService;
|
||||
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.validation.groups.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
|
@ -168,11 +165,11 @@ public class OrganizationProjectController {
|
|||
return organizationProjectService.getUserMemberList(organizationId, projectId, keyword);
|
||||
}
|
||||
|
||||
@GetMapping("/pool-options/{organizationId}")
|
||||
@PostMapping("/pool-options")
|
||||
@Operation(summary = "系统设置-组织-项目-获取资源池下拉选项")
|
||||
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
|
||||
public List<OptionDTO> getProjectOptions(@PathVariable String organizationId) {
|
||||
return organizationProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
|
||||
return organizationProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
|
|
|
@ -4,25 +4,22 @@ package io.metersphere.system.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
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.dto.AddProjectRequest;
|
||||
import io.metersphere.system.dto.ProjectDTO;
|
||||
import io.metersphere.system.dto.UpdateProjectNameRequest;
|
||||
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.constants.OperationLogType;
|
||||
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.dto.request.ProjectRequest;
|
||||
import io.metersphere.system.security.CheckOwner;
|
||||
import io.metersphere.system.service.SystemProjectLogService;
|
||||
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.Created;
|
||||
import io.metersphere.validation.groups.Updated;
|
||||
|
@ -164,11 +161,11 @@ public class SystemProjectController {
|
|||
return userService.getUserList(keyword);
|
||||
}
|
||||
|
||||
@GetMapping("/pool-options")
|
||||
@PostMapping("/pool-options")
|
||||
@Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ)
|
||||
public List<OptionDTO> getProjectOptions(@RequestParam(value = "organizationId",required = false) String organizationId) {
|
||||
return systemProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getProjectOptions(@Validated @RequestBody ProjectPoolRequest request) {
|
||||
return systemProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -18,6 +18,7 @@ import io.metersphere.sdk.util.Translator;
|
|||
import io.metersphere.system.domain.*;
|
||||
import io.metersphere.system.dto.*;
|
||||
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.user.UserExtendDTO;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
|
@ -74,6 +75,9 @@ public class CommonProjectService {
|
|||
@Resource
|
||||
private TestResourcePoolService testResourcePoolService;
|
||||
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
|
||||
public CommonProjectService(ProjectServiceInvoker serviceInvoker) {
|
||||
|
@ -612,12 +616,13 @@ public class CommonProjectService {
|
|||
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<>();
|
||||
if (StringUtils.isNotBlank(organizationId)) {
|
||||
if (StringUtils.isNotBlank(request.getOrganizationId())) {
|
||||
TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample();
|
||||
example.createCriteria().andOrgIdEqualTo(organizationId);
|
||||
example.createCriteria().andOrgIdEqualTo(request.getOrganizationId());
|
||||
List<TestResourcePoolOrganization> orgPools = testResourcePoolOrganizationMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(orgPools)) {
|
||||
List<String> poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList();
|
||||
|
@ -632,9 +637,19 @@ public class CommonProjectService {
|
|||
testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample));
|
||||
|
||||
testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
return testResourcePools.stream().map(testResourcePool ->
|
||||
new OptionDTO(testResourcePool.getId(), testResourcePool.getName())
|
||||
).toList();
|
||||
//这里需要获取项目开启的模块 判断资源池开启的使用范围的模块是否在项目开启的模块中
|
||||
List<String> moduleIds = request.getModulesIds();
|
||||
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) {
|
||||
|
@ -653,6 +668,7 @@ public class CommonProjectService {
|
|||
|
||||
/**
|
||||
* 校验该项目是否有权限使用该资源池
|
||||
*
|
||||
* @param resourcePool
|
||||
* @return
|
||||
*/
|
||||
|
@ -683,6 +699,7 @@ public class CommonProjectService {
|
|||
|
||||
/**
|
||||
* 剩余天数
|
||||
*
|
||||
* @param deleteTime 删除时间
|
||||
* @return 剩余天数
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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.util.BeanUtils;
|
||||
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.UpdateProjectNameRequest;
|
||||
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.OperationLogType;
|
||||
import io.metersphere.system.mapper.ExtSystemProjectMapper;
|
||||
import io.metersphere.system.mapper.OrganizationMapper;
|
||||
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 org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -131,8 +128,8 @@ public class OrganizationProjectService {
|
|||
}
|
||||
}
|
||||
|
||||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
|
||||
return commonProjectService.getTestResourcePoolOptions(request);
|
||||
}
|
||||
|
||||
public void rename(UpdateProjectNameRequest project, String userId) {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package io.metersphere.system.service;
|
||||
|
||||
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.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.OperationLogType;
|
||||
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 org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -96,8 +97,8 @@ public class SystemProjectService {
|
|||
commonProjectService.disable(id, updateUser);
|
||||
}
|
||||
|
||||
public List<OptionDTO> getTestResourcePoolOptions(String organizationId) {
|
||||
return commonProjectService.getTestResourcePoolOptions(organizationId);
|
||||
public List<OptionDTO> getTestResourcePoolOptions(ProjectPoolRequest request) {
|
||||
return commonProjectService.getTestResourcePoolOptions(request);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.metersphere.system.dto.*;
|
|||
import io.metersphere.system.dto.request.OrganizationProjectRequest;
|
||||
import io.metersphere.system.dto.request.ProjectAddMemberRequest;
|
||||
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.UserExtendDTO;
|
||||
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.status;
|
||||
|
||||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class OrganizationProjectControllerTests extends BaseTest {
|
||||
|
@ -128,6 +129,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -148,6 +150,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void compareProjectDTO(Project currentProject, Project result) {
|
||||
Assertions.assertNotNull(currentProject);
|
||||
Assertions.assertNotNull(result);
|
||||
|
@ -173,6 +176,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
addProjectDTO.setUserIds(userIds);
|
||||
return addProjectDTO;
|
||||
}
|
||||
|
||||
public UpdateProjectRequest generatorUpdate(String organizationId,
|
||||
String projectId,
|
||||
String name,
|
||||
|
@ -285,6 +289,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Sql(scripts = {"/dml/init_org_project.sql"},
|
||||
|
@ -295,7 +300,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
*/
|
||||
public void testAddProjectSuccess() throws Exception {
|
||||
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);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
|
@ -321,7 +326,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
checkLog(projectId, OperationLogType.ADD);
|
||||
|
||||
//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);
|
||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
projectExample = new ProjectExample();
|
||||
|
@ -391,7 +396,6 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
Assertions.assertTrue(projectTestResourcePools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList().contains("resourcePoolId"));
|
||||
|
||||
|
||||
|
||||
project.setName("organization-testAddProjectSuccess1");
|
||||
project.setOrganizationId(getDefault().getId());
|
||||
// @@校验权限
|
||||
|
@ -404,10 +408,10 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
* 测试添加项目失败的用例
|
||||
*/
|
||||
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);
|
||||
//项目名称存在 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);
|
||||
//参数组织Id为空
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
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);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
assert result != null;
|
||||
|
@ -448,6 +453,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getProject + projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testGetProjectError() throws Exception {
|
||||
|
@ -565,7 +571,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(7)
|
||||
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);
|
||||
List<String> moduleIds = new ArrayList<>();
|
||||
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.setResourcePoolIds(List.of("resourcePoolId","resourcePoolId1"));
|
||||
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
||||
mvcResult = this.responsePost(updateProject, project);
|
||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
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"));
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
//参数组织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);
|
||||
//项目Id为空
|
||||
project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, null, null, null, true, List.of("admin"));
|
||||
|
@ -714,7 +720,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testAddProjectMember() throws Exception{
|
||||
public void testAddProjectMember() throws Exception {
|
||||
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId(projectId);
|
||||
List<String> userIds = List.of("admin1", "admin2");
|
||||
|
@ -725,7 +731,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
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));
|
||||
userRoleRelations.forEach(item ->{
|
||||
userRoleRelations.forEach(item -> {
|
||||
try {
|
||||
checkLog(item.getId(), OperationLogType.ADD);
|
||||
} catch (Exception e) {
|
||||
|
@ -738,7 +744,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(14)
|
||||
public void testAddProjectMemberError() throws Exception{
|
||||
public void testAddProjectMemberError() throws Exception {
|
||||
//项目Id为空
|
||||
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId(null);
|
||||
|
@ -831,7 +837,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(17)
|
||||
public void testRemoveProjectMember() throws Exception{
|
||||
public void testRemoveProjectMember() throws Exception {
|
||||
String userId = "admin1";
|
||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||
userRoleRelationExample.createCriteria().andSourceIdEqualTo(projectId).andUserIdEqualTo(userId);
|
||||
|
@ -847,7 +853,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(18)
|
||||
public void testRemoveProjectMemberError() throws Exception{
|
||||
public void testRemoveProjectMemberError() throws Exception {
|
||||
String userId = "admin1";
|
||||
MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId);
|
||||
int count = parseObjectFromMvcResult(mvcResult, Integer.class);
|
||||
|
@ -867,7 +873,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
@Order(19)
|
||||
public void disableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(disableProject + id,status().isOk());
|
||||
this.responseGet(disableProject + id, status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
|
@ -886,7 +892,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
@Order(19)
|
||||
public void enableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(enableProject + id,status().isOk());
|
||||
this.responseGet(enableProject + id, status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
|
@ -959,9 +965,12 @@ public class OrganizationProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(23)
|
||||
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
|
||||
|
|
|
@ -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.status;
|
||||
|
||||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class SystemProjectControllerTests extends BaseTest {
|
||||
|
@ -149,6 +149,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
private void responseGet(String url, ResultMatcher resultMatcher) throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(url)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -169,6 +170,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void compareProjectDTO(Project currentProject, Project result) {
|
||||
Assertions.assertNotNull(currentProject);
|
||||
Assertions.assertNotNull(result);
|
||||
|
@ -194,6 +196,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
addProjectDTO.setUserIds(userIds);
|
||||
return addProjectDTO;
|
||||
}
|
||||
|
||||
public UpdateProjectRequest generatorUpdate(String organizationId,
|
||||
String projectId,
|
||||
String name,
|
||||
|
@ -308,6 +311,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
serviceInvoker.invokeCreateServices(initProject.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
/**
|
||||
|
@ -319,7 +323,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
public void testAddProjectSuccess() throws Exception {
|
||||
initData();
|
||||
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);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
ProjectExample projectExample = new ProjectExample();
|
||||
|
@ -345,7 +349,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
assertionsRefStatusFlowSetting(projectId);
|
||||
|
||||
//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);
|
||||
mvcResult = this.responsePost(addProject, project);
|
||||
|
@ -604,10 +608,10 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
* 测试添加项目失败的用例
|
||||
*/
|
||||
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);
|
||||
//项目名称存在 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);
|
||||
//参数组织Id为空
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
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<>();
|
||||
moduleIds.add("apiTest");
|
||||
moduleIds.add("uiTest");
|
||||
|
@ -643,6 +648,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, getProject + projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void testGetProjectError() throws Exception {
|
||||
|
@ -760,7 +766,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(7)
|
||||
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);
|
||||
ProjectDTO result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
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.setResourcePoolIds(List.of("resourcePoolId","resourcePoolId1"));
|
||||
project.setResourcePoolIds(List.of("resourcePoolId", "resourcePoolId1"));
|
||||
mvcResult = this.responsePost(updateProject, project);
|
||||
result = parseObjectFromMvcResult(mvcResult, ProjectDTO.class);
|
||||
currentProject = projectMapper.selectByPrimaryKey(project.getId());
|
||||
|
@ -830,22 +836,22 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Order(8)
|
||||
public void testUpdateProjectError() throws Exception {
|
||||
//项目名称存在 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);
|
||||
//参数组织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);
|
||||
//项目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);
|
||||
//项目名称为空
|
||||
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);
|
||||
//项目不存在
|
||||
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);
|
||||
//资源池不存在
|
||||
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"));
|
||||
this.requestPost(updateProject, project, ERROR_REQUEST_MATCHER);
|
||||
|
||||
|
@ -894,10 +900,9 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
public void testAddProjectMember() throws Exception{
|
||||
public void testAddProjectMember() throws Exception {
|
||||
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId("projectId");
|
||||
List<String> userIds = List.of("admin1", "admin2");
|
||||
|
@ -914,7 +919,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(14)
|
||||
public void testAddProjectMemberError() throws Exception{
|
||||
public void testAddProjectMemberError() throws Exception {
|
||||
//项目Id为空
|
||||
ProjectAddMemberRequest projectAddMemberRequest = new ProjectAddMemberRequest();
|
||||
projectAddMemberRequest.setProjectId(null);
|
||||
|
@ -1008,7 +1013,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(17)
|
||||
public void testRemoveProjectMember() throws Exception{
|
||||
public void testRemoveProjectMember() throws Exception {
|
||||
String projectId = "projectId1";
|
||||
String userId = "admin1";
|
||||
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
|
||||
|
@ -1023,7 +1028,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
|
||||
@Test
|
||||
@Order(18)
|
||||
public void testRemoveProjectMemberError() throws Exception{
|
||||
public void testRemoveProjectMemberError() throws Exception {
|
||||
String projectId = "projectId1";
|
||||
String userId = "admin1";
|
||||
MvcResult mvcResult = this.responseGet(removeProjectMember + projectId + "/" + userId);
|
||||
|
@ -1044,7 +1049,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Order(19)
|
||||
public void disableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(disableProject + id,status().isOk());
|
||||
this.responseGet(disableProject + id, status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), false);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
|
@ -1063,7 +1068,7 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Order(19)
|
||||
public void enableSuccess() throws Exception {
|
||||
String id = "projectId";
|
||||
this.responseGet(enableProject + id,status().isOk());
|
||||
this.responseGet(enableProject + id, status().isOk());
|
||||
Project currentProject = projectMapper.selectByPrimaryKey(id);
|
||||
Assertions.assertEquals(currentProject.getEnable(), true);
|
||||
checkLog(id, OperationLogType.UPDATE);
|
||||
|
@ -1091,10 +1096,13 @@ public class SystemProjectControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(22)
|
||||
public void testGetOptions() throws Exception {
|
||||
this.requestGetWithOkAndReturn(getPoolOptions);
|
||||
this.requestGetWithOkAndReturn(getPoolOptions + "?organizationId=" + DEFAULT_ORGANIZATION_ID);
|
||||
ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue