fix(接口测试): 修复场景报告会将全局前后置脚本作为请求进行统计的问题
--bug=1012106 --user=宋天阳 【接口测试】github#12497,场景报告中统计的请求数把环境中针对场景生效的全局前后置脚本算在内了 https://www.tapd.cn/55049933/s/1135092
This commit is contained in:
parent
6515ebc1dc
commit
777afe6bc5
|
@ -5,8 +5,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class ResultParseUtil {
|
public class ResultParseUtil {
|
||||||
|
|
||||||
private static final String PRE_PROCESS_SCRIPT = "PRE_PROCESSOR_ENV_";
|
public static final String PRE_PROCESS_SCRIPT = "PRE_PROCESSOR_ENV_";
|
||||||
private static final String POST_PROCESS_SCRIPT = "POST_PROCESSOR_ENV_";
|
public static final String POST_PROCESS_SCRIPT = "POST_PROCESSOR_ENV_";
|
||||||
|
|
||||||
public static boolean isNotAutoGenerateSampler(RequestResult result) {
|
public static boolean isNotAutoGenerateSampler(RequestResult result) {
|
||||||
if (StringUtils.equals(result.getMethod(), "Request") && StringUtils.startsWithAny(result.getName(), PRE_PROCESS_SCRIPT, POST_PROCESS_SCRIPT)) {
|
if (StringUtils.equals(result.getMethod(), "Request") && StringUtils.startsWithAny(result.getName(), PRE_PROCESS_SCRIPT, POST_PROCESS_SCRIPT)) {
|
||||||
|
|
|
@ -3,10 +3,12 @@ package io.metersphere.api.service;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO;
|
||||||
import io.metersphere.api.dto.ApiScenarioReportDTO;
|
import io.metersphere.api.dto.ApiScenarioReportDTO;
|
||||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||||
import io.metersphere.api.dto.StepTreeDTO;
|
import io.metersphere.api.dto.StepTreeDTO;
|
||||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||||
|
import io.metersphere.api.exec.utils.ResultParseUtil;
|
||||||
import io.metersphere.api.service.vo.ApiDefinitionExecResultVo;
|
import io.metersphere.api.service.vo.ApiDefinitionExecResultVo;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
|
@ -535,13 +537,18 @@ public class ApiScenarioReportStructureService {
|
||||||
ApiScenarioReportDTO reportDTO = new ApiScenarioReportDTO();
|
ApiScenarioReportDTO reportDTO = new ApiScenarioReportDTO();
|
||||||
// 组装报告
|
// 组装报告
|
||||||
if (CollectionUtils.isNotEmpty(reportStructureWithBLOBs) && CollectionUtils.isNotEmpty(reportResults)) {
|
if (CollectionUtils.isNotEmpty(reportStructureWithBLOBs) && CollectionUtils.isNotEmpty(reportResults)) {
|
||||||
|
ApiScenarioReportStructureWithBLOBs scenarioReportStructure = reportStructureWithBLOBs.get(0);
|
||||||
|
List<StepTreeDTO> stepList = JSONArray.parseArray(new String(scenarioReportStructure.getResourceTree(), StandardCharsets.UTF_8), StepTreeDTO.class);
|
||||||
|
//判断是否含有全局前后置脚本,如果有的话需要将脚本内容添加到stepDTO中
|
||||||
|
reportResults = this.filterProcessResult(reportResults);
|
||||||
|
|
||||||
reportDTO.setTotal(reportResults.size());
|
reportDTO.setTotal(reportResults.size());
|
||||||
reportDTO.setError(reportResults.stream().filter(e -> StringUtils.equals(e.getStatus(), "Error")).collect(Collectors.toList()).size());
|
reportDTO.setError(reportResults.stream().filter(e -> StringUtils.equals(e.getStatus(), "Error")).collect(Collectors.toList()).size());
|
||||||
reportDTO.setErrorCode(reportResults.stream().filter(e -> StringUtils.isNotEmpty(e.getErrorCode())).collect(Collectors.toList()).size());
|
reportDTO.setErrorCode(reportResults.stream().filter(e -> StringUtils.isNotEmpty(e.getErrorCode())).collect(Collectors.toList()).size());
|
||||||
reportDTO.setPassAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getPassAssertions).sum());
|
reportDTO.setPassAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getPassAssertions).sum());
|
||||||
reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getTotalAssertions).sum());
|
reportDTO.setTotalAssertions(reportResults.stream().mapToLong(ApiScenarioReportResult::getTotalAssertions).sum());
|
||||||
ApiScenarioReportStructureWithBLOBs scenarioReportStructure = reportStructureWithBLOBs.get(0);
|
|
||||||
List<StepTreeDTO> stepList = JSONArray.parseArray(new String(scenarioReportStructure.getResourceTree(), StandardCharsets.UTF_8), StepTreeDTO.class);
|
|
||||||
// 匹配结果
|
// 匹配结果
|
||||||
Map<String, List<ApiScenarioReportResultWithBLOBs>> maps = reportResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId));
|
Map<String, List<ApiScenarioReportResultWithBLOBs>> maps = reportResults.stream().collect(Collectors.groupingBy(ApiScenarioReportResult::getResourceId));
|
||||||
this.reportFormatting(stepList, maps);
|
this.reportFormatting(stepList, maps);
|
||||||
|
@ -574,6 +581,21 @@ public class ApiScenarioReportStructureService {
|
||||||
return reportDTO;
|
return reportDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ApiScenarioReportResultWithBLOBs> filterProcessResult(List<ApiScenarioReportResultWithBLOBs> reportResults) {
|
||||||
|
List<ApiScenarioReportResultWithBLOBs> withOutProcessList = new ArrayList<>();
|
||||||
|
for (ApiScenarioReportResultWithBLOBs item : reportResults) {
|
||||||
|
if (item.getBaseInfo() != null) {
|
||||||
|
ApiScenarioReportBaseInfoDTO dto = JSONObject.parseObject(item.getBaseInfo(), ApiScenarioReportBaseInfoDTO.class);
|
||||||
|
if (!StringUtils.startsWithAny(dto.getReqName(), ResultParseUtil.PRE_PROCESS_SCRIPT,ResultParseUtil.POST_PROCESS_SCRIPT)) {
|
||||||
|
withOutProcessList.add(item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
withOutProcessList.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return withOutProcessList;
|
||||||
|
}
|
||||||
|
|
||||||
private List<ApiScenarioReportResultWithBLOBs> selectBaseInfoResultByReportId(String reportId) {
|
private List<ApiScenarioReportResultWithBLOBs> selectBaseInfoResultByReportId(String reportId) {
|
||||||
return extApiScenarioReportResultMapper.selectBaseInfoResultByReportId(reportId);
|
return extApiScenarioReportResultMapper.selectBaseInfoResultByReportId(reportId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue