fix(测试计划): 测试计划组批量执行增加过滤条件,组内的测试计划不再进入执行队列中

This commit is contained in:
Jianguo-Genius 2024-06-19 19:13:10 +08:00 committed by Craftsman
parent f2318eb253
commit e12eb97757
10 changed files with 37 additions and 8 deletions

View File

@ -13,4 +13,6 @@ public interface ExtTestPlanCollectionMapper {
List<TestPlanCollectionEnvDTO> selectSecondCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId);
TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId);
String selectDefaultCollectionId(@Param("testPlanId")String newTestPlanId,@Param("type") String key);
}

View File

@ -52,4 +52,7 @@
and tpc.parent_id = #{parentId}
and tpc.test_plan_id = #{testPlanId}
</select>
<select id="selectDefaultCollectionId" resultType="java.lang.String">
SELECT id FROM test_plan_collection WHERE test_plan_id = #{testPlanId} AND parent_id!='NONE' and type = #{type}
</select>
</mapper>

View File

@ -148,8 +148,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
}
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
List<TestPlanApiCase> copyList = new ArrayList<>();
String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId, CaseType.SCENARIO_CASE.getKey());
extTestPlanApiCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> {
TestPlanApiCase newCase = new TestPlanApiCase();
BeanUtils.copyBean(newCase, originalCase);
@ -158,6 +159,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
newCase.setCreateTime(operatorTime);
newCase.setCreateUser(operator);
newCase.setLastExecTime(0L);
newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()));
newCase.setLastExecResult(ExecStatus.PENDING.name());
newCase.setLastExecReportId(null);
copyList.add(newCase);

View File

@ -139,8 +139,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
}
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
List<TestPlanApiScenario> copyList = new ArrayList<>();
String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId,CaseType.SCENARIO_CASE.getKey());
extTestPlanApiScenarioMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> {
TestPlanApiScenario newCase = new TestPlanApiScenario();
BeanUtils.copyBean(newCase, originalCase);
@ -149,6 +150,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
newCase.setCreateTime(operatorTime);
newCase.setCreateUser(operator);
newCase.setLastExecTime(0L);
newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()));
newCase.setLastExecResult(ExecStatus.PENDING.name());
newCase.setLastExecReportId(null);
copyList.add(newCase);

View File

@ -198,6 +198,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService {
TestPlanCollectionExample parentCollectionExample = new TestPlanCollectionExample();
parentCollectionExample.createCriteria().andTestPlanIdEqualTo(originalTestPlan.getId()).andParentIdEqualTo(TestPlanConstants.DEFAULT_PARENT_ID);
List<TestPlanCollection> testPlanCollectionList = testPlanCollectionMapper.selectByExample(parentCollectionExample);
Map<String, String> oldCollectionIdToNewCollectionId = new HashMap<>();
if (CollectionUtils.isEmpty(testPlanCollectionList)) {
//自动生成测试规划
Objects.requireNonNull(CommonBeanFactory.getBean(TestPlanService.class)).initDefaultPlanCollection(testPlan.getId(), operator);
@ -225,6 +226,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService {
childCollection.setCreateUser(operator);
childCollection.setCreateTime(operatorTime);
newTestPlanCollectionList.add(childCollection);
oldCollectionIdToNewCollectionId.put(child.getId(), childCollection.getId());
}
}
testPlanCollectionMapper.batchInsert(newTestPlanCollectionList);
@ -233,7 +235,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService {
//测试用例信息
Map<String, TestPlanResourceService> beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class);
beansOfType.forEach((k, v) -> {
v.copyResource(originalTestPlan.getId(), testPlan.getId(), operator, operatorTime);
v.copyResource(originalTestPlan.getId(), testPlan.getId(), oldCollectionIdToNewCollectionId, operator, operatorTime);
});
return testPlan;
}

View File

@ -58,7 +58,7 @@ public class TestPlanBugService extends TestPlanResourceService {
}
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
return 0;
}

View File

@ -371,7 +371,7 @@ public class TestPlanExecuteService {
String queueId = executionQueue.getPrepareReportId() + "_" + parentCollection.getId();
String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION;
String runMode = executionQueue.getRunMode();
String runMode = parentCollection.getExecuteMethod();
for (TestPlanCollection collection : childrenList) {
childrenQueue.add(
new TestPlanExecutionQueue(

View File

@ -124,10 +124,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private OperationLogService operationLogService;
@Resource
private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper;
@Resource
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
List<TestPlanFunctionalCase> copyList = new ArrayList<>();
String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId,CaseType.SCENARIO_CASE.getKey());
extTestPlanFunctionalCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> {
TestPlanFunctionalCase newCase = new TestPlanFunctionalCase();
BeanUtils.copyBean(newCase, originalCase);
@ -136,6 +139,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
newCase.setCreateTime(operatorTime);
newCase.setCreateUser(operator);
newCase.setLastExecTime(0L);
newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()));
newCase.setLastExecResult(ExecStatus.PENDING.name());
copyList.add(newCase);
});

View File

@ -55,7 +55,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
return response;
}
public abstract long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime);
public abstract long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime);
/**
* 关联用例

View File

@ -938,8 +938,22 @@ public class TestPlanService extends TestPlanBaseUtilsService {
return hisList;
}
//只查找未归档的测试计划组以及游离态测试计划
public List<String> selectRightfulIds(List<String> executeIds) {
return extTestPlanMapper.selectNotArchivedIds(executeIds);
TestPlanExample testPlanExample = new TestPlanExample();
testPlanExample.createCriteria().andIdIn(executeIds).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED);
Map<String, TestPlan> testPlanIdMap = testPlanMapper.selectByExample(testPlanExample)
.stream().collect(Collectors.toMap(TestPlan::getId, v -> v));
List<String> returnIds = new ArrayList<>();
for (String executeId : executeIds) {
TestPlan testPlan = testPlanIdMap.get(executeId);
if (testPlan != null &&
(StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)
|| StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.DEFAULT_PARENT_ID))) {
returnIds.add(executeId);
}
}
return returnIds;
}
public List<TestPlan> selectNotArchivedChildren(String testPlanGroupId) {