fix(测试计划执行): 修复串行测试计划时接口用例执行顺序不对的问题

--bug=1007796 --user=宋天阳
【Github#7579】测试计划中拖拽编排场景用例,只能调整显示顺序,但无法作用于执行顺序【+github#8144】
https://www.tapd.cn/55049933/s/1075681
This commit is contained in:
song-tianyang 2021-11-26 18:01:55 +08:00 committed by song-tianyang
parent 6eca1344bd
commit 7bfb92b5f7
2 changed files with 41 additions and 69 deletions

View File

@ -423,6 +423,7 @@ public class TestPlanApiCaseService {
List<String> ids = request.getPlanIds(); List<String> ids = request.getPlanIds();
TestPlanApiCaseExample example = new TestPlanApiCaseExample(); TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria().andIdIn(ids); example.createCriteria().andIdIn(ids);
example.setOrderByClause("`order` DESC");
List<TestPlanApiCase> planApiCases = testPlanApiCaseMapper.selectByExample(example); List<TestPlanApiCase> planApiCases = testPlanApiCaseMapper.selectByExample(example);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiDefinitionExecResultMapper batchMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class); ApiDefinitionExecResultMapper batchMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);

View File

@ -131,28 +131,17 @@ public class TestPlanReportService {
} }
public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) {
Map<String, List<String>> apiTestCaseIdMap = new LinkedHashMap<>();
Map<String, String> planScenarioIdMap = new LinkedHashMap<>(); Map<String, String> planScenarioIdMap = new LinkedHashMap<>();
Map<String, String> apiTestCaseDataMap = new LinkedHashMap<>(); Map<String, String> planTestCaseIdMap = new LinkedHashMap<>();
Map<String, String> performanceIdMap = new LinkedHashMap<>(); Map<String, String> performanceIdMap = new LinkedHashMap<>();
List<TestPlanApiScenario> testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId); List<TestPlanApiScenario> testPlanApiScenarioList = extTestPlanScenarioCaseMapper.selectLegalDataByTestPlanId(planId);
for (TestPlanApiScenario model : testPlanApiScenarioList) { for (TestPlanApiScenario model : testPlanApiScenarioList) {
planScenarioIdMap.put(model.getId(), model.getApiScenarioId()); planScenarioIdMap.put(model.getId(), model.getApiScenarioId());
} }
List<TestPlanApiCase> testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(planId); List<TestPlanApiCase> testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(planId);
for (TestPlanApiCase model : testPlanApiCaseList) { for (TestPlanApiCase model : testPlanApiCaseList) {
if (apiTestCaseIdMap.containsKey(model.getApiCaseId())) { planTestCaseIdMap.put(model.getId(), model.getApiCaseId());
apiTestCaseIdMap.get(model.getApiCaseId()).add(model.getId());
} else {
List<String> list = new ArrayList<>();
list.add(model.getId());
apiTestCaseIdMap.put(model.getApiCaseId(), list);
} }
}
LoadCaseRequest loadCaseRequest = new LoadCaseRequest(); LoadCaseRequest loadCaseRequest = new LoadCaseRequest();
loadCaseRequest.setTestPlanId(planId); loadCaseRequest.setTestPlanId(planId);
loadCaseRequest.setProjectId(projectID); loadCaseRequest.setProjectId(projectID);
@ -160,29 +149,12 @@ public class TestPlanReportService {
for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) { for (TestPlanLoadCaseDTO dto : testPlanLoadCaseDTOList) {
performanceIdMap.put(dto.getId(), dto.getLoadCaseId()); performanceIdMap.put(dto.getId(), dto.getLoadCaseId());
} }
String planReportId = UUID.randomUUID().toString(); String planReportId = UUID.randomUUID().toString();
Map<String, String> apiCaseInfoMap = new HashMap<>(); Map<String, String> apiCaseInfoMap = new HashMap<>();
if (!apiTestCaseIdMap.isEmpty()) { for (String id : planTestCaseIdMap.keySet()) {
//筛选出未被删除/放入回收站的案例 apiCaseInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
ApiTestCaseExample apiTestCaseExample = new ApiTestCaseExample();
apiTestCaseExample.createCriteria().andIdIn(new ArrayList<>(apiTestCaseIdMap.keySet()));
List<ApiTestCase> apiCaseList = apiTestCaseMapper.selectByExample(apiTestCaseExample);
if (!apiCaseList.isEmpty()) {
Map<String, ApiTestCase> apiCaseDataMap = apiCaseList.stream().collect(Collectors.toMap(ApiTestCase::getId, k -> k));
for (String id : apiCaseDataMap.keySet()) {
List<String> testPlanCaseIdList = apiTestCaseIdMap.get(id);
if (CollectionUtils.isNotEmpty(testPlanCaseIdList)) {
for (String testPlanCaseId : testPlanCaseIdList) {
apiCaseInfoMap.put(testPlanCaseId, TestPlanApiExecuteStatus.PREPARE.name());
apiTestCaseDataMap.put(testPlanCaseId, id);
} }
}
}
}
}
Map<String, String> scenarioInfoMap = new HashMap<>(); Map<String, String> scenarioInfoMap = new HashMap<>();
for (String id : planScenarioIdMap.keySet()) { for (String id : planScenarioIdMap.keySet()) {
scenarioInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name()); scenarioInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
@ -192,14 +164,13 @@ public class TestPlanReportService {
performanceInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name()); performanceInfoMap.put(id, TestPlanApiExecuteStatus.PREPARE.name());
} }
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode, TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId, planId, userId, triggerMode,
apiTestCaseDataMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0, planTestCaseIdMap.size() > 0, planScenarioIdMap.size() > 0, performanceIdMap.size() > 0,
apiCaseInfoMap, scenarioInfoMap, performanceInfoMap); apiCaseInfoMap, scenarioInfoMap, performanceInfoMap);
TestPlanReport report = this.genTestPlanReport(saveRequest); TestPlanReport report = this.genTestPlanReport(saveRequest);
TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO(); TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO();
returnDTO.setTestPlanReport(report); returnDTO.setTestPlanReport(report);
returnDTO.setPlanScenarioIdMap(planScenarioIdMap); returnDTO.setPlanScenarioIdMap(planScenarioIdMap);
returnDTO.setApiTestCaseDataMap(apiTestCaseDataMap); returnDTO.setApiTestCaseDataMap(planTestCaseIdMap);
returnDTO.setPerformanceIdMap(performanceIdMap); returnDTO.setPerformanceIdMap(performanceIdMap);
return returnDTO; return returnDTO;
} }