mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 20:19:16 +08:00
feat(接口测试): 报告增加版本
This commit is contained in:
parent
3097c19d68
commit
aed24dd095
@ -151,7 +151,7 @@ public class ApiScenarioExecuteService {
|
|||||||
JSON.toJSONString(CollectionUtils.isNotEmpty(scenarioIds) && scenarioIds.size() > 50 ? scenarioIds.subList(0, 50) : scenarioIds),
|
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(),
|
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));
|
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.setName(request.getConfig().getReportName());
|
||||||
report.setId(serialReportId);
|
report.setId(serialReportId);
|
||||||
request.getConfig().setAmassReport(serialReportId);
|
request.getConfig().setAmassReport(serialReportId);
|
||||||
@ -259,7 +259,7 @@ public class ApiScenarioExecuteService {
|
|||||||
}
|
}
|
||||||
report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(),
|
report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(),
|
||||||
request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId());
|
request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId());
|
||||||
|
report.setVersionId(scenario.getVersionId());
|
||||||
scenarioIds.add(scenario.getId());
|
scenarioIds.add(scenario.getId());
|
||||||
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
||||||
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
||||||
@ -310,6 +310,7 @@ public class ApiScenarioExecuteService {
|
|||||||
APIScenarioReportResult report = apiScenarioReportService.init(reportId, item.getId(), item.getName(), request.getTriggerMode(),
|
APIScenarioReportResult report = apiScenarioReportService.init(reportId, item.getId(), item.getName(), request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(), item.getId());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(), item.getId());
|
||||||
scenarioIds.add(item.getId());
|
scenarioIds.add(item.getId());
|
||||||
|
report.setVersionId(item.getVersionId());
|
||||||
scenarioNames.append(item.getName()).append(",");
|
scenarioNames.append(item.getName()).append(",");
|
||||||
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) {
|
||||||
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
RunModeDataDTO runModeDataDTO = new RunModeDataDTO();
|
||||||
@ -377,14 +378,15 @@ public class ApiScenarioExecuteService {
|
|||||||
if (request.isSaved()) {
|
if (request.isSaved()) {
|
||||||
APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
|
APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
|
||||||
SessionUtils.getUserId(), request.getConfig(), request.getId());
|
SessionUtils.getUserId(), request.getConfig(), request.getId());
|
||||||
apiScenarioReportMapper.insert(report);
|
|
||||||
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId());
|
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId());
|
||||||
if (scenarioWithBLOBs != null) {
|
if (scenarioWithBLOBs != null) {
|
||||||
|
report.setVersionId(scenarioWithBLOBs.getVersionId());
|
||||||
apiScenarioReportStructureService.save(scenarioWithBLOBs, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
|
apiScenarioReportStructureService.save(scenarioWithBLOBs, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null);
|
||||||
} else {
|
} else {
|
||||||
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {
|
if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) {
|
||||||
ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs();
|
ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs();
|
||||||
scenario.setId(request.getScenarioId());
|
scenario.setId(request.getScenarioId());
|
||||||
|
report.setVersionId(scenarioWithBLOBs.getVersionId());
|
||||||
MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0);
|
MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0);
|
||||||
if (testElement != null) {
|
if (testElement != null) {
|
||||||
scenario.setName(testElement.getName());
|
scenario.setName(testElement.getName());
|
||||||
@ -393,6 +395,7 @@ public class ApiScenarioExecuteService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
apiScenarioReportMapper.insert(report);
|
||||||
}
|
}
|
||||||
uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles);
|
uploadBodyFiles(request.getBodyFileRequestIds(), bodyFiles);
|
||||||
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
|
FileUtils.createBodyFiles(request.getScenarioFileIds(), scenarioFiles);
|
||||||
|
@ -2,7 +2,6 @@ package io.metersphere.api.service;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.ErrorReportLibraryParseDTO;
|
|
||||||
import io.metersphere.api.dto.RequestResultExpandDTO;
|
import io.metersphere.api.dto.RequestResultExpandDTO;
|
||||||
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
||||||
import io.metersphere.base.domain.*;
|
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.TestCaseReviewApiCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||||
import io.metersphere.commons.constants.*;
|
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.RequestResult;
|
||||||
import io.metersphere.dto.ResultDTO;
|
import io.metersphere.dto.ResultDTO;
|
||||||
import io.metersphere.notice.sender.NoticeModel;
|
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())) {
|
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);
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = null;
|
ApiTestCaseWithBLOBs caseWithBLOBs = null;
|
||||||
@ -162,12 +166,13 @@ public class ApiDefinitionExecResultService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (caseWithBLOBs != null) {
|
if (caseWithBLOBs != null) {
|
||||||
return caseWithBLOBs.getName();
|
name = caseWithBLOBs.getName();
|
||||||
|
version = caseWithBLOBs.getVersionId();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(testId);
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(testId);
|
||||||
if (apiDefinition != null) {
|
if (apiDefinition != null) {
|
||||||
return apiDefinition.getName();
|
name = apiDefinition.getName();
|
||||||
} else {
|
} else {
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testId);
|
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(testId);
|
||||||
if (caseWithBLOBs != null) {
|
if (caseWithBLOBs != null) {
|
||||||
@ -180,11 +185,13 @@ public class ApiDefinitionExecResultService {
|
|||||||
if (LoggerUtil.getLogger().isDebugEnabled()) {
|
if (LoggerUtil.getLogger().isDebugEnabled()) {
|
||||||
LoggerUtil.debug("更新用例【 " + caseWithBLOBs.getId() + " 】");
|
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_")) {
|
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);
|
ApiDefinitionExecResult reportResult = this.save(item, dto.getReportId(), dto.getConsole(), countExpectProcessResultCount, dto.getRunMode(), dto.getTestId(), isFirst);
|
||||||
String status = item.isSuccess() ? "success" : "error";
|
String status = item.isSuccess() ? "success" : "error";
|
||||||
if(reportResult != null){
|
if (reportResult != null) {
|
||||||
status = reportResult.getStatus();
|
status = reportResult.getStatus();
|
||||||
}
|
}
|
||||||
//对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读
|
//对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读
|
||||||
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item);
|
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item);
|
||||||
if(MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())){
|
if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) {
|
||||||
status = expandDTO.getStatus();
|
status = expandDTO.getStatus();
|
||||||
}
|
}
|
||||||
if (StringUtils.equalsAny(dto.getRunMode(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.JENKINS_API_PLAN.name())) {
|
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);
|
RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item);
|
||||||
if(MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())){
|
if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) {
|
||||||
status = expandDTO.getStatus();
|
status = expandDTO.getStatus();
|
||||||
saveResult.setContent(JSON.toJSONString(expandDTO));
|
saveResult.setContent(JSON.toJSONString(expandDTO));
|
||||||
}else {
|
} else {
|
||||||
saveResult.setContent(JSON.toJSONString(item));
|
saveResult.setContent(JSON.toJSONString(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
saveResult.setName(item.getName());
|
saveResult.setName(item.getName());
|
||||||
saveResult.setType(type);
|
saveResult.setType(type);
|
||||||
saveResult.setCreateTime(item.getStartTime());
|
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.setStatus(status);
|
||||||
saveResult.setResourceId(item.getName());
|
saveResult.setResourceId(item.getName());
|
||||||
saveResult.setStartTime(item.getStartTime());
|
saveResult.setStartTime(item.getStartTime());
|
||||||
|
@ -969,69 +969,6 @@ public class TestPlanService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateHashTreeByScenarioList(MsTestPlan testPlan, Map<String, String> planScenarioIdMap, SchedulePlanScenarioExecuteRequest request) throws Exception {
|
|
||||||
String returnId = "";
|
|
||||||
boolean isFirst = true;
|
|
||||||
List<ApiScenarioWithBLOBs> 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<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
|
|
||||||
new TypeReference<LinkedList<MsTestElement>>() {
|
|
||||||
});
|
|
||||||
scenario.setHashTree(elements);
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotEmpty(element.getString("variables"))) {
|
|
||||||
LinkedList<ScenarioVariable> variables = mapper.readValue(element.getString("variables"),
|
|
||||||
new TypeReference<LinkedList<ScenarioVariable>>() {
|
|
||||||
});
|
|
||||||
scenario.setVariables(variables);
|
|
||||||
}
|
|
||||||
group.setEnableCookieShare(scenario.isEnableCookieShare());
|
|
||||||
LinkedList<MsTestElement> 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)
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode) {
|
TestPlanScheduleReportInfoDTO genTestPlanReport(String projectID, String planId, String userId, String triggerMode) {
|
||||||
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, planId, userId, triggerMode);
|
TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, planId, userId, triggerMode);
|
||||||
|
Loading…
Reference in New Issue
Block a user