fix(接口自动化): 批量执行,不同模式切换问题
This commit is contained in:
parent
b610e11b4e
commit
91c7f25067
|
@ -118,6 +118,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
MsHTTPSamplerProxy proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
MsHTTPSamplerProxy proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
||||||
});
|
});
|
||||||
this.setHashTree(proxy.getHashTree());
|
this.setHashTree(proxy.getHashTree());
|
||||||
|
this.setName(bloBs.getName());
|
||||||
|
this.setMethod(proxy.getMethod());
|
||||||
|
this.setBody(proxy.getBody());
|
||||||
|
this.setRest(proxy.getRest());
|
||||||
|
this.setArguments(proxy.getArguments());
|
||||||
|
this.setHeaders(proxy.getHeaders());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||||
|
@ -126,6 +132,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
MsHTTPSamplerProxy proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
MsHTTPSamplerProxy proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
||||||
});
|
});
|
||||||
this.setHashTree(proxy.getHashTree());
|
this.setHashTree(proxy.getHashTree());
|
||||||
|
this.setName(apiDefinition.getName());
|
||||||
|
this.setMethod(proxy.getMethod());
|
||||||
|
this.setBody(proxy.getBody());
|
||||||
|
this.setRest(proxy.getRest());
|
||||||
|
this.setArguments(proxy.getArguments());
|
||||||
|
this.setHeaders(proxy.getHeaders());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -567,7 +567,7 @@ public class ApiAutomationService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public APIScenarioReportResult createScenarioReport(String id, String scenarioId, String scenarioName, String triggerMode, String execType, String projectId, String userID) {
|
public APIScenarioReportResult createScenarioReport(String id, String scenarioId, String scenarioName, String triggerMode, String execType, String projectId, String userID, RunModeConfig config) {
|
||||||
APIScenarioReportResult report = new APIScenarioReportResult();
|
APIScenarioReportResult report = new APIScenarioReportResult();
|
||||||
if (triggerMode.equals(ApiRunMode.SCENARIO.name()) || triggerMode.equals(ApiRunMode.DEFINITION.name())) {
|
if (triggerMode.equals(ApiRunMode.SCENARIO.name()) || triggerMode.equals(ApiRunMode.DEFINITION.name())) {
|
||||||
triggerMode = ReportTriggerMode.MANUAL.name();
|
triggerMode = ReportTriggerMode.MANUAL.name();
|
||||||
|
@ -579,8 +579,12 @@ public class ApiAutomationService {
|
||||||
} else {
|
} else {
|
||||||
report.setName("场景调试");
|
report.setName("场景调试");
|
||||||
}
|
}
|
||||||
report.setCreateTime(System.currentTimeMillis());
|
|
||||||
report.setUpdateTime(System.currentTimeMillis());
|
report.setUpdateTime(System.currentTimeMillis());
|
||||||
|
report.setCreateTime(System.currentTimeMillis());
|
||||||
|
if (config != null && config.getMode().equals("serial")) {
|
||||||
|
report.setCreateTime(System.currentTimeMillis() + 2000);
|
||||||
|
report.setUpdateTime(System.currentTimeMillis() + 2000);
|
||||||
|
}
|
||||||
report.setStatus(APITestStatus.Running.name());
|
report.setStatus(APITestStatus.Running.name());
|
||||||
if (StringUtils.isNotEmpty(userID)) {
|
if (StringUtils.isNotEmpty(userID)) {
|
||||||
report.setUserId(userID);
|
report.setUserId(userID);
|
||||||
|
@ -733,10 +737,10 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report = createScenarioReport(reportId, testPlanScenarioId, item.getName(), request.getTriggerMode(),
|
report = createScenarioReport(reportId, testPlanScenarioId, item.getName(), request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), null);
|
||||||
} else {
|
} else {
|
||||||
report = createScenarioReport(reportId, item.getId(), item.getName(), request.getTriggerMode(),
|
report = createScenarioReport(reportId, item.getId(), item.getName(), request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成报告和HashTree
|
// 生成报告和HashTree
|
||||||
|
@ -769,8 +773,13 @@ public class ApiAutomationService {
|
||||||
private HashTree generateHashTree(List<ApiScenarioWithBLOBs> apiScenarios, RunScenarioRequest request, List<String> reportIds) {
|
private HashTree generateHashTree(List<ApiScenarioWithBLOBs> apiScenarios, RunScenarioRequest request, List<String> reportIds) {
|
||||||
HashTree jmeterHashTree = new ListedHashTree();
|
HashTree jmeterHashTree = new ListedHashTree();
|
||||||
MsTestPlan testPlan = new MsTestPlan();
|
MsTestPlan testPlan = new MsTestPlan();
|
||||||
testPlan.setSerializeThreadgroups(request.getConfig() != null && request.getConfig().getMode().equals("serial"));
|
|
||||||
testPlan.setHashTree(new LinkedList<>());
|
testPlan.setHashTree(new LinkedList<>());
|
||||||
|
if (request.getConfig() != null && request.getConfig().getMode().equals("serial")) {
|
||||||
|
testPlan.setSerializeThreadgroups(true);
|
||||||
|
if (StringUtils.isNotEmpty(request.getConfig().getReportName())) {
|
||||||
|
request.setExecuteType(ExecuteType.Completed.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
for (ApiScenarioWithBLOBs item : apiScenarios) {
|
for (ApiScenarioWithBLOBs item : apiScenarios) {
|
||||||
|
@ -791,7 +800,6 @@ public class ApiAutomationService {
|
||||||
// 批量执行的结果直接存储为报告
|
// 批量执行的结果直接存储为报告
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
group.setName(request.getId());
|
group.setName(request.getId());
|
||||||
isFirst = false;
|
|
||||||
}
|
}
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
@ -829,15 +837,16 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig());
|
||||||
} else {
|
} else {
|
||||||
createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig());
|
||||||
}
|
}
|
||||||
reportIds.add(group.getName());
|
reportIds.add(group.getName());
|
||||||
}
|
}
|
||||||
group.setHashTree(scenarios);
|
group.setHashTree(scenarios);
|
||||||
testPlan.getHashTree().add(group);
|
testPlan.getHashTree().add(group);
|
||||||
|
isFirst = false;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
MSException.throwException(ex.getMessage());
|
MSException.throwException(ex.getMessage());
|
||||||
|
@ -859,7 +868,11 @@ public class ApiAutomationService {
|
||||||
List<String> ids = request.getIds();
|
List<String> ids = request.getIds();
|
||||||
//检查是否有正在执行中的情景
|
//检查是否有正在执行中的情景
|
||||||
this.checkScenarioIsRunning(ids);
|
this.checkScenarioIsRunning(ids);
|
||||||
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(ids);
|
StringBuilder idStr = new StringBuilder();
|
||||||
|
ids.forEach(item -> {
|
||||||
|
idStr.append("\"").append(item).append("\"").append(",");
|
||||||
|
});
|
||||||
|
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectByIds(idStr.toString().substring(0, idStr.toString().length() - 1), "\"" + StringUtils.join(ids, ",") + "\"");
|
||||||
|
|
||||||
String runMode = ApiRunMode.SCENARIO.name();
|
String runMode = ApiRunMode.SCENARIO.name();
|
||||||
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) {
|
if (StringUtils.isNotBlank(request.getRunMode()) && StringUtils.equals(request.getRunMode(), ApiRunMode.SCENARIO_PLAN.name())) {
|
||||||
|
@ -936,7 +949,7 @@ public class ApiAutomationService {
|
||||||
}
|
}
|
||||||
// 调用执行方法
|
// 调用执行方法
|
||||||
createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
|
createScenarioReport(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),
|
||||||
SessionUtils.getUserId());
|
SessionUtils.getUserId(), null);
|
||||||
// 调用执行方法
|
// 调用执行方法
|
||||||
// jMeterService.runTest(request.getId(), hashTree, ApiRunMode.SCENARIO.name(), null);
|
// jMeterService.runTest(request.getId(), hashTree, ApiRunMode.SCENARIO.name(), null);
|
||||||
// 调用执行方法
|
// 调用执行方法
|
||||||
|
|
|
@ -49,41 +49,44 @@ public class ApiDefinitionExecResultService {
|
||||||
if (CollectionUtils.isNotEmpty(result.getScenarios())) {
|
if (CollectionUtils.isNotEmpty(result.getScenarios())) {
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
|
ApiDefinitionExecResultMapper definitionExecResultMapper = sqlSession.getMapper(ApiDefinitionExecResultMapper.class);
|
||||||
result.getScenarios().get(0).getRequestResults().forEach(item -> {
|
result.getScenarios().forEach(scenarioResult -> {
|
||||||
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
|
if (scenarioResult != null && CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
|
||||||
saveResult.setId(UUID.randomUUID().toString());
|
scenarioResult.getRequestResults().forEach(item -> {
|
||||||
saveResult.setCreateTime(System.currentTimeMillis());
|
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
|
||||||
saveResult.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
saveResult.setId(UUID.randomUUID().toString());
|
||||||
saveResult.setName(item.getName());
|
saveResult.setCreateTime(item.getStartTime());
|
||||||
if (item.getName().indexOf("<->") != -1) {
|
saveResult.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||||
saveResult.setName(item.getName().substring(0, item.getName().indexOf("<->")));
|
saveResult.setName(item.getName());
|
||||||
}
|
if (item.getName().indexOf("<->") != -1) {
|
||||||
saveResult.setResourceId(item.getName());
|
saveResult.setName(item.getName().substring(0, item.getName().indexOf("<->")));
|
||||||
saveResult.setContent(JSON.toJSONString(item));
|
}
|
||||||
saveResult.setStartTime(item.getStartTime());
|
saveResult.setResourceId(item.getName());
|
||||||
String status = item.isSuccess() ? "success" : "error";
|
saveResult.setContent(JSON.toJSONString(item));
|
||||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
saveResult.setStartTime(item.getStartTime());
|
||||||
saveResult.setType(type);
|
String status = item.isSuccess() ? "success" : "error";
|
||||||
saveResult.setStatus(status);
|
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||||
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
saveResult.setType(type);
|
||||||
testPlanApiCaseService.setExecResult(item.getName(), status);
|
saveResult.setStatus(status);
|
||||||
testCaseReviewApiCaseService.setExecResult(item.getName(), status);
|
if (StringUtils.equals(type, ApiRunMode.API_PLAN.name())) {
|
||||||
|
testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||||
|
testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// 清空上次执行结果的内容,只保留当前最新一条内容
|
||||||
|
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type);
|
||||||
|
if (prevResult != null) {
|
||||||
|
prevResult.setContent(null);
|
||||||
|
definitionExecResultMapper.updateByPrimaryKeyWithBLOBs(prevResult);
|
||||||
|
}
|
||||||
|
// 更新用例最后执行结果
|
||||||
|
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = new ApiTestCaseWithBLOBs();
|
||||||
|
apiTestCaseWithBLOBs.setId(saveResult.getResourceId());
|
||||||
|
apiTestCaseWithBLOBs.setLastResultId(saveResult.getId());
|
||||||
|
|
||||||
// 清空上次执行结果的内容,只保留当前最新一条内容
|
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCaseWithBLOBs);
|
||||||
ApiDefinitionExecResult prevResult = extApiDefinitionExecResultMapper.selectMaxResultByResourceIdAndType(item.getName(), type);
|
definitionExecResultMapper.insert(saveResult);
|
||||||
if (prevResult != null) {
|
});
|
||||||
prevResult.setContent(null);
|
|
||||||
definitionExecResultMapper.updateByPrimaryKeyWithBLOBs(prevResult);
|
|
||||||
}
|
}
|
||||||
// 更新用例最后执行结果
|
|
||||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = new ApiTestCaseWithBLOBs();
|
|
||||||
apiTestCaseWithBLOBs.setId(saveResult.getResourceId());
|
|
||||||
apiTestCaseWithBLOBs.setLastResultId(saveResult.getId());
|
|
||||||
|
|
||||||
apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCaseWithBLOBs);
|
|
||||||
definitionExecResultMapper.insert(saveResult);
|
|
||||||
});
|
});
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
}
|
}
|
||||||
|
@ -126,8 +129,8 @@ public class ApiDefinitionExecResultService {
|
||||||
testPlanApiCaseService.updateByPrimaryKeySelective(apiCase);
|
testPlanApiCaseService.updateByPrimaryKeySelective(apiCase);
|
||||||
} else {
|
} else {
|
||||||
userID = Objects.requireNonNull(SessionUtils.getUser()).getId();
|
userID = Objects.requireNonNull(SessionUtils.getUser()).getId();
|
||||||
testPlanApiCaseService.setExecResult(item.getName(), status);
|
testPlanApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||||
testCaseReviewApiCaseService.setExecResult(item.getName(), status);
|
testCaseReviewApiCaseService.setExecResult(item.getName(), status, item.getStartTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
saveResult.setUserId(userID);
|
saveResult.setUserId(userID);
|
||||||
|
|
|
@ -15,12 +15,13 @@ import io.metersphere.base.mapper.ApiScenarioReportDetailMapper;
|
||||||
import io.metersphere.base.mapper.ApiScenarioReportMapper;
|
import io.metersphere.base.mapper.ApiScenarioReportMapper;
|
||||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
|
|
||||||
import io.metersphere.commons.constants.APITestStatus;
|
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
import io.metersphere.commons.utils.DateUtils;
|
||||||
|
import io.metersphere.commons.utils.ServiceUtils;
|
||||||
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
import io.metersphere.track.service.TestPlanReportService;
|
import io.metersphere.track.service.TestPlanReportService;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
@ -57,9 +58,9 @@ public class ApiScenarioReportService {
|
||||||
// 更新场景
|
// 更新场景
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (StringUtils.equals(runMode, ApiRunMode.SCENARIO_PLAN.name())) {
|
if (StringUtils.equals(runMode, ApiRunMode.SCENARIO_PLAN.name())) {
|
||||||
return updatePlanCase(result,runMode);
|
return updatePlanCase(result, runMode);
|
||||||
} else if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
} else if (StringUtils.equals(runMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||||
return updateSchedulePlanCase(result,runMode);
|
return updateSchedulePlanCase(result, runMode);
|
||||||
} else {
|
} else {
|
||||||
updateScenarioStatus(result.getTestId());
|
updateScenarioStatus(result.getTestId());
|
||||||
return updateScenario(result, runMode);
|
return updateScenario(result, runMode);
|
||||||
|
@ -114,11 +115,12 @@ public class ApiScenarioReportService {
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiScenarioReport editReport(ScenarioResult test) {
|
public ApiScenarioReport editReport(ScenarioResult test, long startTime) {
|
||||||
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(test.getName());
|
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(test.getName());
|
||||||
report.setId(report.getId());
|
report.setId(report.getId());
|
||||||
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
|
report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis()));
|
||||||
report.setUpdateTime(System.currentTimeMillis());
|
report.setCreateTime(startTime);
|
||||||
|
report.setUpdateTime(startTime);
|
||||||
String status = test.getError() == 0 ? "Success" : "Error";
|
String status = test.getError() == 0 ? "Success" : "Error";
|
||||||
report.setStatus(status);
|
report.setStatus(status);
|
||||||
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||||
|
@ -166,7 +168,7 @@ public class ApiScenarioReportService {
|
||||||
return testResult;
|
return testResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiScenarioReport updatePlanCase(TestResult result,String runMode) {
|
public ApiScenarioReport updatePlanCase(TestResult result, String runMode) {
|
||||||
// TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
// TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
||||||
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
||||||
ApiScenarioReport returnReport = null;
|
ApiScenarioReport returnReport = null;
|
||||||
|
@ -175,9 +177,13 @@ public class ApiScenarioReportService {
|
||||||
String projectId = null;
|
String projectId = null;
|
||||||
String userId = null;
|
String userId = null;
|
||||||
TestResult fullResult = createTestResult(result);
|
TestResult fullResult = createTestResult(result);
|
||||||
for (ScenarioResult scenarioResult :
|
List<String> reportIds = new LinkedList<>();
|
||||||
scenarioResultList) {
|
for (ScenarioResult scenarioResult : scenarioResultList) {
|
||||||
ApiScenarioReport report = editReport(scenarioResult);
|
long startTime = System.currentTimeMillis();
|
||||||
|
if (CollectionUtils.isNotEmpty(scenarioResult.getRequestResults()) && scenarioResult.getRequestResults().get(0).getStartTime() > 0) {
|
||||||
|
startTime = scenarioResult.getRequestResults().get(0).getStartTime();
|
||||||
|
}
|
||||||
|
ApiScenarioReport report = editReport(scenarioResult, startTime);
|
||||||
// 报告详情内容
|
// 报告详情内容
|
||||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||||
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
|
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
|
||||||
|
@ -207,16 +213,17 @@ 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());
|
||||||
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
testPlanApiScenario.setUpdateTime(report.getCreateTime());
|
||||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||||
}
|
}
|
||||||
returnReport = report;
|
returnReport = report;
|
||||||
|
reportIds.add(report.getId());
|
||||||
}
|
}
|
||||||
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId);
|
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds);
|
||||||
return returnReport;
|
return returnReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiScenarioReport updateSchedulePlanCase(TestResult result,String runMode) {
|
public ApiScenarioReport updateSchedulePlanCase(TestResult result, String runMode) {
|
||||||
ApiScenarioReport lastReport = null;
|
ApiScenarioReport lastReport = null;
|
||||||
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
||||||
|
|
||||||
|
@ -226,9 +233,14 @@ public class ApiScenarioReportService {
|
||||||
String projectId = null;
|
String projectId = null;
|
||||||
String userId = null;
|
String userId = null;
|
||||||
TestResult fullResult = createTestResult(result);
|
TestResult fullResult = createTestResult(result);
|
||||||
|
List<String> reportIds = new ArrayList<>();
|
||||||
for (ScenarioResult scenarioResult : scenarioResultList) {
|
for (ScenarioResult scenarioResult : scenarioResultList) {
|
||||||
// 存储场景报告
|
// 存储场景报告
|
||||||
ApiScenarioReport report = editReport(scenarioResult);
|
long startTime = System.currentTimeMillis();
|
||||||
|
if (CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) {
|
||||||
|
startTime = scenarioResult.getRequestResults().get(0).getStartTime();
|
||||||
|
}
|
||||||
|
ApiScenarioReport report = editReport(scenarioResult, startTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试计划的定时任务场景执行时,主键是提前生成的【测试报告ID】。也就是TestResult.id是【测试报告ID】。
|
* 测试计划的定时任务场景执行时,主键是提前生成的【测试报告ID】。也就是TestResult.id是【测试报告ID】。
|
||||||
|
@ -280,9 +292,10 @@ public class ApiScenarioReportService {
|
||||||
scenarioNames.append(report.getName()).append(",");
|
scenarioNames.append(report.getName()).append(",");
|
||||||
|
|
||||||
lastReport = report;
|
lastReport = report;
|
||||||
|
reportIds.add(report.getId());
|
||||||
}
|
}
|
||||||
// 合并报告
|
// 合并报告
|
||||||
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId);
|
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds);
|
||||||
|
|
||||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
||||||
testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ReportTriggerMode.SCHEDULE.name());
|
testPlanReportService.updateReport(testPlanReportIdList, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ReportTriggerMode.SCHEDULE.name());
|
||||||
|
@ -323,9 +336,12 @@ public class ApiScenarioReportService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void margeReport(TestResult result, StringBuilder scenarioIds, StringBuilder scenarioNames, String runMode, String projectId, String userId) {
|
private void margeReport(TestResult result, StringBuilder scenarioIds, StringBuilder scenarioNames, String runMode, String projectId, String userId, List<String> reportIds) {
|
||||||
// 合并生成一份报告
|
// 合并生成一份报告
|
||||||
if (StringUtils.isNotEmpty(result.getReportName())) {
|
if (StringUtils.isNotEmpty(result.getReportName())) {
|
||||||
|
// 清理其他报告保留一份合并后的报告
|
||||||
|
this.deleteByIds(reportIds);
|
||||||
|
|
||||||
ApiScenarioReport report = createScenarioReport(scenarioIds.toString(), result.getReportName(), result.getError() > 0 ? "Error" : "Success", scenarioNames.toString().substring(0, scenarioNames.toString().length() - 1), runMode, projectId, userId);
|
ApiScenarioReport report = createScenarioReport(scenarioIds.toString(), result.getReportName(), result.getError() > 0 ? "Error" : "Success", scenarioNames.toString().substring(0, scenarioNames.toString().length() - 1), runMode, projectId, userId);
|
||||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||||
detail.setContent(JSON.toJSONString(result).getBytes(StandardCharsets.UTF_8));
|
detail.setContent(JSON.toJSONString(result).getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -342,9 +358,14 @@ public class ApiScenarioReportService {
|
||||||
String projectId = null;
|
String projectId = null;
|
||||||
String userId = null;
|
String userId = null;
|
||||||
TestResult fullResult = createTestResult(result);
|
TestResult fullResult = createTestResult(result);
|
||||||
|
List<String> reportIds = new LinkedList<>();
|
||||||
for (ScenarioResult item : result.getScenarios()) {
|
for (ScenarioResult item : result.getScenarios()) {
|
||||||
// 更新报告状态
|
// 更新报告状态
|
||||||
ApiScenarioReport report = editReport(item);
|
long startTime = System.currentTimeMillis();
|
||||||
|
if (CollectionUtils.isNotEmpty(item.getRequestResults())) {
|
||||||
|
startTime = item.getRequestResults().get(0).getStartTime();
|
||||||
|
}
|
||||||
|
ApiScenarioReport report = editReport(item, startTime);
|
||||||
TestResult newResult = createTestResult(result.getTestId(), item);
|
TestResult newResult = createTestResult(result.getTestId(), item);
|
||||||
item.setName(report.getScenarioName());
|
item.setName(report.getScenarioName());
|
||||||
newResult.addScenario(item);
|
newResult.addScenario(item);
|
||||||
|
@ -373,9 +394,10 @@ public class ApiScenarioReportService {
|
||||||
apiScenarioMapper.updateByPrimaryKey(scenario);
|
apiScenarioMapper.updateByPrimaryKey(scenario);
|
||||||
}
|
}
|
||||||
lastReport = report;
|
lastReport = report;
|
||||||
|
reportIds.add(report.getId());
|
||||||
}
|
}
|
||||||
// 合并生成一份报告
|
// 合并生成一份报告
|
||||||
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId);
|
margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds);
|
||||||
return lastReport;
|
return lastReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,10 +17,13 @@ public interface ExtApiScenarioMapper {
|
||||||
|
|
||||||
List<ApiScenarioWithBLOBs> selectIds(@Param("ids") List<String> ids);
|
List<ApiScenarioWithBLOBs> selectIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
List<ApiScenarioWithBLOBs> selectByIds(@Param("ids") String ids,@Param("oderId") String oderId);
|
||||||
|
|
||||||
List<ApiScenario> selectReference(@Param("request") ApiScenarioRequest request);
|
List<ApiScenario> selectReference(@Param("request") ApiScenarioRequest request);
|
||||||
|
|
||||||
int removeToGc(@Param("ids") List<String> ids);
|
int removeToGc(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
|
|
||||||
int removeToGcByExample(ApiScenarioExample example);
|
int removeToGcByExample(ApiScenarioExample example);
|
||||||
|
|
||||||
int reduction(@Param("ids") List<String> ids);
|
int reduction(@Param("ids") List<String> ids);
|
||||||
|
|
|
@ -256,6 +256,10 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIds" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||||
|
select * from api_scenario where id in (${ids}) ORDER BY FIND_IN_SET(id,${oderId})
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectReference" resultType="io.metersphere.base.domain.ApiScenario">
|
<select id="selectReference" resultType="io.metersphere.base.domain.ApiScenario">
|
||||||
select * from api_scenario
|
select * from api_scenario
|
||||||
<where>
|
<where>
|
||||||
|
|
|
@ -19,4 +19,7 @@ public interface ExtTestPlanScenarioCaseMapper {
|
||||||
List<String> getNotRelevanceCaseIds(String planId, List<String> relevanceProjectIds);
|
List<String> getNotRelevanceCaseIds(String planId, List<String> relevanceProjectIds);
|
||||||
|
|
||||||
List<String> selectIds(@Param("request")TestPlanScenarioRequest request);
|
List<String> selectIds(@Param("request")TestPlanScenarioRequest request);
|
||||||
|
|
||||||
|
List<TestPlanApiScenario> selectByIds(@Param("ids")String ids ,@Param("oderId")String oderId );
|
||||||
|
|
||||||
}
|
}
|
|
@ -88,6 +88,9 @@
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIds" resultType="io.metersphere.base.domain.TestPlanApiScenario">
|
||||||
|
select t.* from test_plan_api_scenario t where t.id in (${ids}) ORDER BY FIND_IN_SET(t.id,${oderId})
|
||||||
|
</select>
|
||||||
<select id="selectIds" resultType="java.lang.String">
|
<select id="selectIds" resultType="java.lang.String">
|
||||||
select
|
select
|
||||||
t.id
|
t.id
|
||||||
|
|
|
@ -7,8 +7,6 @@ import io.metersphere.api.service.ApiDefinitionExecResultService;
|
||||||
import io.metersphere.api.service.ApiTestCaseService;
|
import io.metersphere.api.service.ApiTestCaseService;
|
||||||
import io.metersphere.base.domain.TestCaseReviewApiCase;
|
import io.metersphere.base.domain.TestCaseReviewApiCase;
|
||||||
import io.metersphere.base.domain.TestCaseReviewApiCaseExample;
|
import io.metersphere.base.domain.TestCaseReviewApiCaseExample;
|
||||||
import io.metersphere.base.domain.TestPlanApiCase;
|
|
||||||
import io.metersphere.base.domain.TestPlanApiCaseExample;
|
|
||||||
import io.metersphere.base.mapper.TestCaseReviewApiCaseMapper;
|
import io.metersphere.base.mapper.TestCaseReviewApiCaseMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestCaseReviewApiCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestCaseReviewApiCaseMapper;
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
import io.metersphere.commons.utils.ServiceUtils;
|
||||||
|
@ -91,11 +89,11 @@ public class TestCaseReviewApiCaseService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setExecResult(String id, String status) {
|
public void setExecResult(String id, String status,Long time) {
|
||||||
TestCaseReviewApiCase apiCase = new TestCaseReviewApiCase();
|
TestCaseReviewApiCase apiCase = new TestCaseReviewApiCase();
|
||||||
apiCase.setId(id);
|
apiCase.setId(id);
|
||||||
apiCase.setStatus(status);
|
apiCase.setStatus(status);
|
||||||
apiCase.setUpdateTime(System.currentTimeMillis());
|
apiCase.setUpdateTime(time);
|
||||||
testCaseReviewApiCaseMapper.updateByPrimaryKeySelective(apiCase);
|
testCaseReviewApiCaseMapper.updateByPrimaryKeySelective(apiCase);
|
||||||
}
|
}
|
||||||
public void updateByPrimaryKeySelective(TestCaseReviewApiCase apiCase) {
|
public void updateByPrimaryKeySelective(TestCaseReviewApiCase apiCase) {
|
||||||
|
|
|
@ -122,11 +122,11 @@ public class TestPlanApiCaseService {
|
||||||
return testPlanApiCaseMapper.selectByPrimaryKey(id);
|
return testPlanApiCaseMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExecResult(String id, String status) {
|
public void setExecResult(String id, String status,Long time) {
|
||||||
TestPlanApiCase apiCase = new TestPlanApiCase();
|
TestPlanApiCase apiCase = new TestPlanApiCase();
|
||||||
apiCase.setId(id);
|
apiCase.setId(id);
|
||||||
apiCase.setStatus(status);
|
apiCase.setStatus(status);
|
||||||
apiCase.setUpdateTime(System.currentTimeMillis());
|
apiCase.setUpdateTime(time);
|
||||||
testPlanApiCaseMapper.updateByPrimaryKeySelective(apiCase);
|
testPlanApiCaseMapper.updateByPrimaryKeySelective(apiCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,14 +92,14 @@ public class TestPlanScenarioCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String run(RunScenarioRequest request) {
|
public String run(RunScenarioRequest request) {
|
||||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
StringBuilder idStr = new StringBuilder();
|
||||||
example.createCriteria().andIdIn(request.getPlanCaseIds());
|
request.getPlanCaseIds().forEach(item -> {
|
||||||
List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
idStr.append("\"").append(item).append("\"").append(",");
|
||||||
|
});
|
||||||
|
List<TestPlanApiScenario> testPlanApiScenarioList =extTestPlanScenarioCaseMapper.selectByIds(idStr.toString().substring(0, idStr.toString().length() - 1), "\"" + org.apache.commons.lang3.StringUtils.join(request.getPlanCaseIds(), ",") + "\"");
|
||||||
List<String> scenarioIds = new ArrayList<>();
|
List<String> scenarioIds = new ArrayList<>();
|
||||||
Map<String,String> scenarioIdApiScarionMap = new HashMap<>();
|
Map<String,String> scenarioIdApiScarionMap = new HashMap<>();
|
||||||
for (TestPlanApiScenario apiScenario:
|
for (TestPlanApiScenario apiScenario: testPlanApiScenarioList) {
|
||||||
testPlanApiScenarioList) {
|
|
||||||
scenarioIds.add(apiScenario.getApiScenarioId());
|
scenarioIds.add(apiScenario.getApiScenarioId());
|
||||||
scenarioIdApiScarionMap.put(apiScenario.getApiScenarioId(),apiScenario.getId());
|
scenarioIdApiScarionMap.put(apiScenario.getApiScenarioId(),apiScenario.getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -932,7 +932,7 @@ public class TestPlanService {
|
||||||
APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(),
|
APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(),
|
||||||
planScenarioID + ":" + request.getTestPlanReportId(),
|
planScenarioID + ":" + request.getTestPlanReportId(),
|
||||||
item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
request.getExecuteType(), item.getProjectId(), request.getReportUserID(),null);
|
||||||
group.setHashTree(scenarios);
|
group.setHashTree(scenarios);
|
||||||
testPlan.getHashTree().add(group);
|
testPlan.getHashTree().add(group);
|
||||||
apiScenarioReportMapper.insert(report);
|
apiScenarioReportMapper.insert(report);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -486,7 +486,6 @@ export default {
|
||||||
this.rowLoading = row.id;
|
this.rowLoading = row.id;
|
||||||
|
|
||||||
this.$get('/api/testcase/get/' + row.caseId, (response) => {
|
this.$get('/api/testcase/get/' + row.caseId, (response) => {
|
||||||
console.log(response.data)
|
|
||||||
let apiCase = response.data;
|
let apiCase = response.data;
|
||||||
let request = JSON.parse(apiCase.request);
|
let request = JSON.parse(apiCase.request);
|
||||||
request.name = row.id;
|
request.name = row.id;
|
||||||
|
@ -512,7 +511,7 @@ export default {
|
||||||
request.name = row.id;
|
request.name = row.id;
|
||||||
request.id = row.id;
|
request.id = row.id;
|
||||||
request.useEnvironment = row.environmentId;
|
request.useEnvironment = row.environmentId;
|
||||||
this.runData.push(request);
|
this.runData.unshift(request);
|
||||||
if (this.selectRows.size === index) {
|
if (this.selectRows.size === index) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,8 +309,6 @@ export default {
|
||||||
this.selectRows.forEach(row => {
|
this.selectRows.forEach(row => {
|
||||||
this.buildExecuteParam(param,row);
|
this.buildExecuteParam(param,row);
|
||||||
});
|
});
|
||||||
console.log(param)
|
|
||||||
|
|
||||||
this.$post("/test/plan/scenario/case/run", param, response => {});
|
this.$post("/test/plan/scenario/case/run", param, response => {});
|
||||||
}
|
}
|
||||||
this.$message('任务执行中,请稍后刷新查看结果');
|
this.$message('任务执行中,请稍后刷新查看结果');
|
||||||
|
|
Loading…
Reference in New Issue