fix(测试跟踪): 项目下模块默认节点创建重复的问题

--bug=1013696 --user=宋昌昌 【测试跟踪】github#14110  升级导致模块未规划用例重复问题 https://www.tapd.cn/55049933/s/1179384
This commit is contained in:
songcc 2022-06-11 15:37:48 +08:00 committed by jianxing
parent 63e5025952
commit 61b501513a
6 changed files with 79 additions and 11 deletions

View File

@ -73,8 +73,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
}
public List<ApiModuleDTO> getNodeTreeByProjectId(String projectId, String protocol, String versionId) {
// 判断当前项目下是否有默认模块没有添加默认模块
this.getDefaultNode(projectId, protocol);
List<ApiModuleDTO> apiModules = extApiModuleMapper.getNodeTreeByProjectId(projectId, protocol);
ApiDefinitionRequest request = new ApiDefinitionRequest();
request.setProjectId(projectId);

View File

@ -62,9 +62,6 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
}
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId) {
// 判断当前项目下是否有默认模块没有添加默认模块
this.getDefaultNode(projectId);
List<ApiScenarioModuleDTO> nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId);
ApiScenarioRequest request = new ApiScenarioRequest();
request.setProjectId(projectId);

View File

@ -8,4 +8,5 @@ import lombok.Data;
@Data
public class ModuleNode extends TestCaseNode {
private Integer caseNum;
private String protocol;
}

View File

@ -0,0 +1,41 @@
package io.metersphere.commons.constants;
/**
* 项目模块默认节点
* @author song-cc
*/
public enum ProjectModuleDefaultNodeEnum {
/**
* 测试用例默认节点
*/
TEST_CASE_DEFAULT_NODE("未规划用例", "test_case_node"),
/**
* 接口默认节点
*/
API_MODULE_DEFAULT_NODE("未规划接口", "api_module"),
/**
* 接口场景默认节点
*/
API_SCENARIO_DEFAULT_NODE("未规划场景", "api_scenario_module"),
/**
* 接口场景默认节点
*/
UI_SCENARIO_DEFAULT_NODE("未规划场景", "ui_scenario_module");
private String nodeName;
private String tableName;
ProjectModuleDefaultNodeEnum(String nodeName, String tableName) {
this.nodeName = nodeName;
this.tableName = tableName;
}
public String getNodeName() {
return nodeName;
}
public String getTableName() {
return tableName;
}
}

View File

@ -8,10 +8,7 @@ import io.metersphere.api.service.*;
import io.metersphere.api.tcp.TCPPool;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.base.mapper.ext.ExtProjectVersionMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtUserMapper;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
@ -113,6 +110,10 @@ public class ProjectService {
private ProjectApplicationService projectApplicationService;
@Resource
private ProjectVersionMapper projectVersionMapper;
@Resource
ExtModuleNodeMapper extModuleNodeMapper;
@Resource
ApiModuleMapper apiModuleMapper;
public Project addProject(AddProjectRequest project) {
if (StringUtils.isBlank(project.getName())) {
@ -175,6 +176,8 @@ public class ProjectService {
addProjectVersion(project);
// 初始化项目应用管理
initProjectApplication(project.getId());
// 初始化项目默认节点
initProjectDefaultNode(project.getId());
return project;
}
@ -229,6 +232,36 @@ public class ProjectService {
}
}
private void initProjectDefaultNode(String projectId) {
ModuleNode record = new ModuleNode();
record.setId(UUID.randomUUID().toString());
record.setCreateUser(SessionUtils.getUserId());
record.setPos(1.0);
record.setLevel(1);
record.setCreateTime(System.currentTimeMillis());
record.setUpdateTime(System.currentTimeMillis());
record.setProjectId(projectId);
//每个新项目的默认测试用例节点, 接口场景节点, UI自动化场景, 接口节点{HTTP, DUBBO, SQL, TCP}
record.setName(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getNodeName());
extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.TEST_CASE_DEFAULT_NODE.getTableName(), record);
record.setId(UUID.randomUUID().toString());
record.setName(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getNodeName());
extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.API_SCENARIO_DEFAULT_NODE.getTableName(), record);
record.setId(UUID.randomUUID().toString());
record.setName(ProjectModuleDefaultNodeEnum.UI_SCENARIO_DEFAULT_NODE.getNodeName());
extModuleNodeMapper.insert(ProjectModuleDefaultNodeEnum.UI_SCENARIO_DEFAULT_NODE.getTableName(), record);
ApiModule apiRecord = new ApiModule();
BeanUtils.copyBean(apiRecord, record);
apiRecord.setName(ProjectModuleDefaultNodeEnum.API_MODULE_DEFAULT_NODE.getNodeName());
String[] protocols = {"HTTP", "DUBBO", "SQL", "TCP"};
for (String protocol : protocols) {
apiRecord.setProtocol(protocol);
apiRecord.setId(UUID.randomUUID().toString());
apiModuleMapper.insert(apiRecord);
}
}
public void checkThirdProjectExist(Project project) {
IssuesRequest issuesRequest = new IssuesRequest();
if (StringUtils.isBlank(project.getId())) {

View File

@ -148,8 +148,6 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
}
public List<TestCaseNodeDTO> getNodeTreeByProjectId(String projectId, QueryTestCaseRequest request) {
// 判断当前项目下是否有默认模块没有添加默认模块
this.getDefaultNode(projectId);
List<TestCaseNodeDTO> testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId);
request.setUserId(SessionUtils.getUserId());
request.setProjectId(projectId);