refactor(系统设置): 优化测试用例的初始化项目的sql

This commit is contained in:
wxg0103 2023-11-03 13:54:59 +08:00 committed by Craftsman
parent 5fa267720f
commit af23997c9f
2 changed files with 13 additions and 13 deletions

View File

@ -10,9 +10,6 @@ import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.InternalUserRole;
import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.constants.UserRoleType;
import io.metersphere.system.log.dto.LogDTO;
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.JSON; import io.metersphere.sdk.util.JSON;
@ -20,12 +17,15 @@ import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.Translator; 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.sdk.OptionDTO;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.invoker.ProjectServiceInvoker; import io.metersphere.system.invoker.ProjectServiceInvoker;
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.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.*; import io.metersphere.system.mapper.*;
import io.metersphere.system.dto.request.ProjectAddMemberBatchRequest;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -349,7 +349,7 @@ public class CommonProjectService {
project.setModuleSetting(null); project.setModuleSetting(null);
projectDTO.setModuleIds(new ArrayList<>()); projectDTO.setModuleIds(new ArrayList<>());
} }
project.setOrganizationId(null);
projectMapper.updateByPrimaryKeySelective(project); projectMapper.updateByPrimaryKeySelective(project);
return projectDTO; return projectDTO;
} }

View File

@ -590,7 +590,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
// 校验日志 // 校验日志
checkLog(projectId, OperationLogType.ADD); checkLog(projectId, OperationLogType.ADD);
//用户id为空 //用户id为空
project = this.generatorUpdate("organizationId", "projectId2", "organization-TestNameUserIdIsNull", "Edit name", true, new ArrayList<>()); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "organization-TestNameUserIdIsNull", "Edit name", true, new ArrayList<>());
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());
@ -605,7 +605,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
Assertions.assertEquals(projectExtend.getModuleSetting(), CollectionUtils.isEmpty(project.getModuleIds()) ? null : JSON.toJSONString(project.getModuleIds())); Assertions.assertEquals(projectExtend.getModuleSetting(), CollectionUtils.isEmpty(project.getModuleIds()) ? null : JSON.toJSONString(project.getModuleIds()));
// 修改模块设置 // 修改模块设置
project = this.generatorUpdate("organizationId", "projectId2", "org-Module", "Edit name", true, new ArrayList<>()); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId2", "org-Module", "Edit name", true, new ArrayList<>());
moduleIds = new ArrayList<>(); moduleIds = new ArrayList<>();
moduleIds.add("apiTest"); moduleIds.add("apiTest");
moduleIds.add("uiTest"); moduleIds.add("uiTest");
@ -624,7 +624,7 @@ public class OrganizationProjectControllerTests extends BaseTest {
Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds)); Assertions.assertEquals(projectExtend.getModuleSetting(), JSON.toJSONString(moduleIds));
//设置资源池 //设置资源池
project = this.generatorUpdate("organizationId", "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);
@ -649,22 +649,22 @@ public class OrganizationProjectControllerTests extends BaseTest {
@Order(8) @Order(8)
public void testUpdateProjectError() throws Exception { public void testUpdateProjectError() throws Exception {
//项目名称存在 500 //项目名称存在 500
UpdateProjectRequest project = this.generatorUpdate("organizationId", "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("organizationId", 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("organizationId", "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("organizationId", "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("organizationId", "projectId","org-Module-pool", null, true, List.of("admin")); project = this.generatorUpdate(DEFAULT_ORGANIZATION_ID, "projectId", "org-Module-pool", null, 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);