fix: 测试计划中功能用例关联的用例执行完自动更新功能用例的状态
This commit is contained in:
parent
ef6fe018e2
commit
7708a39416
|
@ -15,14 +15,17 @@ 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.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.notice.sender.NoticeModel;
|
import io.metersphere.notice.sender.NoticeModel;
|
||||||
import io.metersphere.notice.service.NoticeSendService;
|
import io.metersphere.notice.service.NoticeSendService;
|
||||||
import io.metersphere.track.dto.TestPlanDTO;
|
import io.metersphere.track.dto.TestPlanDTO;
|
||||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||||
|
import io.metersphere.track.request.testcase.TrackCount;
|
||||||
import io.metersphere.track.service.TestCaseReviewApiCaseService;
|
import io.metersphere.track.service.TestCaseReviewApiCaseService;
|
||||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||||
import io.metersphere.track.service.TestPlanService;
|
import io.metersphere.track.service.TestPlanService;
|
||||||
|
import io.metersphere.track.service.TestPlanTestCaseService;
|
||||||
import org.apache.commons.beanutils.BeanMap;
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -61,6 +64,12 @@ public class ApiDefinitionExecResultService {
|
||||||
@Resource
|
@Resource
|
||||||
private NoticeSendService noticeSendService;
|
private NoticeSendService noticeSendService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestPlanTestCaseService testPlanTestCaseService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ApiTestCaseService apiTestCaseService;
|
||||||
|
|
||||||
public ApiDefinitionExecResult getInfo(String id) {
|
public ApiDefinitionExecResult getInfo(String id) {
|
||||||
return apiDefinitionExecResultMapper.selectByPrimaryKey(id);
|
return apiDefinitionExecResultMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +140,9 @@ public class ApiDefinitionExecResultService {
|
||||||
} else {
|
} else {
|
||||||
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(saveResult);
|
apiDefinitionExecResultMapper.updateByPrimaryKeyWithBLOBs(saveResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTestCaseStates(saveResult.getResourceId());
|
||||||
|
|
||||||
apiDefinitionService.removeCache(result.getTestId());
|
apiDefinitionService.removeCache(result.getTestId());
|
||||||
if (StringUtils.isNotEmpty(result.getTestId())) {
|
if (StringUtils.isNotEmpty(result.getTestId())) {
|
||||||
MessageCache.caseExecResourceLock.remove(result.getTestId());
|
MessageCache.caseExecResourceLock.remove(result.getTestId());
|
||||||
|
@ -144,6 +156,7 @@ public class ApiDefinitionExecResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendNotice(ApiDefinitionExecResult result) {
|
private void sendNotice(ApiDefinitionExecResult result) {
|
||||||
String resourceId = result.getResourceId();
|
String resourceId = result.getResourceId();
|
||||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(resourceId);
|
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseMapper.selectByPrimaryKey(resourceId);
|
||||||
|
@ -348,6 +361,8 @@ public class ApiDefinitionExecResultService {
|
||||||
testCaseReviewApiCaseService.setExecResult(caseId, status, item.getStartTime());
|
testCaseReviewApiCaseService.setExecResult(caseId, status, item.getStartTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTestCaseStates(caseId);
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(caseId)) {
|
if (StringUtils.isNotEmpty(caseId)) {
|
||||||
apiIdResultMap.put(caseId, item.isSuccess() ? TestPlanApiExecuteStatus.SUCCESS.name() : TestPlanApiExecuteStatus.FAILD.name());
|
apiIdResultMap.put(caseId, item.isSuccess() ? TestPlanApiExecuteStatus.SUCCESS.name() : TestPlanApiExecuteStatus.FAILD.name());
|
||||||
}
|
}
|
||||||
|
@ -364,6 +379,21 @@ public class ApiDefinitionExecResultService {
|
||||||
TestPlanReportExecuteCatch.updateTestPlanReport(testPlanReportId, caseReportMap, null);
|
TestPlanReportExecuteCatch.updateTestPlanReport(testPlanReportId, caseReportMap, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新测试计划中, 关联接口测试的功能用例的状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void updateTestCaseStates(String testPlanApiCaseId) {
|
||||||
|
try {
|
||||||
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testPlanApiCaseId);
|
||||||
|
if (testPlanApiCase == null) return;
|
||||||
|
ApiTestCaseWithBLOBs apiTestCase = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
||||||
|
testPlanTestCaseService.updateTestCaseStates(apiTestCase.getId(), apiTestCase.getName(), testPlanApiCase.getTestPlanId(), TrackCount.TESTCASE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteByResourceId(String resourceId) {
|
public void deleteByResourceId(String resourceId) {
|
||||||
ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample();
|
ApiDefinitionExecResultExample example = new ApiDefinitionExecResultExample();
|
||||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||||
|
|
|
@ -22,10 +22,7 @@ import io.metersphere.base.mapper.ext.ExtApiScenarioReportDetailMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.*;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
|
||||||
import io.metersphere.dto.ApiReportCountDTO;
|
import io.metersphere.dto.ApiReportCountDTO;
|
||||||
import io.metersphere.dto.NodeDTO;
|
import io.metersphere.dto.NodeDTO;
|
||||||
import io.metersphere.dto.UserDTO;
|
import io.metersphere.dto.UserDTO;
|
||||||
|
@ -37,6 +34,8 @@ import io.metersphere.log.vo.api.ModuleReference;
|
||||||
import io.metersphere.notice.sender.NoticeModel;
|
import io.metersphere.notice.sender.NoticeModel;
|
||||||
import io.metersphere.notice.service.NoticeSendService;
|
import io.metersphere.notice.service.NoticeSendService;
|
||||||
import io.metersphere.service.UserService;
|
import io.metersphere.service.UserService;
|
||||||
|
import io.metersphere.track.request.testcase.TrackCount;
|
||||||
|
import io.metersphere.track.service.TestPlanTestCaseService;
|
||||||
import org.apache.commons.beanutils.BeanMap;
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -46,6 +45,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -86,6 +86,12 @@ public class ApiScenarioReportService {
|
||||||
private EnvironmentGroupMapper environmentGroupMapper;
|
private EnvironmentGroupMapper environmentGroupMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
|
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private TestPlanTestCaseService testPlanTestCaseService;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private ApiAutomationService apiAutomationService;
|
||||||
|
|
||||||
public ApiScenarioReport complete(TestResult result, String runMode) {
|
public ApiScenarioReport complete(TestResult result, String runMode) {
|
||||||
// 更新场景
|
// 更新场景
|
||||||
|
@ -269,7 +275,6 @@ public class ApiScenarioReportService {
|
||||||
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
||||||
testPlanApiScenario.setPassRate(passRate);
|
testPlanApiScenario.setPassRate(passRate);
|
||||||
testPlanApiScenario.setReportId(report.getId());
|
testPlanApiScenario.setReportId(report.getId());
|
||||||
report.setTestPlanScenarioId(testPlanApiScenario.getId());
|
|
||||||
report.setEndTime(System.currentTimeMillis());
|
report.setEndTime(System.currentTimeMillis());
|
||||||
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
|
@ -294,6 +299,8 @@ public class ApiScenarioReportService {
|
||||||
// 发送通知
|
// 发送通知
|
||||||
// sendNotice(scenario);
|
// sendNotice(scenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePlanTestCaseStates(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
returnReport = report;
|
returnReport = report;
|
||||||
reportIds.add(report.getId());
|
reportIds.add(report.getId());
|
||||||
|
@ -353,8 +360,6 @@ public class ApiScenarioReportService {
|
||||||
if(testPlanApiScenario != null){
|
if(testPlanApiScenario != null){
|
||||||
//更新测试计划场景相关状态
|
//更新测试计划场景相关状态
|
||||||
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
|
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
|
||||||
report.setTestPlanScenarioId(planScenarioId);
|
|
||||||
|
|
||||||
if (scenarioResult.getError() > 0) {
|
if (scenarioResult.getError() > 0) {
|
||||||
scenarioAndErrorMap.put(testPlanApiScenario.getId(), TestPlanApiExecuteStatus.FAILD.name());
|
scenarioAndErrorMap.put(testPlanApiScenario.getId(), TestPlanApiExecuteStatus.FAILD.name());
|
||||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||||
|
@ -367,6 +372,8 @@ public class ApiScenarioReportService {
|
||||||
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
|
scenarioIdList.add(testPlanApiScenario.getApiScenarioId());
|
||||||
|
|
||||||
|
updatePlanTestCaseStates(testPlanApiScenario);
|
||||||
}else {
|
}else {
|
||||||
LogUtil.info("TestPlanReport_Id is null. scenario report id : ["+report.getId()+"]; planScenarioIdArr:["+report.getScenarioId()+"] DATA:"+JSON.toJSONString(scenarioResult));
|
LogUtil.info("TestPlanReport_Id is null. scenario report id : ["+report.getId()+"]; planScenarioIdArr:["+report.getScenarioId()+"] DATA:"+JSON.toJSONString(scenarioResult));
|
||||||
}
|
}
|
||||||
|
@ -420,6 +427,19 @@ public class ApiScenarioReportService {
|
||||||
return lastReport;
|
return lastReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新测试计划,关联产经测试的功能用例的状态
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void updatePlanTestCaseStates(TestPlanApiScenario testPlanApiScenario) {
|
||||||
|
try {
|
||||||
|
ApiScenarioWithBLOBs apiScenario = apiAutomationService.getApiScenario(testPlanApiScenario.getApiScenarioId());
|
||||||
|
testPlanTestCaseService.updateTestCaseStates(apiScenario.getId(), apiScenario.getName(), testPlanApiScenario.getTestPlanId(), TrackCount.AUTOMATION);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量更新状态,防止重复刷新报告
|
* 批量更新状态,防止重复刷新报告
|
||||||
*
|
*
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.commons.constants.APITestStatus;
|
import io.metersphere.commons.constants.APITestStatus;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -29,6 +30,12 @@ public class RemakeReportService {
|
||||||
private TestCaseReviewApiCaseMapper testCaseReviewApiCaseMapper;
|
private TestCaseReviewApiCaseMapper testCaseReviewApiCaseMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private ApiScenarioReportService apiScenarioReportService;
|
||||||
|
@Resource
|
||||||
|
@Lazy
|
||||||
|
private ApiDefinitionExecResultService apiDefinitionExecResultService;
|
||||||
|
|
||||||
public void remake(RunRequest runRequest, RunModeConfig config, String reportId) {
|
public void remake(RunRequest runRequest, RunModeConfig config, String reportId) {
|
||||||
if (config != null && config.getAmassReport() != null && MessageCache.cache.get(config.getAmassReport()) != null
|
if (config != null && config.getAmassReport() != null && MessageCache.cache.get(config.getAmassReport()) != null
|
||||||
|
@ -50,6 +57,7 @@ public class RemakeReportService {
|
||||||
testPlanApiCase.setStatus("error");
|
testPlanApiCase.setStatus("error");
|
||||||
testPlanApiCase.setUpdateTime(System.currentTimeMillis());
|
testPlanApiCase.setUpdateTime(System.currentTimeMillis());
|
||||||
testPlanApiCaseMapper.updateByPrimaryKeySelective(testPlanApiCase);
|
testPlanApiCaseMapper.updateByPrimaryKeySelective(testPlanApiCase);
|
||||||
|
apiDefinitionExecResultService.updateTestCaseStates(testPlanApiCase.getId());
|
||||||
}
|
}
|
||||||
TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(runRequest.getTestId());
|
TestCaseReviewApiCase testCaseReviewApiCase = testCaseReviewApiCaseMapper.selectByPrimaryKey(runRequest.getTestId());
|
||||||
if (testCaseReviewApiCase != null) {
|
if (testCaseReviewApiCase != null) {
|
||||||
|
@ -71,10 +79,10 @@ public class RemakeReportService {
|
||||||
testPlanApiScenario.setReportId(report.getId());
|
testPlanApiScenario.setReportId(report.getId());
|
||||||
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
|
|
||||||
report.setTestPlanScenarioId(testPlanApiScenario.getId());
|
|
||||||
}
|
}
|
||||||
apiScenarioReportMapper.updateByPrimaryKey(report);
|
apiScenarioReportMapper.updateByPrimaryKey(report);
|
||||||
|
|
||||||
|
apiScenarioReportService.updatePlanTestCaseStates(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
} else if (StringUtils.equalsAny(runRequest.getRunMode(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
|
} else if (StringUtils.equalsAny(runRequest.getRunMode(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
|
||||||
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
|
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
|
||||||
|
@ -85,7 +93,6 @@ public class RemakeReportService {
|
||||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(planScenarioId);
|
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(planScenarioId);
|
||||||
if (testPlanApiScenario != null) {
|
if (testPlanApiScenario != null) {
|
||||||
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
|
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
|
||||||
report.setTestPlanScenarioId(planScenarioId);
|
|
||||||
report.setEndTime(System.currentTimeMillis());
|
report.setEndTime(System.currentTimeMillis());
|
||||||
|
|
||||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||||
|
@ -95,6 +102,8 @@ public class RemakeReportService {
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||||
|
|
||||||
|
apiScenarioReportService.updatePlanTestCaseStates(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
|
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);
|
||||||
|
@ -129,7 +138,6 @@ public class RemakeReportService {
|
||||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testId);
|
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testId);
|
||||||
if (testPlanApiScenario != null) {
|
if (testPlanApiScenario != null) {
|
||||||
report.setScenarioId(scenarioWithBLOBs.getId());
|
report.setScenarioId(scenarioWithBLOBs.getId());
|
||||||
report.setTestPlanScenarioId(testId);
|
|
||||||
report.setEndTime(System.currentTimeMillis());
|
report.setEndTime(System.currentTimeMillis());
|
||||||
|
|
||||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||||
|
@ -137,6 +145,8 @@ public class RemakeReportService {
|
||||||
testPlanApiScenario.setReportId(report.getId());
|
testPlanApiScenario.setReportId(report.getId());
|
||||||
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
|
|
||||||
|
apiScenarioReportService.updatePlanTestCaseStates(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scenarioWithBLOBs.setLastResult("Fail");
|
scenarioWithBLOBs.setLastResult("Fail");
|
||||||
|
|
|
@ -3,7 +3,10 @@ package io.metersphere.api.service;
|
||||||
import io.metersphere.api.dto.automation.ApiTestReportVariable;
|
import io.metersphere.api.dto.automation.ApiTestReportVariable;
|
||||||
import io.metersphere.api.jmeter.TestResult;
|
import io.metersphere.api.jmeter.TestResult;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
|
import io.metersphere.commons.constants.NoticeConstants;
|
||||||
|
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||||
|
import io.metersphere.commons.constants.TriggerMode;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
|
@ -12,19 +15,13 @@ import io.metersphere.i18n.Translator;
|
||||||
import io.metersphere.notice.sender.NoticeModel;
|
import io.metersphere.notice.sender.NoticeModel;
|
||||||
import io.metersphere.notice.service.NoticeSendService;
|
import io.metersphere.notice.service.NoticeSendService;
|
||||||
import io.metersphere.service.SystemParameterService;
|
import io.metersphere.service.SystemParameterService;
|
||||||
import io.metersphere.track.request.testcase.TrackCount;
|
|
||||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
|
||||||
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
|
||||||
import io.metersphere.track.service.TestPlanTestCaseService;
|
|
||||||
import org.apache.commons.beanutils.BeanMap;
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -40,16 +37,10 @@ public class TestResultService {
|
||||||
private ApiTestCaseService apiTestCaseService;
|
private ApiTestCaseService apiTestCaseService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiAutomationService apiAutomationService;
|
private ApiAutomationService apiAutomationService;
|
||||||
@Resource
|
|
||||||
private TestPlanApiCaseService testPlanApiCaseService;
|
|
||||||
@Resource
|
|
||||||
private TestPlanTestCaseService testPlanTestCaseService;
|
|
||||||
|
|
||||||
public void saveResult(TestResult testResult, String runMode, String debugReportId, String testId) {
|
public void saveResult(TestResult testResult, String runMode, String debugReportId, String testId) {
|
||||||
try {
|
try {
|
||||||
ApiTestReport report = null;
|
|
||||||
ApiTestReportVariable reportTask = null;
|
ApiTestReportVariable reportTask = null;
|
||||||
String planScenarioId = null;
|
|
||||||
if (StringUtils.equals(runMode, ApiRunMode.DEFINITION.name())) {
|
if (StringUtils.equals(runMode, ApiRunMode.DEFINITION.name())) {
|
||||||
// 调试操作,不需要存储结果
|
// 调试操作,不需要存储结果
|
||||||
apiDefinitionService.addResult(testResult);
|
apiDefinitionService.addResult(testResult);
|
||||||
|
@ -118,16 +109,6 @@ public class TestResultService {
|
||||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||||
assert systemParameterService != null;
|
assert systemParameterService != null;
|
||||||
testResult.setTestId(scenarioReport.getScenarioId());
|
testResult.setTestId(scenarioReport.getScenarioId());
|
||||||
planScenarioId = scenarioReport.getTestPlanScenarioId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateTestCaseStates(testResult, planScenarioId, runMode);
|
|
||||||
List<String> ids = testPlanTestCaseService.getTestPlanTestCaseIds(testResult.getTestId());
|
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
|
||||||
if (StringUtils.equals(APITestStatus.Success.name(), report.getStatus())) {
|
|
||||||
testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Pass.name());
|
|
||||||
} else {
|
|
||||||
testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Failure.name());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reportTask != null) {
|
if (reportTask != null) {
|
||||||
|
@ -141,39 +122,6 @@ public class TestResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新测试计划关联接口测试的功能用例的状态
|
|
||||||
*
|
|
||||||
* @param testResult
|
|
||||||
*/
|
|
||||||
private void updateTestCaseStates(TestResult testResult, String testPlanScenarioId, String runMode) {
|
|
||||||
try {
|
|
||||||
if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(),
|
|
||||||
ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) {
|
|
||||||
testResult.getScenarios().forEach(scenarioResult -> {
|
|
||||||
if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
|
|
||||||
scenarioResult.getRequestResults().forEach(item -> {
|
|
||||||
if (StringUtils.equalsAny(runMode, ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(),
|
|
||||||
ApiRunMode.JENKINS_API_PLAN.name())) {
|
|
||||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(item.getName());
|
|
||||||
ApiTestCaseWithBLOBs apiTestCase = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
|
||||||
testPlanTestCaseService.updateTestCaseStates(apiTestCase.getId(), apiTestCase.getName(), testPlanApiCase.getTestPlanId(), TrackCount.TESTCASE);
|
|
||||||
} else {
|
|
||||||
TestPlanScenarioCaseService testPlanScenarioCaseService = CommonBeanFactory.getBean(TestPlanScenarioCaseService.class);
|
|
||||||
TestPlanApiScenario testPlanApiScenario = testPlanScenarioCaseService.get(testPlanScenarioId);
|
|
||||||
ApiScenarioWithBLOBs apiScenario = apiAutomationService.getApiScenario(testPlanApiScenario.getApiScenarioId());
|
|
||||||
testPlanTestCaseService.updateTestCaseStates(apiScenario.getId(), apiScenario.getName(), testPlanApiScenario.getTestPlanId(), TrackCount.AUTOMATION);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LogUtil.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendTask(ApiTestReportVariable report, TestResult testResult) {
|
private void sendTask(ApiTestReportVariable report, TestResult testResult) {
|
||||||
if (report == null) {
|
if (report == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -34,8 +34,6 @@ public class ApiScenarioReport implements Serializable {
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
private String testPlanScenarioId;
|
|
||||||
|
|
||||||
private Long endTime;
|
private Long endTime;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
@ -34,8 +34,6 @@ public interface ExtTestPlanTestCaseMapper {
|
||||||
|
|
||||||
int updateTestCaseStates(@Param("ids") List<String> ids, @Param("reportStatus") String reportStatus);
|
int updateTestCaseStates(@Param("ids") List<String> ids, @Param("reportStatus") String reportStatus);
|
||||||
|
|
||||||
List<String> getTestPlanTestCaseIds(String testId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据项目 ids 查询 TestPlanCaseDTO 列表
|
* 根据项目 ids 查询 TestPlanCaseDTO 列表
|
||||||
* @param ids project id list
|
* @param ids project id list
|
||||||
|
|
|
@ -359,15 +359,6 @@
|
||||||
from test_plan_test_case
|
from test_plan_test_case
|
||||||
where plan_id = #{planId}
|
where plan_id = #{planId}
|
||||||
</select>
|
</select>
|
||||||
<select id="getTestPlanTestCaseIds" resultType="java.lang.String">
|
|
||||||
select c.id from test_case a left join test_plan_test_case c on a.id=c.case_id
|
|
||||||
<where>
|
|
||||||
<if test="testId!=null">
|
|
||||||
and a.test_id=#{testId}
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="get" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
|
<select id="get" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
|
||||||
select test_case.remark,
|
select test_case.remark,
|
||||||
test_plan_test_case.id as id,
|
test_plan_test_case.id as id,
|
||||||
|
|
|
@ -206,6 +206,12 @@ public class TestPlanApiCaseService {
|
||||||
return testPlanApiCaseMapper.selectByExample(example);
|
return testPlanApiCaseMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TestPlanApiCase> getCases(String planId) {
|
||||||
|
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||||
|
example.createCriteria().andTestPlanIdEqualTo(planId);
|
||||||
|
return testPlanApiCaseMapper.selectByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
public TestPlanApiCase getById(String id) {
|
public TestPlanApiCase getById(String id) {
|
||||||
return testPlanApiCaseMapper.selectByPrimaryKey(id);
|
return testPlanApiCaseMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,14 +217,6 @@ public class TestPlanTestCaseService {
|
||||||
testPlanTestCaseMapper.deleteByExample(example);
|
testPlanTestCaseMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTestPlanTestCaseIds(String testId) {
|
|
||||||
return extTestPlanTestCaseMapper.getTestPlanTestCaseIds(testId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int updateTestCaseStates(List<String> ids, String reportStatus) {
|
|
||||||
return extTestPlanTestCaseMapper.updateTestCaseStates(ids, reportStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新测试计划关联接口测试的功能用例的状态
|
* 更新测试计划关联接口测试的功能用例的状态
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue