fix(测试跟踪): 修复测试计划取消关联用例或场景时之前的测试报告也同步删除的问题

--bug=1011648 --user=宋天阳 【测试跟踪】测试计划 中
取消
关联用例/场景,之前生成的报告不应同步删除
https://www.tapd.cn/55049933/s/1128306
This commit is contained in:
song-tianyang 2022-03-31 17:14:47 +08:00 committed by CountryBuilder
parent 214e32465f
commit fb58085870
5 changed files with 244 additions and 54 deletions

View File

@ -1,9 +1,12 @@
package io.metersphere.dto;
import io.metersphere.api.dto.automation.TestPlanFailureApiDTO;
import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.Map;
@Getter
@ -13,4 +16,6 @@ public class TestPlanExecuteReportDTO {
private Map<String,String> testPlanApiCaseIdAndReportIdMap;
private Map<String,String> testPlanScenarioIdAndReportIdMap;
private Map<String,String> testPlanLoadCaseIdAndReportIdMap;
private List<TestPlanFailureApiDTO> apiCaseInfoDTOList;
private List<TestPlanFailureScenarioDTO> scenarioInfoDTOList;
}

View File

@ -29,6 +29,7 @@ import io.metersphere.track.dto.TestCaseReportStatusResultDTO;
import io.metersphere.track.dto.TestPlanApiResultReportDTO;
import io.metersphere.track.dto.TestPlanSimpleReportDTO;
import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -128,7 +129,6 @@ public class TestPlanApiCaseService {
}
public int delete(String id) {
apiDefinitionExecResultService.deleteByResourceId(id);
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria()
.andIdEqualTo(id);
@ -138,7 +138,6 @@ public class TestPlanApiCaseService {
public int deleteByPlanId(String planId) {
List<String> ids = extTestPlanApiCaseMapper.getIdsByPlanId(planId);
apiDefinitionExecResultService.deleteByResourceIds(ids);
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria()
.andTestPlanIdEqualTo(planId);
@ -157,7 +156,6 @@ public class TestPlanApiCaseService {
if (CollectionUtils.isEmpty(deleteIds)) {
return;
}
apiDefinitionExecResultService.deleteByResourceIds(deleteIds);
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
example.createCriteria()
.andIdIn(deleteIds)
@ -366,6 +364,19 @@ public class TestPlanApiCaseService {
calculatePlanReport(report, planReportCaseDTOS);
}
public void calculatePlanReportByApiCaseList(List<TestPlanFailureApiDTO> apiCaseList, TestPlanSimpleReportDTO report) {
List<PlanReportCaseDTO> planReportCaseDTOS = new ArrayList<>();
for (TestPlanFailureApiDTO dto : apiCaseList) {
PlanReportCaseDTO reportCaseDTO = new PlanReportCaseDTO();
reportCaseDTO.setId(dto.getId());
reportCaseDTO.setCaseId(dto.getCaseId());
reportCaseDTO.setReportId(dto.getReportId());
reportCaseDTO.setStatus(dto.getExecResult());
planReportCaseDTOS.add(reportCaseDTO);
}
calculatePlanReport(report, planReportCaseDTOS);
}
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanApiResultReportDTO apiResult = report.getApiResult();
List<TestCaseReportStatusResultDTO> statusResult = new ArrayList<>();
@ -422,9 +433,11 @@ public class TestPlanApiCaseService {
String defaultStatus = "error";
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureListByIds(testPlanApiCaseReportMap.keySet(), null);
Map<String, String> reportResult = apiDefinitionExecResultService.selectReportResultByReportIds(testPlanApiCaseReportMap.values());
Map<String, String> savedReportMap = new HashMap<>(testPlanApiCaseReportMap);
for (TestPlanFailureApiDTO dto : apiTestCases) {
String testPlanApiCaseId = dto.getId();
String reportId = testPlanApiCaseReportMap.get(testPlanApiCaseId);
String reportId = savedReportMap.get(testPlanApiCaseId);
savedReportMap.remove(testPlanApiCaseId);
dto.setReportId(reportId);
if (StringUtils.isEmpty(reportId)) {
dto.setExecResult(defaultStatus);
@ -436,6 +449,27 @@ public class TestPlanApiCaseService {
dto.setExecResult(status);
}
}
if (!MapUtils.isEmpty(savedReportMap)) {
for (Map.Entry<String, String> entry : savedReportMap.entrySet()) {
String testPlanApiCaseId = entry.getKey();
String reportId = entry.getValue();
TestPlanFailureApiDTO dto = new TestPlanFailureApiDTO();
dto.setId(testPlanApiCaseId);
dto.setReportId(reportId);
dto.setName("DELETED");
dto.setNum(0);
if (StringUtils.isEmpty(reportId)) {
dto.setExecResult(defaultStatus);
} else {
String status = reportResult.get(reportId);
if (status == null) {
status = defaultStatus;
}
dto.setExecResult(status);
}
apiTestCases.add(dto);
}
}
return buildCases(apiTestCases);
}

View File

@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.minlog.Log;
import io.metersphere.api.dto.automation.TestPlanFailureApiDTO;
import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO;
import io.metersphere.api.service.ApiDefinitionExecResultService;
import io.metersphere.api.service.ApiScenarioReportService;
import io.metersphere.api.service.ShareInfoService;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
@ -93,6 +95,11 @@ public class TestPlanReportService {
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Lazy
@Resource
private ApiDefinitionExecResultService apiDefinitionExecResultService;
@Resource
private ApiScenarioReportService apiScenarioReportService;
public List<TestPlanReportDTO> list(QueryTestPlanReportRequest request) {
List<TestPlanReportDTO> list = new ArrayList<>();
@ -439,15 +446,81 @@ public class TestPlanReportService {
testPlanReport.setUpdateTime(endTime);
}
//更新content表对结束日期
TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId);
List<TestPlanReportContentWithBLOBs> contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample);
TestPlanReportContentWithBLOBs content = null;
if(CollectionUtils.isNotEmpty(contents)){
content = contents.get(0);
}
if(content!= null){
//更新接口用例场景用例的最终执行状态
if(StringUtils.isNotEmpty(content.getPlanApiCaseReportStruct())){
try {
List<TestPlanFailureApiDTO> apiTestCases = JSONArray.parseArray(content.getPlanApiCaseReportStruct(),TestPlanFailureApiDTO.class);
List<String> reportIdList = new ArrayList<>();
apiTestCases.forEach( item -> {
if(StringUtils.isNotEmpty(item.getReportId())){
reportIdList.add(item.getReportId());
}
});
Map<String, String> reportResult = apiDefinitionExecResultService.selectReportResultByReportIds(reportIdList);
String defaultStatus = "error";
for (TestPlanFailureApiDTO dto : apiTestCases) {
String reportId = dto.getReportId();
if (StringUtils.isEmpty(reportId)) {
dto.setExecResult(defaultStatus);
} else {
String execStatus = reportResult.get(reportId);
if (execStatus == null) {
execStatus = defaultStatus;
}
dto.setExecResult(execStatus);
}
}
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiTestCases));
}catch (Exception e){
LogUtil.error("update test plan api error! "+e.getMessage());
}
}
if(StringUtils.isNotEmpty(content.getPlanScenarioReportStruct())){
try {
List<TestPlanFailureScenarioDTO> scenarioCases = JSONArray.parseArray(content.getPlanScenarioReportStruct(),TestPlanFailureScenarioDTO.class);
List<String> reportIdList = new ArrayList<>();
scenarioCases.forEach( item -> {
if(StringUtils.isNotEmpty(item.getReportId())){
reportIdList.add(item.getReportId());
}
});
String defaultStatus = "Fail";
Map<String, String> reportStatus = apiScenarioReportService.getReportStatusByReportIds(reportIdList);
TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs();
content.setStartTime(testPlanReport.getStartTime());
content.setEndTime(endTime);
testPlanReportContentMapper.updateByExampleSelective(content, contentExample);
for (TestPlanFailureScenarioDTO dto : scenarioCases) {
String reportId = dto.getReportId();
if (StringUtils.isNotEmpty(reportId)) {
String execStatus = reportStatus.get(reportId);
if (execStatus == null) {
execStatus = defaultStatus;
} else {
if (StringUtils.equalsIgnoreCase(status, "Error")) {
status = "Fail";
}
}
dto.setLastResult(execStatus);
dto.setStatus(execStatus);
}
}
content.setPlanScenarioReportStruct(JSONObject.toJSONString(scenarioCases));
}catch (Exception e){
LogUtil.error("update test plan api error! "+e.getMessage());
}
}
//更新content表对结束日期
content.setStartTime(testPlanReport.getStartTime());
content.setEndTime(endTime);
testPlanReportContentMapper.updateByExampleSelective(content, contentExample);
}
//更新测试计划并发送通知
testPlanReport.setIsApiCaseExecuting(false);
@ -857,7 +930,6 @@ public class TestPlanReportService {
}
public TestPlanSimpleReportDTO getReport(String reportId) {
Log.info("----> SELECT REPORT: "+ reportId);
TestPlanReportContentExample example = new TestPlanReportContentExample();
example.createCriteria().andTestPlanReportIdEqualTo(reportId);
List<TestPlanReportContentWithBLOBs> testPlanReportContents = testPlanReportContentMapper.selectByExampleWithBLOBs(example);
@ -873,7 +945,6 @@ public class TestPlanReportService {
testPlanReportContent = this.dynamicallyGenerateReports(testPlanReportContent);
Log.info("----> GenerateReports OVER: "+ JSONObject.toJSONString(testPlanReportContent));
}
Log.info("----> parse return object: "+ JSONObject.toJSONString(testPlanReportContent));
TestPlanSimpleReportDTO testPlanReportDTO = new TestPlanSimpleReportDTO();
BeanUtils.copyBean(testPlanReportDTO, testPlanReportContent);
if (StringUtils.isNotBlank(testPlanReportContent.getFunctionResult())) {
@ -927,7 +998,6 @@ public class TestPlanReportService {
testPlanReportDTO.setId(reportId);
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId());
testPlanReportDTO.setName(testPlanReport.getName());
Log.info("----> SELECT REPORT OVER ");
return testPlanReportDTO;
}
@ -948,10 +1018,19 @@ public class TestPlanReportService {
content.setTestPlanReportId(testPlanReportID);
if (MapUtils.isNotEmpty(apiCaseReportMap)) {
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiCaseReportMap));
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureListByIds(apiCaseReportMap.keySet(),null);
for (TestPlanFailureApiDTO dto : apiTestCases) {
dto.setReportId(apiCaseReportMap.get(dto.getId()));
}
content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiTestCases));
}
if (MapUtils.isNotEmpty(scenarioReportIdMap)) {
content.setPlanScenarioReportStruct(JSONObject.toJSONString(scenarioReportIdMap));
List<TestPlanFailureScenarioDTO> apiTestCases =
extTestPlanScenarioCaseMapper.getFailureListByIds(scenarioReportIdMap.keySet(), null);
for (TestPlanFailureScenarioDTO dto : apiTestCases) {
dto.setReportId(scenarioReportIdMap.get(dto.getId()));
}
content.setPlanScenarioReportStruct(JSONObject.toJSONString(apiTestCases));
}
if (MapUtils.isNotEmpty(loadCaseReportIdMap)) {
content.setPlanLoadCaseReportStruct(JSONObject.toJSONString(loadCaseReportIdMap));
@ -963,18 +1042,37 @@ public class TestPlanReportService {
Map<String, String> testPlanApiCaseIdAndReportIdMap = new HashMap<>();
Map<String, String> testPlanScenarioIdAndReportIdMap = new HashMap<>();
Map<String, String> testPlanLoadCaseIdAndReportIdMap = new HashMap<>();
List<TestPlanFailureApiDTO> apiCaseInfoDTOList = null;
List<TestPlanFailureScenarioDTO> scenarioInfoDTOList = null;
if (testPlanReportContentWithBLOBs != null) {
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct())) {
try {
testPlanApiCaseIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct(), Map.class);
} catch (Exception ignore) {
apiCaseInfoDTOList = JSONArray.parseArray(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct(), TestPlanFailureApiDTO.class);
}catch (Exception ignore){}
if(apiCaseInfoDTOList == null){
try {
testPlanApiCaseIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanApiCaseReportStruct(), Map.class);
} catch (Exception ignore) {
}
}else {
for (TestPlanFailureApiDTO item : apiCaseInfoDTOList) {
testPlanApiCaseIdAndReportIdMap.put(item.getId(),item.getReportId());
}
}
}
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct())) {
try {
testPlanScenarioIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct(), Map.class);
} catch (Exception ignore) {
scenarioInfoDTOList = JSONArray.parseArray(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct(), TestPlanFailureScenarioDTO.class);
}catch (Exception ignore){}
if(scenarioInfoDTOList == null){
try {
testPlanScenarioIdAndReportIdMap = JSONObject.parseObject(testPlanReportContentWithBLOBs.getPlanScenarioReportStruct(), Map.class);
} catch (Exception ignore) {
}
}else {
for (TestPlanFailureScenarioDTO item : scenarioInfoDTOList) {
testPlanScenarioIdAndReportIdMap.put(item.getId(),item.getReportId());
}
}
}
if (StringUtils.isNotEmpty(testPlanReportContentWithBLOBs.getPlanLoadCaseReportStruct())) {
@ -984,7 +1082,7 @@ public class TestPlanReportService {
}
}
}
TestPlanExecuteReportDTO returnDTO = new TestPlanExecuteReportDTO(testPlanApiCaseIdAndReportIdMap, testPlanScenarioIdAndReportIdMap, testPlanLoadCaseIdAndReportIdMap);
TestPlanExecuteReportDTO returnDTO = new TestPlanExecuteReportDTO(testPlanApiCaseIdAndReportIdMap, testPlanScenarioIdAndReportIdMap, testPlanLoadCaseIdAndReportIdMap,apiCaseInfoDTOList,scenarioInfoDTOList);
return returnDTO;
}

View File

@ -33,6 +33,7 @@ import io.metersphere.service.ProjectService;
import io.metersphere.track.dto.*;
import io.metersphere.track.request.testcase.TestPlanScenarioCaseBatchRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -97,11 +98,15 @@ public class TestPlanScenarioCaseService {
apiTestCases.forEach(item -> {
Project project = projectMap.get(item.getProjectId());
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.SCENARIO_CUSTOM_NUM.name());
boolean custom = config.getCaseCustomNum();
if (project != null && custom) {
item.setCustomNum(item.getCustomNum());
} else {
if(project != null){
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.SCENARIO_CUSTOM_NUM.name());
boolean custom = config.getCaseCustomNum();
if(custom){
item.setCustomNum(item.getCustomNum());
}else {
item.setCustomNum(item.getNum().toString());
}
}else {
item.setCustomNum(item.getNum().toString());
}
});
@ -137,11 +142,6 @@ public class TestPlanScenarioCaseService {
}
public int delete(String id) {
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(id);
String reportId = testPlanApiScenario.getReportId();
if (!StringUtils.isEmpty(reportId)) {
apiScenarioReportService.delete(reportId);
}
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria()
.andIdEqualTo(id);
@ -164,9 +164,6 @@ public class TestPlanScenarioCaseService {
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria()
.andIdIn(ids);
List<String> reportIds = testPlanApiScenarioMapper.selectByExample(example).stream()
.map(TestPlanApiScenario::getReportId).collect(Collectors.toList());
apiScenarioReportService.deleteByIds(reportIds);
testPlanApiScenarioMapper.deleteByExample(example);
}
@ -447,6 +444,19 @@ public class TestPlanScenarioCaseService {
calculatePlanReport(report, planReportCaseDTOS);
}
public void calculatePlanReportByScenarioList(List<TestPlanFailureScenarioDTO> scenarioList,TestPlanSimpleReportDTO report){
List<PlanReportCaseDTO> planReportCaseDTOS = new ArrayList<>();
for (TestPlanFailureScenarioDTO scenario : scenarioList) {
PlanReportCaseDTO dto = new PlanReportCaseDTO();
dto.setCaseId(scenario.getCaseId());
dto.setId(scenario.getId());
dto.setStatus(scenario.getStatus());
dto.setReportId(scenario.getReportId());
planReportCaseDTOS.add(dto);
}
calculatePlanReport(report, planReportCaseDTOS);
}
private void calculatePlanReport(TestPlanSimpleReportDTO report, List<PlanReportCaseDTO> planReportCaseDTOS) {
TestPlanApiResultReportDTO apiResult = report.getApiResult();
@ -472,7 +482,7 @@ public class TestPlanScenarioCaseService {
private int getUnderwayStepsCounts(List<String> underwayIds) {
if (CollectionUtils.isNotEmpty(underwayIds)) {
List<Integer> underwayStepsCounts = extTestPlanScenarioCaseMapper.getUnderwaySteps(underwayIds);
return underwayStepsCounts.stream().filter(Objects::nonNull).reduce(0,Integer::sum);
return underwayStepsCounts.stream().filter(Objects::nonNull).reduce(0, Integer::sum);
}
return 0;
}
@ -518,10 +528,13 @@ public class TestPlanScenarioCaseService {
String defaultStatus = "Fail";
Map<String, String> reportStatus = apiScenarioReportService.getReportStatusByReportIds(idMap.values());
Map<String, String> savedReportMap = new HashMap<>(idMap);
for (TestPlanFailureScenarioDTO dto : apiTestCases) {
String reportId = idMap.get(dto.getId());
String reportId = savedReportMap.get(dto.getId());
savedReportMap.remove(dto.getId());
dto.setReportId(reportId);
if (reportId != null) {
if (StringUtils.isNotEmpty(reportId)) {
String status = reportStatus.get(reportId);
if (status == null) {
status = defaultStatus;
@ -534,6 +547,32 @@ public class TestPlanScenarioCaseService {
dto.setStatus(status);
}
}
if (!MapUtils.isEmpty(savedReportMap)) {
for (Map.Entry<String, String> entry : savedReportMap.entrySet()) {
String testPlanApiCaseId = entry.getKey();
String reportId = entry.getValue();
TestPlanFailureScenarioDTO dto = new TestPlanFailureScenarioDTO();
dto.setId(testPlanApiCaseId);
dto.setReportId(reportId);
dto.setName("DELETED");
dto.setNum(0);
if (StringUtils.isNotEmpty(reportId)) {
String status = reportStatus.get(reportId);
if (status == null) {
status = defaultStatus;
} else {
if (StringUtils.equalsIgnoreCase(status, "Error")) {
status = "Fail";
}
}
dto.setLastResult(status);
dto.setStatus(status);
}
apiTestCases.add(dto);
}
}
return buildCases(apiTestCases);
}

View File

@ -429,7 +429,7 @@ public class TestPlanService {
request.setProjectId(request.getProjectId());
}
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
if(testPlans.size()==0){
if (testPlans.size() == 0) {
return new ArrayList<>();
}
Set<String> ids = testPlans.stream().map(TestPlan::getId).collect(Collectors.toSet());
@ -443,7 +443,7 @@ public class TestPlanService {
Map<String, ParamsDTO> stringParamsDTOMap = testPlanReportMapper.reportCount(ids);
testPlans.forEach(item -> {
item.setExecutionTimes(stringParamsDTOMap.get(item.getId()) == null ? 0 : Integer.parseInt(stringParamsDTOMap.get(item.getId()).getValue() == null ? "0" : stringParamsDTOMap.get(item.getId()).getValue()));
item.setExecutionTimes(stringParamsDTOMap.get(item.getId()) == null ? 0 : Integer.parseInt(stringParamsDTOMap.get(item.getId()).getValue() == null ? "0" : stringParamsDTOMap.get(item.getId()).getValue()));
if (StringUtils.isNotBlank(item.getScheduleId())) {
if (item.isScheduleOpen()) {
item.setScheduleStatus(ScheduleStatus.OPEN.name());
@ -456,10 +456,10 @@ public class TestPlanService {
} else {
item.setScheduleStatus(ScheduleStatus.NOTSET.name());
}
item.setTestPlanTestCaseCount(planTestCaseCountMap.get(item.getId()) == null ? 0 : Integer.parseInt(planTestCaseCountMap.get(item.getId()).getValue() == null ? "0" : planTestCaseCountMap.get(item.getId()).getValue()));
item.setTestPlanApiCaseCount(planApiCaseMap.get(item.getId()) == null ? 0 : Integer.parseInt(planApiCaseMap.get(item.getId()).getValue() == null ? "0" : planApiCaseMap.get(item.getId()).getValue()));
item.setTestPlanApiScenarioCount(planApiScenarioMap.get(item.getId()) == null? 0 : Integer.parseInt(planApiScenarioMap.get(item.getId()).getValue() == null ? "0" : planApiScenarioMap.get(item.getId()).getValue()));
item.setTestPlanLoadCaseCount(planLoadCaseMap.get(item.getId()) == null ? 0 : Integer.parseInt(planLoadCaseMap.get(item.getId()).getValue() == null ? "0" : planLoadCaseMap.get(item.getId()).getValue()));
item.setTestPlanTestCaseCount(planTestCaseCountMap.get(item.getId()) == null ? 0 : Integer.parseInt(planTestCaseCountMap.get(item.getId()).getValue() == null ? "0" : planTestCaseCountMap.get(item.getId()).getValue()));
item.setTestPlanApiCaseCount(planApiCaseMap.get(item.getId()) == null ? 0 : Integer.parseInt(planApiCaseMap.get(item.getId()).getValue() == null ? "0" : planApiCaseMap.get(item.getId()).getValue()));
item.setTestPlanApiScenarioCount(planApiScenarioMap.get(item.getId()) == null ? 0 : Integer.parseInt(planApiScenarioMap.get(item.getId()).getValue() == null ? "0" : planApiScenarioMap.get(item.getId()).getValue()));
item.setTestPlanLoadCaseCount(planLoadCaseMap.get(item.getId()) == null ? 0 : Integer.parseInt(planLoadCaseMap.get(item.getId()).getValue() == null ? "0" : planLoadCaseMap.get(item.getId()).getValue()));
});
calcTestPlanRate(testPlans);
return testPlans;
@ -1581,23 +1581,31 @@ public class TestPlanService {
}
public void buildApiReport(TestPlanSimpleReportDTO report, JSONObject config, TestPlanExecuteReportDTO testPlanExecuteReportDTO) {
if (MapUtils.isEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap()) && MapUtils.isEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) {
if (MapUtils.isEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())
&& MapUtils.isEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())
&& CollectionUtils.isEmpty(testPlanExecuteReportDTO.getApiCaseInfoDTOList())
&& CollectionUtils.isEmpty(testPlanExecuteReportDTO.getScenarioInfoDTOList())) {
return;
}
if (checkReportConfig(config, "api")) {
List<TestPlanFailureApiDTO> apiAllCases = null;
List<TestPlanFailureScenarioDTO> scenarioAllCases = null;
if (checkReportConfig(config, "api", "all")) {
if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) {
// 接口
// 接口
if(CollectionUtils.isNotEmpty(testPlanExecuteReportDTO.getApiCaseInfoDTOList())){
apiAllCases = testPlanExecuteReportDTO.getApiCaseInfoDTOList();
}else if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) {
apiAllCases = testPlanApiCaseService.getByApiExecReportIds(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap());
report.setApiAllCases(apiAllCases);
}
if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) {
//场景
report.setApiAllCases(apiAllCases);
//场景
if(CollectionUtils.isNotEmpty(testPlanExecuteReportDTO.getScenarioInfoDTOList())){
scenarioAllCases = testPlanExecuteReportDTO.getScenarioInfoDTOList();
}else if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) {
scenarioAllCases = testPlanScenarioCaseService.getAllCases(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap());
report.setScenarioAllCases(scenarioAllCases);
}
report.setScenarioAllCases(scenarioAllCases);
}
//筛选符合配置需要的执行结果的用例和场景
@ -1617,7 +1625,7 @@ public class TestPlanService {
failureScenarios.add(scenario);
} else if (StringUtils.equalsIgnoreCase(scenario.getLastResult(), ExecuteResult.errorReportResult.name())) {
errorReportScenarios.add(scenario);
} else if (StringUtils.equalsAnyIgnoreCase(scenario.getLastResult(), "stop","unexecute")) {
} else if (StringUtils.equalsAnyIgnoreCase(scenario.getLastResult(), "stop", "unexecute")) {
unExecuteScenarios.add(scenario);
}
}
@ -1643,7 +1651,7 @@ public class TestPlanService {
apiFailureCases.add(apiDTO);
} else if (StringUtils.equalsIgnoreCase(apiDTO.getExecResult(), ExecuteResult.errorReportResult.name())) {
apiErrorReportCases.add(apiDTO);
} else if (StringUtils.equalsAnyIgnoreCase(apiDTO.getExecResult(), "stop","unexecute")) {
} else if (StringUtils.equalsAnyIgnoreCase(apiDTO.getExecResult(), "stop", "unexecute")) {
apiUnExecuteCases.add(apiDTO);
}
}
@ -1817,12 +1825,18 @@ public class TestPlanService {
testPlanScenarioCaseService.calculatePlanReport(planId, report);
testPlanLoadCaseService.calculatePlanReport(planId, report);
} else {
if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) {
if(CollectionUtils.isNotEmpty(testPlanExecuteReportDTO.getApiCaseInfoDTOList())){
testPlanApiCaseService.calculatePlanReportByApiCaseList(testPlanExecuteReportDTO.getApiCaseInfoDTOList(), report);
}else if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) {
testPlanApiCaseService.calculatePlanReport(new ArrayList<>(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap().values()), report);
}
if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) {
if(CollectionUtils.isNotEmpty(testPlanExecuteReportDTO.getScenarioInfoDTOList())){
testPlanScenarioCaseService.calculatePlanReportByScenarioList(testPlanExecuteReportDTO.getScenarioInfoDTOList(), report);
}else if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) {
testPlanScenarioCaseService.calculatePlanReport(new ArrayList<>(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap().values()), report);
}
if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap())) {
testPlanLoadCaseService.calculatePlanReport(new ArrayList<>(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap().values()), report);
}