feat(测试计划): 提供规划节点关联用例的抽象方法及统一入参

This commit is contained in:
song-cc-rock 2024-06-06 11:46:24 +08:00 committed by 刘瑞斌
parent 63168b9067
commit d821cfe9f2
9 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package io.metersphere.plan.dto.request;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class BaseCollectionAssociateRequest {
@Schema(description = "测试集ID")
private String collectionId;
@Schema(description = "关联的用例ID集合")
private List<String> ids;
@Schema(description = "测试集类型")
private String type;
}

View File

@ -21,6 +21,7 @@ import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectExample;
import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.CaseType;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.TestPlanResourceConstants;
import io.metersphere.sdk.domain.Environment;
@ -363,4 +364,14 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
extTestPlanApiCaseMapper.batchUpdateExecutor(ids, request.getUserId());
}
}
@Override
public void associateCollection(String planId, List<BaseCollectionAssociateRequest> collectionAssociates) {
List<BaseCollectionAssociateRequest> apiAssociates = collectionAssociates.stream().filter(associate -> StringUtils.equals(associate.getType(), CaseType.API_CASE.getKey())).toList();
if (CollectionUtils.isNotEmpty(apiAssociates)) {
apiAssociates.forEach(apiAssociate -> {
// TODO: 调用具体的关联功能用例入库方法 入参{计划ID, 测试集ID, 关联的用例ID集合}
});
}
}
}

View File

@ -3,11 +3,15 @@ package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
import io.metersphere.sdk.constants.CaseType;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -91,5 +95,14 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
// SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
@Override
public void associateCollection(String planId, List<BaseCollectionAssociateRequest> collectionAssociates) {
List<BaseCollectionAssociateRequest> scenarioAssociates = collectionAssociates.stream().filter(associate -> StringUtils.equals(associate.getType(), CaseType.SCENARIO_CASE.getKey())).toList();
if (CollectionUtils.isNotEmpty(scenarioAssociates)) {
scenarioAssociates.forEach(scenarioAssociate -> {
// TODO: 调用具体的关联场景用例入库方法 入参{计划ID, 测试集ID, 关联的用例ID集合}
});
}
}
}

View File

@ -4,6 +4,7 @@ import io.metersphere.bug.domain.BugRelationCaseExample;
import io.metersphere.bug.mapper.BugRelationCaseMapper;
import io.metersphere.bug.service.BugCommonService;
import io.metersphere.plan.dto.TestPlanBugCaseDTO;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.dto.request.TestPlanBugPageRequest;
import io.metersphere.plan.dto.response.TestPlanBugPageResponse;
import io.metersphere.plan.mapper.ExtTestPlanBugMapper;
@ -115,4 +116,9 @@ public class TestPlanBugService extends TestPlanResourceService {
});
return bugList;
}
@Override
public void associateCollection(String planId, List<BaseCollectionAssociateRequest> collectionAssociates) {
// TODO: 暂不支持缺陷关联测试集
}
}

View File

@ -646,4 +646,14 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public List<UserDTO> getExecUserList(String projectId, String keyword) {
return extUserMapper.getUserByKeyword(projectId, keyword);
}
@Override
public void associateCollection(String planId, List<BaseCollectionAssociateRequest> collectionAssociates) {
List<BaseCollectionAssociateRequest> functionalAssociates = collectionAssociates.stream().filter(associate -> StringUtils.equals(associate.getType(), CaseType.FUNCTIONAL_CASE.getKey())).toList();
if (CollectionUtils.isNotEmpty(functionalAssociates)) {
functionalAssociates.forEach(functionalAssociate -> {
// TODO: 调用具体的关联接口用例入库方法 入参{计划ID, 测试集ID, 关联的用例ID集合}
});
}
}
}

View File

@ -3,6 +3,7 @@ package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.mapper.TestPlanMapper;
@ -53,4 +54,11 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
}
public abstract long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime);
/**
* 关联用例
* @param planId 计划ID
* @param collectionAssociates 测试集关联用例参数
*/
public abstract void associateCollection(String planId, List<BaseCollectionAssociateRequest> collectionAssociates);
}

View File

@ -89,6 +89,12 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private ProjectApplicationService projectApplicationService;
@Resource
private TestPlanCollectionMapper testPlanCollectionMapper;
@Resource
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
@Resource
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
private static final int MAX_TAG_SIZE = 10;
private static final int MAX_CHILDREN_COUNT = 20;
@ -853,4 +859,37 @@ public class TestPlanService extends TestPlanBaseUtilsService {
return collectionDTOS;
}
/**
* 删除测试集资源 (删除测试集及所关联的关联用例)
*/
public void deletePlanCollectionResource(List<String> collectionIds) {
TestPlanCollectionExample example = new TestPlanCollectionExample();
example.createCriteria().andIdIn(collectionIds);
List<TestPlanCollection> collections = testPlanCollectionMapper.selectByExample(example);
List<TestPlanCollection> functionalCollections = collections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.FUNCTIONAL_CASE.getKey())).toList();
List<TestPlanCollection> apiCollections = collections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.API_CASE.getKey())).toList();
List<TestPlanCollection> scenarioCollections = collections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.SCENARIO_CASE.getKey())).toList();
if (CollectionUtils.isNotEmpty(functionalCollections)) {
// 删除{计划集-功能用例}关系
TestPlanFunctionalCaseExample functionalCaseExample = new TestPlanFunctionalCaseExample();
functionalCaseExample.createCriteria().andTestPlanCollectionIdIn(functionalCollections.stream().map(TestPlanCollection::getId).toList());
testPlanFunctionalCaseMapper.deleteByExample(functionalCaseExample);
}
if (CollectionUtils.isNotEmpty(apiCollections)) {
// 删除{计划集-接口用例}关系
TestPlanApiCaseExample apiCaseExample = new TestPlanApiCaseExample();
apiCaseExample.createCriteria().andTestPlanCollectionIdIn(apiCollections.stream().map(TestPlanCollection::getId).toList());
testPlanApiCaseMapper.deleteByExample(apiCaseExample);
}
if (CollectionUtils.isNotEmpty(scenarioCollections)) {
// 删除{计划集-场景用例}关系
TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample();
scenarioExample.createCriteria().andTestPlanCollectionIdIn(scenarioCollections.stream().map(TestPlanCollection::getId).toList());
testPlanApiScenarioMapper.deleteByExample(scenarioExample);
}
// 删除测试集
testPlanCollectionMapper.deleteByExample(example);
}
}

View File

@ -2308,4 +2308,11 @@ public class TestPlanTests extends BaseTest {
void testInitDefaultCollection() {
testPlanService.initDefaultPlanCollection("init_plan_id", "admin");
}
@Test
@Order(309)
void testDeleteCollection() {
testPlanService.deletePlanCollectionResource(List.of("init_collection-delete-4"));
testPlanService.deletePlanCollectionResource(List.of("init_collection-delete-1", "init_collection-delete-2", "init_collection-delete-3"));
}
}

View File

@ -66,3 +66,9 @@ INSERT INTO `test_plan`(`id`, `num`, `project_id`, `group_id`, `module_id`, `nam
VALUES ('init_plan_id', 5000, 'init_project', 'NONE', '1', '测试一下计划', 'PREPARED', 'TEST_PLAN', NULL,
unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, unix_timestamp() * 1000, unix_timestamp() * 1000, '11');
-- 初始化功能集 (删除使用)
INSERT INTO `test_plan_collection`(`id`, `test_plan_id`, `name`, `type`, `environment_id`, `test_resource_pool_id`, `pos`, `create_user`, `create_time`) VALUES
('init_collection-delete-1', 'init_plan_id', '功能用例点', 'FUNCTIONAL', '1', '1', 1, 'admin', unix_timestamp() * 1000),
('init_collection-delete-2', 'init_plan_id', '接口功能点', 'API', '1', '1', 1, 'admin', unix_timestamp() * 1000),
('init_collection-delete-3', 'init_plan_id', '场景功能点', 'SCENARIO', '1', '1', 1, 'admin', unix_timestamp() * 1000),
('init_collection-delete-4', 'init_plan_id', '未知的功能点', 'UNKNOWN', '1', '1', 1, 'admin', unix_timestamp() * 1000);