parent
cf39bb066d
commit
51a172385a
|
@ -2,22 +2,20 @@ package io.metersphere.track.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.base.domain.TestCaseReport;
|
|
||||||
import io.metersphere.base.domain.TestPlanReport;
|
import io.metersphere.base.domain.TestPlanReport;
|
||||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.track.dto.TestCaseReportMetricDTO;
|
|
||||||
import io.metersphere.track.dto.TestPlanDTOWithMetric;
|
|
||||||
import io.metersphere.track.dto.TestPlanReportDTO;
|
import io.metersphere.track.dto.TestPlanReportDTO;
|
||||||
import io.metersphere.track.request.report.QueryTestPlanReportRequest;
|
import io.metersphere.track.request.report.QueryTestPlanReportRequest;
|
||||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
import io.metersphere.track.request.report.TestPlanReportSaveRequest;
|
||||||
import io.metersphere.track.service.TestPlanReportService;
|
import io.metersphere.track.service.TestPlanReportService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author song.tianyang
|
* @author song.tianyang
|
||||||
|
@ -62,14 +60,18 @@ public class TestPlanReportController {
|
||||||
|
|
||||||
@GetMapping("/apiExecuteFinish/{planId}/{userId}")
|
@GetMapping("/apiExecuteFinish/{planId}/{userId}")
|
||||||
public void apiExecuteFinish(@PathVariable String planId,@PathVariable String userId) {
|
public void apiExecuteFinish(@PathVariable String planId,@PathVariable String userId) {
|
||||||
TestPlanReport report = testPlanReportService.genTestPlanReport(planId,userId,ReportTriggerMode.API.name());
|
String reportId = UUID.randomUUID().toString();
|
||||||
|
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,ReportTriggerMode.API.name());
|
||||||
|
TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest);
|
||||||
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name());
|
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/saveTestPlanReport/{planId}/{triggerMode}")
|
@GetMapping("/saveTestPlanReport/{planId}/{triggerMode}")
|
||||||
public String saveTestPlanReport(@PathVariable String planId,@PathVariable String triggerMode) {
|
public String saveTestPlanReport(@PathVariable String planId,@PathVariable String triggerMode) {
|
||||||
String userId = SessionUtils.getUser().getId();
|
String userId = SessionUtils.getUser().getId();
|
||||||
TestPlanReport report = testPlanReportService.genTestPlanReport(planId,userId,triggerMode);
|
String reportId = UUID.randomUUID().toString();
|
||||||
|
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,triggerMode);
|
||||||
|
TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest);
|
||||||
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode);
|
testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode);
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@ package io.metersphere.track.service;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
|
||||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
|
||||||
import io.metersphere.api.jmeter.TestResult;
|
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
import io.metersphere.base.mapper.ext.ExtTestPlanApiCaseMapper;
|
||||||
|
@ -21,15 +18,14 @@ import io.metersphere.track.Factory.ReportComponentFactory;
|
||||||
import io.metersphere.track.domain.ReportComponent;
|
import io.metersphere.track.domain.ReportComponent;
|
||||||
import io.metersphere.track.dto.*;
|
import io.metersphere.track.dto.*;
|
||||||
import io.metersphere.track.request.report.QueryTestPlanReportRequest;
|
import io.metersphere.track.request.report.QueryTestPlanReportRequest;
|
||||||
|
import io.metersphere.track.request.report.TestPlanReportSaveRequest;
|
||||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.python.bouncycastle.pqc.math.linearalgebra.IntUtils;
|
|
||||||
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.lang.reflect.Array;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -80,36 +76,25 @@ public class TestPlanReportService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成测试计划
|
* @param reportId 报告ID(外部传入)
|
||||||
* @param planId
|
* @param planId 测试计划ID
|
||||||
* @param userId
|
* @param userId 用户ID
|
||||||
* @param triggerMode
|
* @param triggerMode 执行方式
|
||||||
|
* @param countResources 是否统计资源-false的话, 下面三个不同资源是否运行则由参数决定。 true的话则由统计后的结果决定
|
||||||
|
* @param apiCaseIsExecuting 接口案例是否执行中
|
||||||
|
* @param scenarioIsExecuting 场景案例是否执行中
|
||||||
|
* @param performanceIsExecuting 性能案例是否执行中
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TestPlanReport genTestPlanReport(String planId, String userId,String triggerMode) {
|
public TestPlanReport genTestPlanReport(TestPlanReportSaveRequest saveRequest) {
|
||||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(saveRequest.getPlanId());
|
||||||
testPlan.setExecutionTimes(1);
|
testPlan.setExecutionTimes(1);
|
||||||
testPlan.setExecutionTimes(testPlan.getExecutionTimes() + 1);
|
testPlan.setExecutionTimes(testPlan.getExecutionTimes() + 1);
|
||||||
testPlanMapper.updateByPrimaryKey(testPlan);
|
testPlanMapper.updateByPrimaryKey(testPlan);
|
||||||
TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample();
|
|
||||||
apiExample.createCriteria().andTestPlanIdEqualTo(planId);
|
|
||||||
List<String> apiCaseIdList = testPlanApiCaseMapper.selectByExample(apiExample)
|
|
||||||
.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
String testPlanReportID = saveRequest.getReportID();
|
||||||
example.createCriteria().andTestPlanIdEqualTo(planId);
|
|
||||||
List<String> scenarioIdList = testPlanScenarioCaseMapper.selectByExample(example)
|
|
||||||
.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
LoadCaseRequest loadCaseRequest = new LoadCaseRequest();
|
|
||||||
loadCaseRequest.setTestPlanId(planId);
|
|
||||||
loadCaseRequest.setProjectId(testPlan.getProjectId());
|
|
||||||
List<String> performanceIdList = testPlanLoadCaseService.list(loadCaseRequest)
|
|
||||||
.stream().map(TestPlanLoadCaseDTO::getLoadCaseId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
String testPlanReportID = UUID.randomUUID().toString();
|
|
||||||
TestPlanReport testPlanReport = new TestPlanReport();
|
TestPlanReport testPlanReport = new TestPlanReport();
|
||||||
testPlanReport.setTestPlanId(planId);
|
testPlanReport.setTestPlanId(saveRequest.getPlanId());
|
||||||
testPlanReport.setId(testPlanReportID);
|
testPlanReport.setId(testPlanReportID);
|
||||||
testPlanReport.setCreateTime(System.currentTimeMillis());
|
testPlanReport.setCreateTime(System.currentTimeMillis());
|
||||||
testPlanReport.setUpdateTime(System.currentTimeMillis());
|
testPlanReport.setUpdateTime(System.currentTimeMillis());
|
||||||
|
@ -117,41 +102,68 @@ public class TestPlanReportService {
|
||||||
testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date()));
|
testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
testPlanReport.setTriggerMode(triggerMode);
|
testPlanReport.setTriggerMode(saveRequest.getTriggerMode());
|
||||||
testPlanReport.setCreator(userId);
|
testPlanReport.setCreator(saveRequest.getUserId());
|
||||||
testPlanReport.setStartTime(System.currentTimeMillis());
|
testPlanReport.setStartTime(System.currentTimeMillis());
|
||||||
testPlanReport.setEndTime(System.currentTimeMillis());
|
testPlanReport.setEndTime(System.currentTimeMillis());
|
||||||
if (apiCaseIdList.isEmpty()) {
|
|
||||||
testPlanReport.setIsApiCaseExecuting(false);
|
|
||||||
} else {
|
|
||||||
testPlanReport.setIsApiCaseExecuting(true);
|
|
||||||
}
|
|
||||||
if (scenarioIdList.isEmpty()) {
|
|
||||||
testPlanReport.setIsScenarioExecuting(false);
|
|
||||||
} else {
|
|
||||||
testPlanReport.setIsScenarioExecuting(true);
|
|
||||||
}
|
|
||||||
if (performanceIdList.isEmpty()) {
|
|
||||||
testPlanReport.setIsPerformanceExecuting(false);
|
|
||||||
} else {
|
|
||||||
testPlanReport.setIsPerformanceExecuting(true);
|
|
||||||
}
|
|
||||||
testPlanReport.setPrincipal(testPlan.getPrincipal());
|
|
||||||
|
|
||||||
if(testPlanReport.getIsScenarioExecuting() || testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting()){
|
|
||||||
testPlanReport.setStatus(APITestStatus.Starting.name());
|
|
||||||
}else {
|
|
||||||
testPlanReport.setStatus(APITestStatus.Completed.name());
|
|
||||||
}
|
|
||||||
testPlanReportMapper.insert(testPlanReport);
|
|
||||||
|
|
||||||
TestPlanReportDataWithBLOBs testPlanReportData = new TestPlanReportDataWithBLOBs();
|
TestPlanReportDataWithBLOBs testPlanReportData = new TestPlanReportDataWithBLOBs();
|
||||||
testPlanReportData.setId(UUID.randomUUID().toString());
|
testPlanReportData.setId(UUID.randomUUID().toString());
|
||||||
testPlanReportData.setTestPlanReportId(testPlanReportID);
|
testPlanReportData.setTestPlanReportId(testPlanReportID);
|
||||||
|
|
||||||
testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseIdList));
|
if (saveRequest.isCountResources()) {
|
||||||
testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioIdList));
|
TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample();
|
||||||
testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceIdList));
|
apiExample.createCriteria().andTestPlanIdEqualTo(saveRequest.getPlanId());
|
||||||
|
List<String> apiCaseIdList = testPlanApiCaseMapper.selectByExample(apiExample)
|
||||||
|
.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
||||||
|
if (apiCaseIdList.isEmpty()) {
|
||||||
|
testPlanReport.setIsApiCaseExecuting(false);
|
||||||
|
} else {
|
||||||
|
testPlanReport.setIsApiCaseExecuting(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||||
|
example.createCriteria().andTestPlanIdEqualTo(saveRequest.getPlanId());
|
||||||
|
List<String> scenarioIdList = testPlanScenarioCaseMapper.selectByExample(example)
|
||||||
|
.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
|
||||||
|
if (scenarioIdList.isEmpty()) {
|
||||||
|
testPlanReport.setIsScenarioExecuting(false);
|
||||||
|
} else {
|
||||||
|
testPlanReport.setIsScenarioExecuting(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadCaseRequest loadCaseRequest = new LoadCaseRequest();
|
||||||
|
loadCaseRequest.setTestPlanId(saveRequest.getPlanId());
|
||||||
|
loadCaseRequest.setProjectId(testPlan.getProjectId());
|
||||||
|
List<String> performanceIdList = testPlanLoadCaseService.list(loadCaseRequest)
|
||||||
|
.stream().map(TestPlanLoadCaseDTO::getLoadCaseId).collect(Collectors.toList());
|
||||||
|
if (performanceIdList.isEmpty()) {
|
||||||
|
testPlanReport.setIsPerformanceExecuting(false);
|
||||||
|
} else {
|
||||||
|
testPlanReport.setIsPerformanceExecuting(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseIdList));
|
||||||
|
testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioIdList));
|
||||||
|
testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceIdList));
|
||||||
|
} else {
|
||||||
|
testPlanReport.setIsApiCaseExecuting(saveRequest.isApiCaseIsExecuting());
|
||||||
|
testPlanReport.setIsScenarioExecuting(saveRequest.isScenarioIsExecuting());
|
||||||
|
testPlanReport.setIsPerformanceExecuting(saveRequest.isPerformanceIsExecuting());
|
||||||
|
|
||||||
|
testPlanReportData.setApiCaseInfo(saveRequest.getApiCaseIdListJSON());
|
||||||
|
testPlanReportData.setScenarioInfo(saveRequest.getScenarioIdListJSON());
|
||||||
|
testPlanReportData.setPerformanceInfo(saveRequest.getPerformanceIdListJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
testPlanReport.setPrincipal(testPlan.getPrincipal());
|
||||||
|
if (testPlanReport.getIsScenarioExecuting() || testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting()) {
|
||||||
|
testPlanReport.setStatus(APITestStatus.Starting.name());
|
||||||
|
} else {
|
||||||
|
testPlanReport.setStatus(APITestStatus.Completed.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
testPlanReportMapper.insert(testPlanReport);
|
||||||
testPlanReportDataMapper.insert(testPlanReportData);
|
testPlanReportDataMapper.insert(testPlanReportData);
|
||||||
|
|
||||||
//更新TestPlan状态,改为进行中
|
//更新TestPlan状态,改为进行中
|
||||||
|
@ -203,9 +215,9 @@ public class TestPlanReportService {
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateReport(List<String> testPlanReportIdList, String runMode,String triggerMode) {
|
public synchronized void updateReport(List<String> testPlanReportIdList, String runMode, String triggerMode) {
|
||||||
for (String planReportId : testPlanReportIdList) {
|
for (String planReportId : testPlanReportIdList) {
|
||||||
this.countReportByTestPlanReportId(planReportId,runMode,triggerMode);
|
this.countReportByTestPlanReportId(planReportId, runMode, triggerMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,12 +231,11 @@ public class TestPlanReportService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param planReportId 测试计划报告ID
|
||||||
* @param planReportId 测试计划报告ID
|
* @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null
|
||||||
* @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null
|
* @param triggerMode 触发方式 ReportTriggerMode.enum
|
||||||
* @param triggerMode 触发方式 ReportTriggerMode.enum
|
|
||||||
*/
|
*/
|
||||||
public void countReportByTestPlanReportId(String planReportId,String resourceRunMode,String triggerMode) {
|
public void countReportByTestPlanReportId(String planReportId, String resourceRunMode, String triggerMode) {
|
||||||
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId);
|
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId);
|
||||||
|
|
||||||
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
|
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
|
||||||
|
@ -233,26 +244,26 @@ public class TestPlanReportService {
|
||||||
String issuesInfo = null;
|
String issuesInfo = null;
|
||||||
|
|
||||||
//因为接口案例的定时任务是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理
|
//因为接口案例的定时任务是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理
|
||||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||||
&&StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
&& StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||||
List<String> statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId());
|
List<String> statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId());
|
||||||
for (String status : statusList) {
|
for (String status : statusList) {
|
||||||
if (status == null) {
|
if (status == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(),triggerMode)){
|
} else if (StringUtils.equals(ReportTriggerMode.TEST_PLAN_SCHEDULE.name(), triggerMode)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
testPlanReport.setEndTime(System.currentTimeMillis());
|
testPlanReport.setEndTime(System.currentTimeMillis());
|
||||||
testPlanReport.setUpdateTime(System.currentTimeMillis());
|
testPlanReport.setUpdateTime(System.currentTimeMillis());
|
||||||
|
|
||||||
//手动触发的需要保存手工执行的信息
|
//手动触发的需要保存手工执行的信息
|
||||||
int [] componentIndexArr = null;
|
int[] componentIndexArr = null;
|
||||||
if(StringUtils.equals(ReportTriggerMode.MANUAL.name(),triggerMode)){
|
if (StringUtils.equals(ReportTriggerMode.MANUAL.name(), triggerMode)) {
|
||||||
componentIndexArr = new int[]{1,2,3,4,5};
|
componentIndexArr = new int[]{1, 2, 3, 4, 5};
|
||||||
}else {
|
} else {
|
||||||
componentIndexArr = new int[]{1,3,4};
|
componentIndexArr = new int[]{1, 3, 4};
|
||||||
}
|
}
|
||||||
testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr));
|
testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr));
|
||||||
|
|
||||||
|
@ -263,23 +274,23 @@ public class TestPlanReportService {
|
||||||
testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components);
|
testPlanService.buildScenarioCaseReport(testPlanReport.getTestPlanId(), components);
|
||||||
testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components);
|
testPlanService.buildLoadCaseReport(testPlanReport.getTestPlanId(), components);
|
||||||
|
|
||||||
if(StringUtils.equals(ReportTriggerMode.MANUAL.name(),triggerMode)){
|
if (StringUtils.equals(ReportTriggerMode.MANUAL.name(), triggerMode)) {
|
||||||
List<Issues> issues = testPlanService.buildFunctionalCaseReport(testPlanReport.getTestPlanId(), components);
|
List<Issues> issues = testPlanService.buildFunctionalCaseReport(testPlanReport.getTestPlanId(), components);
|
||||||
issuesInfo = JSONArray.toJSONString(issues);
|
issuesInfo = JSONArray.toJSONString(issues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//只针对定时任务做处理
|
//只针对定时任务做处理
|
||||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||||
testPlanReport.setIsApiCaseExecuting(false);
|
testPlanReport.setIsApiCaseExecuting(false);
|
||||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||||
testPlanReport.setIsScenarioExecuting(false);
|
testPlanReport.setIsScenarioExecuting(false);
|
||||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||||
testPlanReport.setIsPerformanceExecuting(false);
|
testPlanReport.setIsPerformanceExecuting(false);
|
||||||
}else {
|
} else {
|
||||||
testPlanReport.setIsPerformanceExecuting(false);
|
testPlanReport.setIsPerformanceExecuting(false);
|
||||||
testPlanReport.setIsScenarioExecuting(false);
|
testPlanReport.setIsScenarioExecuting(false);
|
||||||
testPlanReport.setIsApiCaseExecuting(false);
|
testPlanReport.setIsApiCaseExecuting(false);
|
||||||
|
@ -289,12 +300,12 @@ public class TestPlanReportService {
|
||||||
component.afterBuild(testCaseReportMetricDTO);
|
component.afterBuild(testCaseReportMetricDTO);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||||
//如果是性能测试作为触发,由于延迟原因可能会出现报告已经结束但是状态还是进行中的状态
|
//如果是性能测试作为触发,由于延迟原因可能会出现报告已经结束但是状态还是进行中的状态
|
||||||
List<TestCaseReportStatusResultDTO> loadResult = testCaseReportMetricDTO.getExecuteResult().getLoadResult();
|
List<TestCaseReportStatusResultDTO> loadResult = testCaseReportMetricDTO.getExecuteResult().getLoadResult();
|
||||||
for (TestCaseReportStatusResultDTO dto: loadResult) {
|
for (TestCaseReportStatusResultDTO dto : loadResult) {
|
||||||
if(StringUtils.equals(dto.getStatus(),TestPlanTestCaseStatus.Underway.name())){
|
if (StringUtils.equals(dto.getStatus(), TestPlanTestCaseStatus.Underway.name())) {
|
||||||
dto.setStatus(TestPlanTestCaseStatus.Pass.name());
|
dto.setStatus(TestPlanTestCaseStatus.Pass.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,49 +322,50 @@ public class TestPlanReportService {
|
||||||
testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult()));
|
testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult()));
|
||||||
testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases()));
|
testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases()));
|
||||||
testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult()));
|
testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult()));
|
||||||
if(issuesInfo!=null){
|
if (issuesInfo != null) {
|
||||||
testPlanReportData.setIssuesInfo(issuesInfo);
|
testPlanReportData.setIssuesInfo(issuesInfo);
|
||||||
}
|
}
|
||||||
testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(testPlanReportData);
|
testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(testPlanReportData);
|
||||||
}
|
}
|
||||||
|
|
||||||
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport,testPlanReportData);
|
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport, testPlanReportData);
|
||||||
testPlanReport.setStatus(testPlanStatus);
|
testPlanReport.setStatus(testPlanStatus);
|
||||||
this.update(testPlanReport);
|
this.update(testPlanReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算测试计划的状态
|
* 计算测试计划的状态
|
||||||
|
*
|
||||||
* @param testPlanReport
|
* @param testPlanReport
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getTestPlanReportStatus(TestPlanReport testPlanReport, TestPlanReportDataWithBLOBs testPlanReportData) {
|
private String getTestPlanReportStatus(TestPlanReport testPlanReport, TestPlanReportDataWithBLOBs testPlanReportData) {
|
||||||
String status = TestPlanReportStatus.COMPLETED.name();
|
String status = TestPlanReportStatus.COMPLETED.name();
|
||||||
if(testPlanReport!=null){
|
if (testPlanReport != null) {
|
||||||
if(testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting() || testPlanReport.getIsScenarioExecuting()){
|
if (testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting() || testPlanReport.getIsScenarioExecuting()) {
|
||||||
status = TestPlanReportStatus.RUNNING.name();
|
status = TestPlanReportStatus.RUNNING.name();
|
||||||
}else {
|
} else {
|
||||||
if(testPlanReportData == null){
|
if (testPlanReportData == null) {
|
||||||
String failCaseString = testPlanReportData.getFailurTestCases();
|
String failCaseString = testPlanReportData.getFailurTestCases();
|
||||||
status = TestPlanReportStatus.SUCCESS.name();
|
status = TestPlanReportStatus.SUCCESS.name();
|
||||||
try {
|
try {
|
||||||
JSONObject failurCaseObject = JSONObject.parseObject(failCaseString);
|
JSONObject failurCaseObject = JSONObject.parseObject(failCaseString);
|
||||||
if(failurCaseObject.containsKey("apiTestCases")&&failurCaseObject.getJSONArray("apiTestCases").size()>=0){
|
if (failurCaseObject.containsKey("apiTestCases") && failurCaseObject.getJSONArray("apiTestCases").size() >= 0) {
|
||||||
status = TestPlanReportStatus.FAILED.name();
|
status = TestPlanReportStatus.FAILED.name();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
if(failurCaseObject.containsKey("loadTestCases")&&failurCaseObject.getJSONArray("loadTestCases").size()>=0){
|
if (failurCaseObject.containsKey("loadTestCases") && failurCaseObject.getJSONArray("loadTestCases").size() >= 0) {
|
||||||
status = TestPlanReportStatus.FAILED.name();
|
status = TestPlanReportStatus.FAILED.name();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
if(failurCaseObject.containsKey("scenarioTestCases")&&failurCaseObject.getJSONArray("scenarioTestCases").size()>=0){
|
if (failurCaseObject.containsKey("scenarioTestCases") && failurCaseObject.getJSONArray("scenarioTestCases").size() >= 0) {
|
||||||
status = TestPlanReportStatus.FAILED.name();
|
status = TestPlanReportStatus.FAILED.name();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
status = TestPlanReportStatus.FAILED.name();
|
status = TestPlanReportStatus.FAILED.name();
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
status = TestPlanReportStatus.COMPLETED.name();
|
status = TestPlanReportStatus.COMPLETED.name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +383,7 @@ public class TestPlanReportService {
|
||||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.equalsAny(report.getTriggerMode(),ReportTriggerMode.SCHEDULE.name())){
|
if (StringUtils.equalsAny(report.getTriggerMode(), ReportTriggerMode.SCHEDULE.name())) {
|
||||||
//发送通知
|
//发送通知
|
||||||
sendMessage(report);
|
sendMessage(report);
|
||||||
}
|
}
|
||||||
|
@ -379,7 +391,7 @@ public class TestPlanReportService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
}
|
}
|
||||||
testPlanReportMapper.updateByPrimaryKey(report);
|
testPlanReportMapper.updateByPrimaryKey(report);
|
||||||
}
|
}
|
||||||
|
@ -417,7 +429,7 @@ public class TestPlanReportService {
|
||||||
String successfulMailTemplate = "";
|
String successfulMailTemplate = "";
|
||||||
String errfoMailTemplate = "";
|
String errfoMailTemplate = "";
|
||||||
|
|
||||||
if(StringUtils.equals(testPlanReport.getTriggerMode(),ReportTriggerMode.SCHEDULE.name())){
|
if (StringUtils.equals(testPlanReport.getTriggerMode(), ReportTriggerMode.SCHEDULE.name())) {
|
||||||
successfulMailTemplate = "TestPlanSuccessfulNotification";
|
successfulMailTemplate = "TestPlanSuccessfulNotification";
|
||||||
errfoMailTemplate = "TestPlanFailedNotification";
|
errfoMailTemplate = "TestPlanFailedNotification";
|
||||||
}
|
}
|
||||||
|
@ -446,7 +458,7 @@ public class TestPlanReportService {
|
||||||
* @param testPlanReport
|
* @param testPlanReport
|
||||||
* @param performaneReportIDList
|
* @param performaneReportIDList
|
||||||
*/
|
*/
|
||||||
public void updatePerformanceInfo(TestPlanReport testPlanReport, List<String> performaneReportIDList,String triggerMode) {
|
public void updatePerformanceInfo(TestPlanReport testPlanReport, List<String> performaneReportIDList, String triggerMode) {
|
||||||
TestPlanReportDataExample example = new TestPlanReportDataExample();
|
TestPlanReportDataExample example = new TestPlanReportDataExample();
|
||||||
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId());
|
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId());
|
||||||
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
|
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
|
||||||
|
@ -462,36 +474,36 @@ public class TestPlanReportService {
|
||||||
List<String> updatePerformaneReportIDList = new ArrayList<>(performaneReportIDList);
|
List<String> updatePerformaneReportIDList = new ArrayList<>(performaneReportIDList);
|
||||||
executorService.submit(() -> {
|
executorService.submit(() -> {
|
||||||
//错误数据检查集合。 如果错误数据出现超过20次,则取消该条数据的检查
|
//错误数据检查集合。 如果错误数据出现超过20次,则取消该条数据的检查
|
||||||
Map<String,Integer> errorDataCheckMap = new HashMap<>();
|
Map<String, Integer> errorDataCheckMap = new HashMap<>();
|
||||||
while (performaneReportIDList.size()>0) {
|
while (performaneReportIDList.size() > 0) {
|
||||||
List<String> selectList = new ArrayList<>(performaneReportIDList);
|
List<String> selectList = new ArrayList<>(performaneReportIDList);
|
||||||
for (String loadTestReportId:selectList) {
|
for (String loadTestReportId : selectList) {
|
||||||
LoadTestReportWithBLOBs loadTestReportFromDatabase = loadTestReportMapper.selectByPrimaryKey(loadTestReportId);
|
LoadTestReportWithBLOBs loadTestReportFromDatabase = loadTestReportMapper.selectByPrimaryKey(loadTestReportId);
|
||||||
if(loadTestReportFromDatabase == null){
|
if (loadTestReportFromDatabase == null) {
|
||||||
//检查错误数据
|
//检查错误数据
|
||||||
if(errorDataCheckMap.containsKey(loadTestReportId)){
|
if (errorDataCheckMap.containsKey(loadTestReportId)) {
|
||||||
if(errorDataCheckMap.get(loadTestReportId)>10){
|
if (errorDataCheckMap.get(loadTestReportId) > 10) {
|
||||||
performaneReportIDList.remove(loadTestReportId);
|
performaneReportIDList.remove(loadTestReportId);
|
||||||
}else {
|
} else {
|
||||||
errorDataCheckMap.put(loadTestReportId,errorDataCheckMap.get(loadTestReportId)+1);
|
errorDataCheckMap.put(loadTestReportId, errorDataCheckMap.get(loadTestReportId) + 1);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
errorDataCheckMap.put(loadTestReportId,1);
|
errorDataCheckMap.put(loadTestReportId, 1);
|
||||||
}
|
}
|
||||||
}else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(),
|
} else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(),
|
||||||
PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
|
PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
|
||||||
performaneReportIDList.remove(loadTestReportId);
|
performaneReportIDList.remove(loadTestReportId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(performaneReportIDList.isEmpty()){
|
if (performaneReportIDList.isEmpty()) {
|
||||||
for (String string: updatePerformaneReportIDList) {
|
for (String string : updatePerformaneReportIDList) {
|
||||||
TestPlanLoadCaseEventDTO eventDTO = new TestPlanLoadCaseEventDTO();
|
TestPlanLoadCaseEventDTO eventDTO = new TestPlanLoadCaseEventDTO();
|
||||||
eventDTO.setReportId(string);
|
eventDTO.setReportId(string);
|
||||||
eventDTO.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
eventDTO.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
||||||
eventDTO.setStatus(PerformanceTestStatus.Completed.name());
|
eventDTO.setStatus(PerformanceTestStatus.Completed.name());
|
||||||
this.updatePerformanceTestStatus(eventDTO);
|
this.updatePerformanceTestStatus(eventDTO);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
try {
|
try {
|
||||||
//查询定时任务是否关闭
|
//查询定时任务是否关闭
|
||||||
Thread.sleep(1000 * 10);// 检查 loadtest 的状态
|
Thread.sleep(1000 * 10);// 检查 loadtest 的状态
|
||||||
|
@ -505,7 +517,7 @@ public class TestPlanReportService {
|
||||||
|
|
||||||
public void updatePerformanceTestStatus(TestPlanLoadCaseEventDTO eventDTO) {
|
public void updatePerformanceTestStatus(TestPlanLoadCaseEventDTO eventDTO) {
|
||||||
List<String> testPlanReportId = extTestPlanMapper.findIdByPerformanceReportId(eventDTO.getReportId());
|
List<String> testPlanReportId = extTestPlanMapper.findIdByPerformanceReportId(eventDTO.getReportId());
|
||||||
this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(),eventDTO.getTriggerMode());
|
this.updateReport(testPlanReportId, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name(), eventDTO.getTriggerMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(List<String> testPlanReportIdList) {
|
public void delete(List<String> testPlanReportIdList) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import io.metersphere.service.SystemParameterService;
|
||||||
import io.metersphere.track.Factory.ReportComponentFactory;
|
import io.metersphere.track.Factory.ReportComponentFactory;
|
||||||
import io.metersphere.track.domain.ReportComponent;
|
import io.metersphere.track.domain.ReportComponent;
|
||||||
import io.metersphere.track.dto.*;
|
import io.metersphere.track.dto.*;
|
||||||
|
import io.metersphere.track.request.report.TestPlanReportSaveRequest;
|
||||||
import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest;
|
import io.metersphere.track.request.testcase.PlanCaseRelevanceRequest;
|
||||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||||
import io.metersphere.track.request.testplan.AddTestPlanRequest;
|
import io.metersphere.track.request.testplan.AddTestPlanRequest;
|
||||||
|
@ -128,6 +129,8 @@ public class TestPlanService {
|
||||||
private ApiScenarioMapper apiScenarioMapper;
|
private ApiScenarioMapper apiScenarioMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestCaseTestMapper testCaseTestMapper;
|
private TestCaseTestMapper testCaseTestMapper;
|
||||||
|
@Resource
|
||||||
|
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||||
|
|
||||||
public synchronized String addTestPlan(AddTestPlanRequest testPlan) {
|
public synchronized String addTestPlan(AddTestPlanRequest testPlan) {
|
||||||
if (getTestPlanByName(testPlan.getName()).size() > 0) {
|
if (getTestPlanByName(testPlan.getName()).size() > 0) {
|
||||||
|
@ -863,12 +866,13 @@ public class TestPlanService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String runScenarioCase(SchedulePlanScenarioExecuteRequest request) {
|
public String runScenarioCase(SchedulePlanScenarioExecuteRequest request) {
|
||||||
|
String returnId = "";
|
||||||
MsTestPlan testPlan = new MsTestPlan();
|
MsTestPlan testPlan = new MsTestPlan();
|
||||||
testPlan.setHashTree(new LinkedList<>());
|
testPlan.setHashTree(new LinkedList<>());
|
||||||
HashTree jmeterHashTree = new ListedHashTree();
|
HashTree jmeterHashTree = new ListedHashTree();
|
||||||
Map<String, Map<String, String>> testPlanScenarioIdMap = request.getTestPlanScenarioIDMap();
|
Map<String, Map<String, String>> testPlanScenarioIdMap = request.getTestPlanScenarioIDMap();
|
||||||
|
|
||||||
for (Map.Entry<String, Map<String, String>> entry : testPlanScenarioIdMap.entrySet()) {
|
for (Map.Entry<String, Map<String, String>> entry : testPlanScenarioIdMap.entrySet()) {
|
||||||
String testPlanID = entry.getKey();
|
|
||||||
Map<String, String> planScenarioIdMap = entry.getValue();
|
Map<String, String> planScenarioIdMap = entry.getValue();
|
||||||
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(new ArrayList<>(planScenarioIdMap.keySet()));
|
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(new ArrayList<>(planScenarioIdMap.keySet()));
|
||||||
try {
|
try {
|
||||||
|
@ -918,23 +922,27 @@ public class TestPlanService {
|
||||||
scenarios.add(scenario);
|
scenarios.add(scenario);
|
||||||
// 创建场景报告
|
// 创建场景报告
|
||||||
//不同的运行模式,第二个参数入参不同
|
//不同的运行模式,第二个参数入参不同
|
||||||
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());
|
||||||
group.setHashTree(scenarios);
|
group.setHashTree(scenarios);
|
||||||
testPlan.getHashTree().add(group);
|
testPlan.getHashTree().add(group);
|
||||||
|
apiScenarioReportMapper.insert(report);
|
||||||
|
returnId = request.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
MSException.throwException(ex.getMessage());
|
MSException.throwException(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
|
||||||
|
String runMode = ApiRunMode.SCHEDULE_SCENARIO_PLAN.name();
|
||||||
|
// 调用执行方法
|
||||||
|
jMeterService.runDefinition(request.getId(), jmeterHashTree, request.getReportId(), runMode);
|
||||||
}
|
}
|
||||||
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), new ParameterConfig());
|
|
||||||
String runMode = ApiRunMode.SCHEDULE_SCENARIO_PLAN.name();
|
return returnId;
|
||||||
// 调用执行方法
|
|
||||||
jMeterService.runDefinition(request.getId(), jmeterHashTree, request.getReportId(), runMode);
|
|
||||||
return request.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(String testPlanID, String projectID, String userId, String triggerMode) {
|
public void run(String testPlanID, String projectID, String userId, String triggerMode) {
|
||||||
|
@ -966,37 +974,21 @@ public class TestPlanService {
|
||||||
|
|
||||||
LogUtil.info("-------------- start testplan schedule ----------");
|
LogUtil.info("-------------- start testplan schedule ----------");
|
||||||
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class);
|
||||||
//首先创建testPlanReport,然后返回的ID重新赋值为resourceID,作为后续的参数
|
|
||||||
TestPlanReport testPlanReport = testPlanReportService.genTestPlanReport(testPlanID, userId, triggerMode);
|
|
||||||
//执行接口案例任务
|
|
||||||
for (Map.Entry<String, String> entry : apiTestCaseIdMap.entrySet()) {
|
|
||||||
String apiCaseID = entry.getKey();
|
|
||||||
String planCaseID = entry.getValue();
|
|
||||||
ApiTestCaseWithBLOBs blobs = apiTestCaseService.get(apiCaseID);
|
|
||||||
//需要更新这里来保证PlanCase的状态能正常更改
|
|
||||||
apiTestCaseService.run(blobs, UUID.randomUUID().toString(), testPlanReport.getId(), testPlanID, ApiRunMode.SCHEDULE_API_PLAN.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
//执行场景执行任务
|
boolean apiCaseIsExcuting = false;
|
||||||
if (!planScenarioIdMap.isEmpty()) {
|
boolean scenarioIsExcuting = false;
|
||||||
LogUtil.info("-------------- testplan schedule ---------- api case over -----------------");
|
boolean performaceIsExcuting = false;
|
||||||
SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest();
|
String apiCaseIdArray = "";
|
||||||
String senarionReportID = UUID.randomUUID().toString();
|
String scenarioCaseIdArray = "";
|
||||||
scenarioRequest.setId(senarionReportID);
|
String performanceCaseIdArray = "";
|
||||||
scenarioRequest.setReportId(senarionReportID);
|
String planReportId = UUID.randomUUID().toString();
|
||||||
scenarioRequest.setProjectId(projectID);
|
//创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数
|
||||||
scenarioRequest.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId,testPlanID,userId,triggerMode,
|
||||||
scenarioRequest.setExecuteType(ExecuteType.Saved.name());
|
apiTestCaseIdMap.size()>0,planScenarioIdMap.size()>0,performanceIdMap.size()>0,
|
||||||
Map<String, Map<String, String>> testPlanScenarioIdMap = new HashMap<>();
|
JSONArray.toJSONString(new ArrayList<>(apiTestCaseIdMap.keySet())),JSONArray.toJSONString(new ArrayList<>(planScenarioIdMap.keySet())),JSONArray.toJSONString(new ArrayList<>(performanceIdMap.values())));
|
||||||
testPlanScenarioIdMap.put(testPlanID, planScenarioIdMap);
|
|
||||||
scenarioRequest.setTestPlanScenarioIDMap(testPlanScenarioIdMap);
|
TestPlanReport testPlanReport = testPlanReportService.genTestPlanReport(saveRequest);
|
||||||
scenarioRequest.setReportUserID(userId);
|
|
||||||
scenarioRequest.setTestPlanID(testPlanID);
|
|
||||||
scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name());
|
|
||||||
scenarioRequest.setTestPlanReportId(testPlanReport.getId());
|
|
||||||
this.runScenarioCase(scenarioRequest);
|
|
||||||
LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------");
|
|
||||||
}
|
|
||||||
//执行性能测试任务
|
//执行性能测试任务
|
||||||
List<String> performaneReportIDList = new ArrayList<>();
|
List<String> performaneReportIDList = new ArrayList<>();
|
||||||
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
||||||
|
@ -1016,20 +1008,76 @@ public class TestPlanService {
|
||||||
testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId());
|
testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId());
|
||||||
testPlanLoadCase.setLoadReportId(reportId);
|
testPlanLoadCase.setLoadReportId(reportId);
|
||||||
testPlanLoadCaseService.update(testPlanLoadCase);
|
testPlanLoadCaseService.update(testPlanLoadCase);
|
||||||
|
|
||||||
|
//更新关联处的报告
|
||||||
|
TestPlanLoadCase loadCase = new TestPlanLoadCaseDTO();
|
||||||
|
loadCase.setId(id);
|
||||||
|
loadCase.setLoadReportId(reportId);
|
||||||
|
testPlanLoadCaseService.update(loadCase);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//更新关联处的报告
|
if(StringUtils.isEmpty(reportId)){
|
||||||
TestPlanLoadCase loadCase = new TestPlanLoadCaseDTO();
|
performaceIsExcuting = false;
|
||||||
loadCase.setId(id);
|
}
|
||||||
loadCase.setLoadReportId(reportId);
|
}
|
||||||
testPlanLoadCaseService.update(loadCase);
|
|
||||||
|
if(performaceIsExcuting){
|
||||||
|
performanceCaseIdArray= JSONArray.toJSONString(new ArrayList<>(performanceIdMap.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!performaneReportIDList.isEmpty()) {
|
if (!performaneReportIDList.isEmpty()) {
|
||||||
//性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行
|
//性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行
|
||||||
testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDList, ReportTriggerMode.SCHEDULE.name());
|
testPlanReportService.updatePerformanceInfo(testPlanReport, performaneReportIDList, ReportTriggerMode.SCHEDULE.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//执行接口案例任务
|
||||||
|
for (Map.Entry<String, String> entry : apiTestCaseIdMap.entrySet()) {
|
||||||
|
String apiCaseID = entry.getKey();
|
||||||
|
String planCaseID = entry.getValue();
|
||||||
|
ApiTestCaseWithBLOBs blobs = apiTestCaseService.get(apiCaseID);
|
||||||
|
//需要更新这里来保证PlanCase的状态能正常更改
|
||||||
|
apiTestCaseService.run(blobs, UUID.randomUUID().toString(), planReportId, testPlanID, ApiRunMode.SCHEDULE_API_PLAN.name());
|
||||||
|
apiCaseIsExcuting = true;
|
||||||
|
}
|
||||||
|
if(apiCaseIsExcuting){
|
||||||
|
apiCaseIdArray = JSONArray.toJSONString(new ArrayList<>(apiTestCaseIdMap.keySet()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//执行场景执行任务
|
||||||
|
if (!planScenarioIdMap.isEmpty()) {
|
||||||
|
LogUtil.info("-------------- testplan schedule ---------- api case over -----------------");
|
||||||
|
SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest();
|
||||||
|
String senarionReportID = UUID.randomUUID().toString();
|
||||||
|
scenarioRequest.setId(senarionReportID);
|
||||||
|
scenarioRequest.setReportId(senarionReportID);
|
||||||
|
scenarioRequest.setProjectId(projectID);
|
||||||
|
scenarioRequest.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
||||||
|
scenarioRequest.setExecuteType(ExecuteType.Saved.name());
|
||||||
|
Map<String, Map<String, String>> testPlanScenarioIdMap = new HashMap<>();
|
||||||
|
testPlanScenarioIdMap.put(testPlanID, planScenarioIdMap);
|
||||||
|
scenarioRequest.setTestPlanScenarioIDMap(testPlanScenarioIdMap);
|
||||||
|
scenarioRequest.setReportUserID(userId);
|
||||||
|
scenarioRequest.setTestPlanID(testPlanID);
|
||||||
|
scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name());
|
||||||
|
scenarioRequest.setTestPlanReportId(planReportId);
|
||||||
|
String scenarioReportID = this.runScenarioCase(scenarioRequest);
|
||||||
|
if(StringUtils.isNotEmpty(scenarioReportID)){
|
||||||
|
scenarioIsExcuting = true;
|
||||||
|
scenarioCaseIdArray= JSONArray.toJSONString(new ArrayList<>(planScenarioIdMap.keySet()));
|
||||||
|
}
|
||||||
|
LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果report参数和预期不对(某些原因执行失败),则更新report
|
||||||
|
if(saveRequest.isApiCaseIsExecuting() != apiCaseIsExcuting ||saveRequest.isScenarioIsExecuting()!=scenarioIsExcuting ||saveRequest.isPerformanceIsExecuting() != performaceIsExcuting){
|
||||||
|
testPlanReport.setIsApiCaseExecuting(apiCaseIsExcuting);
|
||||||
|
testPlanReport.setIsScenarioExecuting(scenarioIsExcuting);
|
||||||
|
testPlanReport.setIsPerformanceExecuting(performaceIsExcuting);
|
||||||
|
testPlanReportService.update(testPlanReport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue