feat(测试计划): 处理β版本计划的测试集数据及其关联用例的数据

This commit is contained in:
song-cc-rock 2024-06-06 17:35:09 +08:00 committed by 刘瑞斌
parent c9dc268569
commit f43f23ae7b
6 changed files with 89 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import io.metersphere.plan.domain.TestPlanCollection;
import io.metersphere.plan.domain.TestPlanCollectionExample; import io.metersphere.plan.domain.TestPlanCollectionExample;
import io.metersphere.plan.dto.ApiCaseModuleDTO; import io.metersphere.plan.dto.ApiCaseModuleDTO;
import io.metersphere.plan.dto.TestPlanCaseRunResultCount; import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam; import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
@ -516,4 +517,17 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
testPlanApiCaseList.add(testPlanApiCase); testPlanApiCaseList.add(testPlanApiCase);
}); });
} }
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.API_CASE.getKey())
&& !StringUtils.equals(collection.getParentId(), "NONE")).toList().get(0);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanApiCaseMapper apiBatchMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class);
TestPlanApiCase record = new TestPlanApiCase();
record.setTestPlanCollectionId(defaultCollection.getId());
TestPlanApiCaseExample apiCaseExample = new TestPlanApiCaseExample();
apiCaseExample.createCriteria().andTestPlanIdEqualTo(planId);
apiBatchMapper.updateByExampleSelective(record, apiCaseExample);
}
} }

View File

@ -4,9 +4,11 @@ import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.domain.TestPlanApiScenario; import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample; import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.TestPlanCaseRunResultCount; import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest; import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper; import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper; import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanCollectionMapper;
import io.metersphere.sdk.constants.CaseType; import io.metersphere.sdk.constants.CaseType;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
@ -34,6 +36,8 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
private TestPlanApiScenarioMapper testPlanApiScenarioMapper; private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource @Resource
private ExtTestPlanApiScenarioMapper extTestPlanApiScenarioMapper; private ExtTestPlanApiScenarioMapper extTestPlanApiScenarioMapper;
@Resource
private TestPlanCollectionMapper testPlanCollectionMapper;
@Override @Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) { public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -102,4 +106,16 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
// TODO: 调用具体的关联场景用例入库方法 入参{计划ID, 测试集ID, 关联的用例ID集合} // TODO: 调用具体的关联场景用例入库方法 入参{计划ID, 测试集ID, 关联的用例ID集合}
} }
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.SCENARIO_CASE.getKey())
&& !StringUtils.equals(collection.getParentId(), "NONE")).toList().get(0);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanApiScenarioMapper scenarioBatchMapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class);
TestPlanApiScenario record = new TestPlanApiScenario();
record.setTestPlanCollectionId(defaultCollection.getId());
TestPlanApiScenarioExample scenarioCaseExample = new TestPlanApiScenarioExample();
scenarioCaseExample.createCriteria().andTestPlanIdEqualTo(planId);
scenarioBatchMapper.updateByExampleSelective(record, scenarioCaseExample);
}
} }

View File

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

View File

@ -21,6 +21,7 @@ import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.domain.*; import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.ResourceLogInsertModule; import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanCaseRunResultCount; import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam; import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.*; import io.metersphere.plan.dto.response.*;
@ -108,11 +109,14 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private TestPlanSendNoticeService testPlanSendNoticeService; private TestPlanSendNoticeService testPlanSendNoticeService;
@Resource @Resource
private BugStatusService bugStatusService; private BugStatusService bugStatusService;
@Resource
private TestPlanCollectionMapper testPlanCollectionMapper;
@Resource @Resource
private ExtUserMapper extUserMapper; private ExtUserMapper extUserMapper;
private static final String CASE_MODULE_COUNT_ALL = "all"; private static final String CASE_MODULE_COUNT_ALL = "all";
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
List<TestPlanFunctionalCase> copyList = new ArrayList<>(); List<TestPlanFunctionalCase> copyList = new ArrayList<>();
extTestPlanFunctionalCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> { extTestPlanFunctionalCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> {
@ -688,4 +692,18 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
}); });
} }
} }
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.FUNCTIONAL_CASE.getKey())
&& !StringUtils.equals(collection.getParentId(), "NONE")).toList().get(0);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanFunctionalCaseMapper functionalBatchMapper = sqlSession.getMapper(TestPlanFunctionalCaseMapper.class);
TestPlanFunctionalCase record = new TestPlanFunctionalCase();
record.setTestPlanCollectionId(defaultCollection.getId());
TestPlanFunctionalCaseExample functionalCaseExample = new TestPlanFunctionalCaseExample();
functionalCaseExample.createCriteria().andTestPlanIdEqualTo(planId);
functionalBatchMapper.updateByExampleSelective(record, functionalCaseExample);
}
} }

View File

@ -2,6 +2,7 @@ package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.domain.TestPlan;
import io.metersphere.plan.dto.ResourceLogInsertModule; import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam; import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest; import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest; import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
@ -62,4 +63,11 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
* @param collectionAssociates 测试集关联用例参数 * @param collectionAssociates 测试集关联用例参数
*/ */
public abstract void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId); public abstract void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, String userId);
/**
* 初始化旧的关联资源到默认测试集
* @param planId
* @param defaultCollections 默认的测试集集合
*/
public abstract void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections);
} }

View File

@ -42,6 +42,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionUtils; import org.mybatis.spring.SqlSessionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -488,10 +489,35 @@ public class TestPlanService extends TestPlanBaseUtilsService {
Boolean isFollow = checkIsFollowCase(id, userId); Boolean isFollow = checkIsFollowCase(id, userId);
response.setFollowFlag(isFollow); response.setFollowFlag(isFollow);
// 是否计划已初始化默认测试集
TestPlanCollectionExample collectionExample = new TestPlanCollectionExample();
collectionExample.createCriteria().andTestPlanIdEqualTo(id);
if (testPlanCollectionMapper.countByExample(collectionExample) == 0) {
List<TestPlanCollectionDTO> collections = initDefaultPlanCollection(id, userId);
TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class);
testPlanService.initResourceDefaultCollection(id, collections);
}
return response; return response;
} }
/**
* 关联的资源初始化默认测试集
* @param planId 计划ID
* @param allCollections 测试集
*/
@Async
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> allCollections) {
// 批处理旧数据
List<TestPlanCollectionDTO> defaultCollections = new ArrayList<>();
allCollections.forEach(allCollection -> {
defaultCollections.addAll(allCollection.getChildren());
});
Map<String, TestPlanResourceService> beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class);
beansOfType.forEach((k, v) -> v.initResourceDefaultCollection(planId, defaultCollections));
}
private Boolean checkIsFollowCase(String testPlanId, String userId) { private Boolean checkIsFollowCase(String testPlanId, String userId) {
TestPlanFollowerExample example = new TestPlanFollowerExample(); TestPlanFollowerExample example = new TestPlanFollowerExample();
example.createCriteria().andTestPlanIdEqualTo(testPlanId).andUserIdEqualTo(userId); example.createCriteria().andTestPlanIdEqualTo(testPlanId).andUserIdEqualTo(userId);
@ -853,9 +879,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
collectionDTOS.add(parentCollectionDTO); collectionDTOS.add(parentCollectionDTO);
} }
testPlanCollectionMapper.batchInsertSelective(collections, TestPlanCollection.Column.id, TestPlanCollection.Column.testPlanId, testPlanCollectionMapper.batchInsert(collections);
TestPlanCollection.Column.parentId, TestPlanCollection.Column.name, TestPlanCollection.Column.type, TestPlanCollection.Column.testResourcePoolId,
TestPlanCollection.Column.createUser, TestPlanCollection.Column.createTime, TestPlanCollection.Column.pos);
return collectionDTOS; return collectionDTOS;
} }