refactor: 测试计划报告方法优化 (#9175)
Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com> Co-authored-by: jianxing <41557596+AgAngle@users.noreply.github.com>
This commit is contained in:
parent
44e4711644
commit
908dd5b734
|
@ -18,6 +18,7 @@ import io.metersphere.dto.RequestResult;
|
|||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.notice.sender.NoticeModel;
|
||||
import io.metersphere.notice.service.NoticeSendService;
|
||||
import io.metersphere.track.dto.PlanReportCaseDTO;
|
||||
import io.metersphere.track.dto.TestPlanDTO;
|
||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.testcase.TrackCount;
|
||||
|
@ -374,4 +375,10 @@ public class ApiDefinitionExecResultService {
|
|||
public ApiDefinitionExecResult getInfo(String id) {
|
||||
return apiDefinitionExecResultMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public List<PlanReportCaseDTO> selectForPlanReport(List<String> apiReportIds) {
|
||||
if (CollectionUtils.isEmpty(apiReportIds))
|
||||
return new ArrayList<>();
|
||||
return extApiDefinitionExecResultMapper.selectForPlanReport(apiReportIds);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.metersphere.log.vo.api.ModuleReference;
|
|||
import io.metersphere.notice.sender.NoticeModel;
|
||||
import io.metersphere.notice.service.NoticeSendService;
|
||||
import io.metersphere.service.UserService;
|
||||
import io.metersphere.track.dto.PlanReportCaseDTO;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
@ -693,6 +694,10 @@ public class ApiScenarioReportService {
|
|||
return status;
|
||||
}
|
||||
|
||||
public List<PlanReportCaseDTO> selectForPlanReport(List<String> reportIds) {
|
||||
return extApiScenarioReportMapper.selectForPlanReport(reportIds);
|
||||
}
|
||||
|
||||
public void cleanUpReport(long time, String projectId) {
|
||||
ApiScenarioReportExample example = new ApiScenarioReportExample();
|
||||
example.createCriteria().andCreateTimeLessThan(time).andProjectIdEqualTo(projectId);
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.base.mapper.ext;
|
|||
|
||||
import io.metersphere.api.dto.datacount.ExecutedCaseInfoResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||
import io.metersphere.track.dto.PlanReportCaseDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -30,4 +31,5 @@ public interface ExtApiDefinitionExecResultMapper {
|
|||
|
||||
List<ApiDefinitionExecResult> selectApiResultByProjectId(String projectId);
|
||||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(@Param("ids") List<String> apiReportIds);
|
||||
}
|
|
@ -116,5 +116,12 @@
|
|||
and (t3.project_id = #{projectId} OR t4.project_id = #{projectId} OR t6.project_id = #{projectId})
|
||||
and t.`STATUS` in ('running', 'waiting')
|
||||
</select>
|
||||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
|
||||
select status from api_definition_exec_result
|
||||
where id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.dto.automation.APIScenarioReportResult;
|
|||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||
import io.metersphere.base.domain.ApiScenarioReport;
|
||||
import io.metersphere.dto.ApiReportCountDTO;
|
||||
import io.metersphere.track.dto.PlanReportCaseDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -34,4 +35,6 @@ public interface ExtApiScenarioReportMapper {
|
|||
List<ApiScenarioReport> selectStatusByIds(@Param("ids") Collection<String> values);
|
||||
|
||||
List<ApiScenarioReport> selectReportByProjectId(String projectId);
|
||||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(@Param("ids") List<String> reportIds);
|
||||
}
|
|
@ -308,4 +308,11 @@
|
|||
#{value}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
|
||||
select status from api_scenario_report
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
|
@ -5,6 +5,7 @@ import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
|||
import io.metersphere.dto.DashboardTestDTO;
|
||||
import io.metersphere.dto.ReportDTO;
|
||||
import io.metersphere.performance.controller.request.ReportRequest;
|
||||
import io.metersphere.track.dto.PlanReportCaseDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -22,4 +23,6 @@ public interface ExtLoadTestReportMapper {
|
|||
void updateJmxContentIfAbsent(LoadTestReportWithBLOBs record);
|
||||
|
||||
List<LoadTestReport> selectReportByProjectId(String projectId);
|
||||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(@Param("ids") List<String> reportIds);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,13 @@
|
|||
and t.status = 'running'
|
||||
|
||||
</select>
|
||||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
|
||||
select status from load_test_report
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<update id="updateJmxContentIfAbsent">
|
||||
update load_test_report
|
||||
|
|
|
@ -11,8 +11,7 @@ import java.util.Map;
|
|||
|
||||
public class TestPlanUtils {
|
||||
|
||||
|
||||
public static void getStatusResultMap(Map<String, TestCaseReportStatusResultDTO> reportStatusResultMap, String result) {
|
||||
public static void buildStatusResultMap(Map<String, TestCaseReportStatusResultDTO> reportStatusResultMap, String result) {
|
||||
if (StringUtils.isBlank(result)) {
|
||||
result = TestPlanTestCaseStatus.Prepare.name();
|
||||
}
|
||||
|
@ -35,6 +34,11 @@ public class TestPlanUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将map转成前端需要的数组数据
|
||||
* @param resultMap
|
||||
* @param statusResult
|
||||
*/
|
||||
public static void addToReportCommonStatusResultList(Map<String, TestCaseReportStatusResultDTO> resultMap,
|
||||
List<TestCaseReportStatusResultDTO> statusResult) {
|
||||
addToReportStatusResultList(resultMap, statusResult, TestPlanTestCaseStatus.Pass.name());
|
||||
|
@ -48,7 +52,10 @@ public class TestPlanUtils {
|
|||
addToReportStatusResultList(resultMap, statusResult, TestPlanTestCaseStatus.Prepare.name());
|
||||
}
|
||||
|
||||
public static void calculatePlanReport(List<PlanReportCaseDTO> planReportCaseDTOS,
|
||||
/**
|
||||
* 将当前用例状态对应的统计数据存储在map中
|
||||
*/
|
||||
public static void buildStatusResultMap(List<PlanReportCaseDTO> planReportCaseDTOS,
|
||||
Map<String, TestCaseReportStatusResultDTO> statusResultMap,
|
||||
TestPlanSimpleReportDTO report, String successStatus) {
|
||||
planReportCaseDTOS.forEach(item -> {
|
||||
|
@ -56,12 +63,14 @@ public class TestPlanUtils {
|
|||
String status = item.getStatus();
|
||||
if (StringUtils.isNotBlank(status)
|
||||
&& !StringUtils.equalsAny(status, TestPlanTestCaseStatus.Underway.name(), TestPlanTestCaseStatus.Prepare.name())) {
|
||||
// 计算执行过的数量
|
||||
report.setExecuteCount(report.getExecuteCount() + 1);
|
||||
if (StringUtils.equals(successStatus, status)) {
|
||||
// 计算执行成功的数量
|
||||
report.setPassCount(report.getPassCount() + 1);
|
||||
}
|
||||
}
|
||||
TestPlanUtils.getStatusResultMap(statusResultMap, status);
|
||||
buildStatusResultMap(statusResultMap, status);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -560,7 +560,7 @@ public class IssuesService {
|
|||
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();
|
||||
|
||||
planReportIssueDTOS.forEach(item -> {
|
||||
String status = null;
|
||||
String status;
|
||||
// 本地缺陷
|
||||
if (StringUtils.equalsIgnoreCase(item.getPlatform(), IssuesManagePlatform.Local.name())
|
||||
|| StringUtils.isBlank(item.getPlatform())) {
|
||||
|
@ -571,7 +571,7 @@ public class IssuesService {
|
|||
if (StringUtils.isBlank(status)) {
|
||||
status = IssuesStatus.NEW.toString();
|
||||
}
|
||||
TestPlanUtils.getStatusResultMap(statusResultMap, status);
|
||||
TestPlanUtils.buildStatusResultMap(statusResultMap, status);
|
||||
});
|
||||
Set<String> status = statusResultMap.keySet();
|
||||
status.forEach(item -> {
|
||||
|
|
|
@ -355,12 +355,20 @@ public class TestPlanApiCaseService {
|
|||
|
||||
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId);
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
public void calculatePlanReport(List<String> apiReportIds, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = apiDefinitionExecResultService.selectForPlanReport(apiReportIds);
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
|
||||
TestPlanApiResultReportDTO apiResult = report.getApiResult();
|
||||
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
|
||||
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();
|
||||
|
||||
TestPlanUtils.calculatePlanReport(planReportCaseDTOS, statusResultMap, report, "success");
|
||||
TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "success");
|
||||
|
||||
TestPlanUtils.addToReportCommonStatusResultList(statusResultMap, statusResult);
|
||||
|
||||
|
|
|
@ -9,7 +9,10 @@ import io.metersphere.base.mapper.LoadTestMapper;
|
|||
import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||
import io.metersphere.base.mapper.TestPlanLoadCaseMapper;
|
||||
import io.metersphere.base.mapper.TestPlanMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtTestPlanLoadCaseMapper;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.constants.TestPlanLoadCaseStatus;
|
||||
import io.metersphere.commons.constants.TestPlanStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
|
@ -59,6 +62,8 @@ public class TestPlanLoadCaseService {
|
|||
@Resource
|
||||
private LoadTestReportMapper loadTestReportMapper;
|
||||
@Resource
|
||||
private ExtLoadTestReportMapper extLoadTestReportMapper;
|
||||
@Resource
|
||||
private LoadTestMapper loadTestMapper;
|
||||
@Resource
|
||||
@Lazy
|
||||
|
@ -184,7 +189,7 @@ public class TestPlanLoadCaseService {
|
|||
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
|
||||
example.createCriteria().andLoadReportIdEqualTo(report.getId());
|
||||
List<TestPlanLoadCase> cases = testPlanLoadCaseMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(cases) || !cases.get(0).getStatus().equals("success")) {
|
||||
if (CollectionUtils.isEmpty(cases) || !cases.get(0).getStatus().equals(TestPlanLoadCaseStatus.success.name())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +357,7 @@ public class TestPlanLoadCaseService {
|
|||
example.createCriteria()
|
||||
.andTestPlanIdEqualTo(planId)
|
||||
.andLoadCaseIdIn(performanceIds)
|
||||
.andStatusEqualTo("error");
|
||||
.andStatusEqualTo(TestPlanLoadCaseStatus.error.name());
|
||||
return testPlanLoadCaseMapper.countByExample(example) > 0 ? true : false;
|
||||
}
|
||||
|
||||
|
@ -367,12 +372,31 @@ public class TestPlanLoadCaseService {
|
|||
|
||||
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanLoadCaseMapper.selectForPlanReport(planId);
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = extLoadTestReportMapper.selectForPlanReport(reportIds);
|
||||
// 性能测试的报告状态跟用例的执行状态不一样
|
||||
planReportCaseDTOS.forEach(item -> {
|
||||
if (item.getStatus().equals(PerformanceTestStatus.Completed.name())) {
|
||||
item.setStatus(TestPlanLoadCaseStatus.success.name());
|
||||
} else if (item.getStatus().equals(PerformanceTestStatus.Error.name())) {
|
||||
item.setStatus(TestPlanLoadCaseStatus.error.name());
|
||||
} else {
|
||||
item.setStatus(TestPlanLoadCaseStatus.run.name());
|
||||
}
|
||||
});
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
|
||||
TestPlanLoadResultReportDTO loadResult = new TestPlanLoadResultReportDTO();
|
||||
report.setLoadResult(loadResult);
|
||||
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
|
||||
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();
|
||||
|
||||
TestPlanUtils.calculatePlanReport(planReportCaseDTOS, statusResultMap, report, "success");
|
||||
TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, TestPlanLoadCaseStatus.success.name());
|
||||
TestPlanUtils.addToReportCommonStatusResultList(statusResultMap, statusResult);
|
||||
|
||||
loadResult.setCaseData(statusResult);
|
||||
|
@ -389,7 +413,7 @@ public class TestPlanLoadCaseService {
|
|||
}
|
||||
|
||||
public List<TestPlanLoadCaseDTO> getFailureCases(String planId) {
|
||||
List<TestPlanLoadCaseDTO> failureCases = extTestPlanLoadCaseMapper.getCases(planId, "error");
|
||||
List<TestPlanLoadCaseDTO> failureCases = extTestPlanLoadCaseMapper.getCases(planId, TestPlanLoadCaseStatus.error.name());
|
||||
return buildCases(failureCases);
|
||||
}
|
||||
|
||||
|
|
|
@ -430,11 +430,20 @@ public class TestPlanScenarioCaseService {
|
|||
|
||||
public void calculatePlanReport(String planId, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId);
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
public void calculatePlanReport(List<String> reportIds, TestPlanSimpleReportDTO report) {
|
||||
List<PlanReportCaseDTO> planReportCaseDTOS = apiScenarioReportService.selectForPlanReport(reportIds);
|
||||
calculatePlanReport(report, planReportCaseDTOS);
|
||||
}
|
||||
|
||||
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
|
||||
TestPlanApiResultReportDTO apiResult = report.getApiResult();
|
||||
|
||||
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
|
||||
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();
|
||||
TestPlanUtils.calculatePlanReport(planReportCaseDTOS, statusResultMap, report, "Success");
|
||||
TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "Success");
|
||||
TestPlanUtils.addToReportCommonStatusResultList(statusResultMap, statusResult);
|
||||
TestPlanScenarioStepCountDTO stepCount = new TestPlanScenarioStepCountDTO();
|
||||
for (PlanReportCaseDTO item : planReportCaseDTOS) {
|
||||
|
|
|
@ -384,7 +384,7 @@ public class TestPlanTestCaseService {
|
|||
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
|
||||
Map<String, TestCaseReportStatusResultDTO> statusResultMap = new HashMap<>();
|
||||
|
||||
TestPlanUtils.calculatePlanReport(planReportCaseDTOS, statusResultMap, report, TestPlanTestCaseStatus.Pass.name());
|
||||
TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, TestPlanTestCaseStatus.Pass.name());
|
||||
TestPlanUtils.addToReportCommonStatusResultList(statusResultMap, statusResult);
|
||||
|
||||
TestPlanUtils.addToReportStatusResultList(statusResultMap, statusResult, TestPlanTestCaseStatus.Blocking.name());
|
||||
|
|
Loading…
Reference in New Issue