diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 6a54ce17a0..db5f6475fd 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -151,7 +151,7 @@ public class ApiScenarioExecuteService { JSON.toJSONString(CollectionUtils.isNotEmpty(scenarioIds) && scenarioIds.size() > 50 ? scenarioIds.subList(0, 50) : scenarioIds), scenarioNames.length() >= 3000 ? scenarioNames.substring(0, 2000) : scenarioNames.deleteCharAt(scenarioNames.length() - 1).toString(), ReportTriggerMode.MANUAL.name(), ExecuteType.Saved.name(), request.getProjectId(), request.getReportUserID(), request.getConfig(), JSON.toJSONString(scenarioIds)); - + report.setVersionId(apiScenarios.get(0).getVersionId()); report.setName(request.getConfig().getReportName()); report.setId(serialReportId); request.getConfig().setAmassReport(serialReportId); @@ -259,7 +259,7 @@ public class ApiScenarioExecuteService { } report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(), request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId()); - + report.setVersionId(scenario.getVersionId()); scenarioIds.add(scenario.getId()); if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) { RunModeDataDTO runModeDataDTO = new RunModeDataDTO(); @@ -310,6 +310,7 @@ public class ApiScenarioExecuteService { APIScenarioReportResult report = apiScenarioReportService.init(reportId, item.getId(), item.getName(), request.getTriggerMode(), request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(), item.getId()); scenarioIds.add(item.getId()); + report.setVersionId(item.getVersionId()); scenarioNames.append(item.getName()).append(","); if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) { RunModeDataDTO runModeDataDTO = new RunModeDataDTO(); @@ -377,14 +378,15 @@ public class ApiScenarioExecuteService { if (request.isSaved()) { APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), SessionUtils.getUserId(), request.getConfig(), request.getId()); - apiScenarioReportMapper.insert(report); ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId()); if (scenarioWithBLOBs != null) { + report.setVersionId(scenarioWithBLOBs.getVersionId()); apiScenarioReportStructureService.save(scenarioWithBLOBs, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null); } else { if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) { ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs(); scenario.setId(request.getScenarioId()); + report.setVersionId(scenarioWithBLOBs.getVersionId()); MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0); if (testElement != null) { scenario.setName(testElement.getName()); @@ -393,6 +395,7 @@ public class ApiScenarioExecuteService { } } } + apiScenarioReportMapper.insert(report); } uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles); FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index ab31b6252d..b21c61aab2 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -2,7 +2,6 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.ErrorReportLibraryParseDTO; import io.metersphere.api.dto.RequestResultExpandDTO; import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult; import io.metersphere.base.domain.*; @@ -12,7 +11,10 @@ import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.TestCaseReviewApiCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.commons.constants.*; -import io.metersphere.commons.utils.*; +import io.metersphere.commons.utils.DateUtils; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.ResponseUtil; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.RequestResult; import io.metersphere.dto.ResultDTO; import io.metersphere.notice.sender.NoticeModel; @@ -135,7 +137,9 @@ public class ApiDefinitionExecResultService { } } - private String editStatus(String type, String status, Long time, String reportId, String testId) { + private void editStatus(ApiDefinitionExecResult saveResult, String type, String status, Long time, String reportId, String testId) { + String name = testId; + String version = ""; if (StringUtils.equalsAnyIgnoreCase(type, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) { TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId); ApiTestCaseWithBLOBs caseWithBLOBs = null; @@ -162,12 +166,13 @@ public class ApiDefinitionExecResultService { } } if (caseWithBLOBs != null) { - return caseWithBLOBs.getName(); + name = caseWithBLOBs.getName(); + version = caseWithBLOBs.getVersionId(); } } else { ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(testId); if (apiDefinition != null) { - return apiDefinition.getName(); + name = apiDefinition.getName(); } else { ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testId); if (caseWithBLOBs != null) { @@ -180,11 +185,13 @@ public class ApiDefinitionExecResultService { if (LoggerUtil.getLogger().isDebugEnabled()) { LoggerUtil.debug("更新用例【 " + caseWithBLOBs.getId() + " 】"); } - return caseWithBLOBs.getName(); + name = caseWithBLOBs.getName(); + version = caseWithBLOBs.getVersionId(); } } } - return testId; + saveResult.setVersionId(version); + saveResult.setName(name); } /** @@ -206,12 +213,12 @@ public class ApiDefinitionExecResultService { if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) { ApiDefinitionExecResult reportResult = this.save(item, dto.getReportId(), dto.getConsole(), countExpectProcessResultCount, dto.getRunMode(), dto.getTestId(), isFirst); String status = item.isSuccess() ? "success" : "error"; - if(reportResult != null){ + if (reportResult != null) { status = reportResult.getStatus(); } //对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读 RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item); - if(MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())){ + if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) { status = expandDTO.getStatus(); } if (StringUtils.equalsAny(dto.getRunMode(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) { @@ -343,17 +350,17 @@ public class ApiDefinitionExecResultService { //对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读 RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item); - if(MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())){ + if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) { status = expandDTO.getStatus(); saveResult.setContent(JSON.toJSONString(expandDTO)); - }else { + } else { saveResult.setContent(JSON.toJSONString(item)); } saveResult.setName(item.getName()); saveResult.setType(type); saveResult.setCreateTime(item.getStartTime()); - saveResult.setName(editStatus(type, status, saveResult.getCreateTime(), saveResult.getId(), testId)); + editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); saveResult.setStatus(status); saveResult.setResourceId(item.getName()); saveResult.setStartTime(item.getStartTime()); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 6a4885aed9..f5963001c7 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -969,69 +969,6 @@ public class TestPlanService { return list; } - private String generateHashTreeByScenarioList(MsTestPlan testPlan, Map planScenarioIdMap, SchedulePlanScenarioExecuteRequest request) throws Exception { - String returnId = ""; - boolean isFirst = true; - List apiScenarios = extApiScenarioMapper.selectIds(new ArrayList<>(planScenarioIdMap.keySet())); - for (ApiScenarioWithBLOBs item : apiScenarios) { - String apiScenarioID = item.getId(); - String planScenarioID = planScenarioIdMap.get(apiScenarioID); - if (StringUtils.isEmpty(planScenarioID)) { - continue; - } - if (item.getStepTotal() == 0) { - // 只有一个场景且没有测试步骤,则提示 - if (apiScenarios.size() == 1) { - MSException.throwException((item.getName() + "," + Translator.get("automation_exec_info"))); - } - LogUtil.warn(item.getName() + "," + Translator.get("automation_exec_info")); - continue; - } - MsThreadGroup group = new MsThreadGroup(); - group.setLabel(item.getName()); - group.setName(UUID.randomUUID().toString()); - // 批量执行的结果直接存储为报告 - if (isFirst) { - group.setName(request.getId()); - isFirst = false; - } - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JSONObject element = JSON.parseObject(item.getScenarioDefinition()); - ElementUtil.dataFormatting(element); - - MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class); - group.setOnSampleError(scenario.getOnSampleError()); - // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 - if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { - LinkedList elements = mapper.readValue(element.getString("hashTree"), - new TypeReference>() { - }); - scenario.setHashTree(elements); - } - if (StringUtils.isNotEmpty(element.getString("variables"))) { - LinkedList variables = mapper.readValue(element.getString("variables"), - new TypeReference>() { - }); - scenario.setVariables(variables); - } - group.setEnableCookieShare(scenario.isEnableCookieShare()); - LinkedList scenarios = new LinkedList<>(); - scenarios.add(scenario); - // 创建场景报告 - //不同的运行模式,第二个参数入参不同 - APIScenarioReportResult report = apiScenarioReportService.init(group.getName(), - planScenarioID + ":" + request.getTestPlanReportId(), - item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(), null); - apiScenarioReportMapper.insert(report); - group.setHashTree(scenarios); - testPlan.getHashTree().add(group); - returnId = request.getId(); - } - return returnId; - } - @Transactional(propagation = Propagation.NOT_SUPPORTED) TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode) { TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, planId, userId, triggerMode);