Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8f4870dd84
|
@ -49,7 +49,7 @@ public class MsIfController extends MsTestElement {
|
|||
ifController.setName(this.getName());
|
||||
ifController.setProperty(TestElement.TEST_CLASS, IfController.class.getName());
|
||||
ifController.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("IfControllerPanel"));
|
||||
ifController.setCondition("true");
|
||||
ifController.setCondition(this.getCondition());
|
||||
ifController.setEvaluateAll(false);
|
||||
ifController.setUseExpression(true);
|
||||
return ifController;
|
||||
|
|
|
@ -254,6 +254,9 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
}
|
||||
|
||||
private static void sendTask(ApiTestReport report, String reportUrl, TestResult testResult) {
|
||||
if (report == null) {
|
||||
return;
|
||||
}
|
||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||
NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class);
|
||||
assert systemParameterService != null;
|
||||
|
|
|
@ -269,7 +269,7 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
private void deleteApiScenarioReport(List<String> scenarioIds) {
|
||||
if(scenarioIds == null || scenarioIds.isEmpty()){
|
||||
if (scenarioIds == null || scenarioIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
|
||||
|
@ -371,6 +371,9 @@ public class ApiAutomationService {
|
|||
|
||||
public APIScenarioReportResult createScenarioReport(String id, String scenarioId, String scenarioName, String triggerMode, String execType, String projectId, String userID) {
|
||||
APIScenarioReportResult report = new APIScenarioReportResult();
|
||||
if (triggerMode.equals(ApiRunMode.SCENARIO.name()) || triggerMode.equals(ApiRunMode.DEFINITION.name())) {
|
||||
triggerMode = ReportTriggerMode.MANUAL.name();
|
||||
}
|
||||
report.setId(id);
|
||||
report.setTestId(id);
|
||||
if (StringUtils.isNotEmpty(scenarioName)) {
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TestPlanController {
|
|||
@PostMapping("/edit")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public void editTestPlan(@RequestBody TestPlanDTO testPlanDTO) {
|
||||
testPlanService.editTestPlan(testPlanDTO);
|
||||
testPlanService.editTestPlan(testPlanDTO, true);
|
||||
}
|
||||
|
||||
@PostMapping("/edit/status/{planId}")
|
||||
|
|
|
@ -2,22 +2,20 @@ package io.metersphere.track.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.base.domain.TestCaseReport;
|
||||
import io.metersphere.base.domain.TestPlanReport;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
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.request.report.QueryTestPlanReportRequest;
|
||||
import io.metersphere.track.request.testcase.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.report.TestPlanReportSaveRequest;
|
||||
import io.metersphere.track.service.TestPlanReportService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
|
@ -62,14 +60,18 @@ public class TestPlanReportController {
|
|||
|
||||
@GetMapping("/apiExecuteFinish/{planId}/{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());
|
||||
}
|
||||
|
||||
@GetMapping("/saveTestPlanReport/{planId}/{triggerMode}")
|
||||
public String saveTestPlanReport(@PathVariable String planId,@PathVariable String triggerMode) {
|
||||
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);
|
||||
return "success";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package io.metersphere.track.request.report;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/1/8 4:36 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class TestPlanReportSaveRequest {
|
||||
private String reportID;
|
||||
private String planId;
|
||||
private String userId;
|
||||
private String triggerMode;
|
||||
|
||||
private boolean countResources;
|
||||
private boolean apiCaseIsExecuting;
|
||||
private boolean scenarioIsExecuting;
|
||||
private boolean performanceIsExecuting;
|
||||
|
||||
private String apiCaseIdListJSON;
|
||||
private String scenarioIdListJSON;
|
||||
private String performanceIdListJSON;
|
||||
|
||||
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode) {
|
||||
this.reportID = reportID;
|
||||
this.planId = planId;
|
||||
this.userId = userId;
|
||||
this.triggerMode = triggerMode;
|
||||
|
||||
this.countResources = true;
|
||||
}
|
||||
|
||||
public TestPlanReportSaveRequest(String reportID, String planId, String userId, String triggerMode, boolean apiCaseIsExecuting, boolean scenarioIsExecuting, boolean performanceIsExecuting, String apiCaseIdListJSON, String scenarioIdListJSON, String performanceIdListJSON) {
|
||||
this.reportID = reportID;
|
||||
this.planId = planId;
|
||||
this.userId = userId;
|
||||
this.triggerMode = triggerMode;
|
||||
|
||||
this.countResources = false;
|
||||
|
||||
this.apiCaseIsExecuting = apiCaseIsExecuting;
|
||||
this.scenarioIsExecuting = scenarioIsExecuting;
|
||||
this.performanceIsExecuting = performanceIsExecuting;
|
||||
|
||||
this.apiCaseIdListJSON = apiCaseIdListJSON;
|
||||
this.scenarioIdListJSON = scenarioIdListJSON;
|
||||
this.performanceIdListJSON = performanceIdListJSON;
|
||||
}
|
||||
}
|
|
@ -2,9 +2,6 @@ package io.metersphere.track.service;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
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.mapper.*;
|
||||
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.dto.*;
|
||||
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.testplan.LoadCaseRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.python.bouncycastle.pqc.math.linearalgebra.IntUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -80,36 +76,25 @@ public class TestPlanReportService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 生成测试计划
|
||||
* @param planId
|
||||
* @param userId
|
||||
* @param triggerMode
|
||||
* @param reportId 报告ID(外部传入)
|
||||
* @param planId 测试计划ID
|
||||
* @param userId 用户ID
|
||||
* @param triggerMode 执行方式
|
||||
* @param countResources 是否统计资源-false的话, 下面三个不同资源是否运行则由参数决定。 true的话则由统计后的结果决定
|
||||
* @param apiCaseIsExecuting 接口案例是否执行中
|
||||
* @param scenarioIsExecuting 场景案例是否执行中
|
||||
* @param performanceIsExecuting 性能案例是否执行中
|
||||
* @return
|
||||
*/
|
||||
public TestPlanReport genTestPlanReport(String planId, String userId,String triggerMode) {
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||
public TestPlanReport genTestPlanReport(TestPlanReportSaveRequest saveRequest) {
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(saveRequest.getPlanId());
|
||||
testPlan.setExecutionTimes(1);
|
||||
testPlan.setExecutionTimes(testPlan.getExecutionTimes() + 1);
|
||||
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();
|
||||
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();
|
||||
String testPlanReportID = saveRequest.getReportID();
|
||||
TestPlanReport testPlanReport = new TestPlanReport();
|
||||
testPlanReport.setTestPlanId(planId);
|
||||
testPlanReport.setTestPlanId(saveRequest.getPlanId());
|
||||
testPlanReport.setId(testPlanReportID);
|
||||
testPlanReport.setCreateTime(System.currentTimeMillis());
|
||||
testPlanReport.setUpdateTime(System.currentTimeMillis());
|
||||
|
@ -117,41 +102,68 @@ public class TestPlanReportService {
|
|||
testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date()));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
testPlanReport.setTriggerMode(triggerMode);
|
||||
testPlanReport.setCreator(userId);
|
||||
testPlanReport.setTriggerMode(saveRequest.getTriggerMode());
|
||||
testPlanReport.setCreator(saveRequest.getUserId());
|
||||
testPlanReport.setStartTime(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();
|
||||
testPlanReportData.setId(UUID.randomUUID().toString());
|
||||
testPlanReportData.setTestPlanReportId(testPlanReportID);
|
||||
|
||||
testPlanReportData.setApiCaseInfo(JSONArray.toJSONString(apiCaseIdList));
|
||||
testPlanReportData.setScenarioInfo(JSONArray.toJSONString(scenarioIdList));
|
||||
testPlanReportData.setPerformanceInfo(JSONArray.toJSONString(performanceIdList));
|
||||
if (saveRequest.isCountResources()) {
|
||||
TestPlanApiCaseExample apiExample = new TestPlanApiCaseExample();
|
||||
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);
|
||||
|
||||
//更新TestPlan状态,改为进行中
|
||||
|
@ -203,9 +215,9 @@ public class TestPlanReportService {
|
|||
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) {
|
||||
this.countReportByTestPlanReportId(planReportId,runMode,triggerMode);
|
||||
this.countReportByTestPlanReportId(planReportId, runMode, triggerMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,12 +231,11 @@ public class TestPlanReportService {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param planReportId 测试计划报告ID
|
||||
* @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null
|
||||
* @param triggerMode 触发方式 ReportTriggerMode.enum
|
||||
* @param planReportId 测试计划报告ID
|
||||
* @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null
|
||||
* @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);
|
||||
|
||||
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
|
||||
|
@ -233,26 +244,26 @@ public class TestPlanReportService {
|
|||
String issuesInfo = null;
|
||||
|
||||
//因为接口案例的定时任务是单个案例开线程运行, 所以要检查是否都执行完成。全部执行完成时才会进行统一整理
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
||||
&&StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||
&& StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
List<String> statusList = extTestPlanApiCaseMapper.getStatusByTestPlanId(testPlan.getId());
|
||||
for (String status : statusList) {
|
||||
if (status == null) {
|
||||
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.setUpdateTime(System.currentTimeMillis());
|
||||
|
||||
//手动触发的需要保存手工执行的信息
|
||||
int [] componentIndexArr = null;
|
||||
if(StringUtils.equals(ReportTriggerMode.MANUAL.name(),triggerMode)){
|
||||
componentIndexArr = new int[]{1,2,3,4,5};
|
||||
}else {
|
||||
componentIndexArr = new int[]{1,3,4};
|
||||
int[] componentIndexArr = null;
|
||||
if (StringUtils.equals(ReportTriggerMode.MANUAL.name(), triggerMode)) {
|
||||
componentIndexArr = new int[]{1, 2, 3, 4, 5};
|
||||
} else {
|
||||
componentIndexArr = new int[]{1, 3, 4};
|
||||
}
|
||||
testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr));
|
||||
|
||||
|
@ -263,23 +274,23 @@ public class TestPlanReportService {
|
|||
testPlanService.buildScenarioCaseReport(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);
|
||||
issuesInfo = JSONArray.toJSONString(issues);
|
||||
}
|
||||
|
||||
|
||||
//只针对定时任务做处理
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_API_PLAN.name())) {
|
||||
testPlanReport.setIsApiCaseExecuting(false);
|
||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name())) {
|
||||
testPlanReport.setIsScenarioExecuting(false);
|
||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||
} else if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||
testPlanReport.setIsPerformanceExecuting(false);
|
||||
}else {
|
||||
} else {
|
||||
testPlanReport.setIsPerformanceExecuting(false);
|
||||
testPlanReport.setIsScenarioExecuting(false);
|
||||
testPlanReport.setIsApiCaseExecuting(false);
|
||||
|
@ -289,12 +300,12 @@ public class TestPlanReportService {
|
|||
component.afterBuild(testCaseReportMetricDTO);
|
||||
});
|
||||
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(),triggerMode)
|
||||
&&StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), triggerMode)
|
||||
&& StringUtils.equals(resourceRunMode, ApiRunMode.SCHEDULE_PERFORMANCE_TEST.name())) {
|
||||
//如果是性能测试作为触发,由于延迟原因可能会出现报告已经结束但是状态还是进行中的状态
|
||||
List<TestCaseReportStatusResultDTO> loadResult = testCaseReportMetricDTO.getExecuteResult().getLoadResult();
|
||||
for (TestCaseReportStatusResultDTO dto: loadResult) {
|
||||
if(StringUtils.equals(dto.getStatus(),TestPlanTestCaseStatus.Underway.name())){
|
||||
for (TestCaseReportStatusResultDTO dto : loadResult) {
|
||||
if (StringUtils.equals(dto.getStatus(), TestPlanTestCaseStatus.Underway.name())) {
|
||||
dto.setStatus(TestPlanTestCaseStatus.Pass.name());
|
||||
}
|
||||
}
|
||||
|
@ -311,49 +322,50 @@ public class TestPlanReportService {
|
|||
testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult()));
|
||||
testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases()));
|
||||
testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult()));
|
||||
if(issuesInfo!=null){
|
||||
if (issuesInfo != null) {
|
||||
testPlanReportData.setIssuesInfo(issuesInfo);
|
||||
}
|
||||
testPlanReportDataMapper.updateByPrimaryKeyWithBLOBs(testPlanReportData);
|
||||
}
|
||||
|
||||
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport,testPlanReportData);
|
||||
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport, testPlanReportData);
|
||||
testPlanReport.setStatus(testPlanStatus);
|
||||
this.update(testPlanReport);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算测试计划的状态
|
||||
*
|
||||
* @param testPlanReport
|
||||
* @return
|
||||
*/
|
||||
private String getTestPlanReportStatus(TestPlanReport testPlanReport, TestPlanReportDataWithBLOBs testPlanReportData) {
|
||||
String status = TestPlanReportStatus.COMPLETED.name();
|
||||
if(testPlanReport!=null){
|
||||
if(testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting() || testPlanReport.getIsScenarioExecuting()){
|
||||
if (testPlanReport != null) {
|
||||
if (testPlanReport.getIsApiCaseExecuting() || testPlanReport.getIsPerformanceExecuting() || testPlanReport.getIsScenarioExecuting()) {
|
||||
status = TestPlanReportStatus.RUNNING.name();
|
||||
}else {
|
||||
if(testPlanReportData == null){
|
||||
} else {
|
||||
if (testPlanReportData == null) {
|
||||
String failCaseString = testPlanReportData.getFailurTestCases();
|
||||
status = TestPlanReportStatus.SUCCESS.name();
|
||||
try {
|
||||
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();
|
||||
return status;
|
||||
}
|
||||
if(failurCaseObject.containsKey("loadTestCases")&&failurCaseObject.getJSONArray("loadTestCases").size()>=0){
|
||||
if (failurCaseObject.containsKey("loadTestCases") && failurCaseObject.getJSONArray("loadTestCases").size() >= 0) {
|
||||
status = TestPlanReportStatus.FAILED.name();
|
||||
return status;
|
||||
}
|
||||
if(failurCaseObject.containsKey("scenarioTestCases")&&failurCaseObject.getJSONArray("scenarioTestCases").size()>=0){
|
||||
if (failurCaseObject.containsKey("scenarioTestCases") && failurCaseObject.getJSONArray("scenarioTestCases").size() >= 0) {
|
||||
status = TestPlanReportStatus.FAILED.name();
|
||||
return status;
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
status = TestPlanReportStatus.FAILED.name();
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
status = TestPlanReportStatus.COMPLETED.name();
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +383,7 @@ public class TestPlanReportService {
|
|||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||
}
|
||||
|
||||
if(StringUtils.equalsAny(report.getTriggerMode(),ReportTriggerMode.SCHEDULE.name())){
|
||||
if (StringUtils.equalsAny(report.getTriggerMode(), ReportTriggerMode.SCHEDULE.name())) {
|
||||
//发送通知
|
||||
sendMessage(report);
|
||||
}
|
||||
|
@ -379,7 +391,7 @@ public class TestPlanReportService {
|
|||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
}
|
||||
testPlanReportMapper.updateByPrimaryKey(report);
|
||||
}
|
||||
|
@ -417,7 +429,7 @@ public class TestPlanReportService {
|
|||
String successfulMailTemplate = "";
|
||||
String errfoMailTemplate = "";
|
||||
|
||||
if(StringUtils.equals(testPlanReport.getTriggerMode(),ReportTriggerMode.SCHEDULE.name())){
|
||||
if (StringUtils.equals(testPlanReport.getTriggerMode(), ReportTriggerMode.SCHEDULE.name())) {
|
||||
successfulMailTemplate = "TestPlanSuccessfulNotification";
|
||||
errfoMailTemplate = "TestPlanFailedNotification";
|
||||
}
|
||||
|
@ -446,7 +458,7 @@ public class TestPlanReportService {
|
|||
* @param testPlanReport
|
||||
* @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();
|
||||
example.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId());
|
||||
List<TestPlanReportDataWithBLOBs> reportDataList = testPlanReportDataMapper.selectByExampleWithBLOBs(example);
|
||||
|
@ -462,36 +474,36 @@ public class TestPlanReportService {
|
|||
List<String> updatePerformaneReportIDList = new ArrayList<>(performaneReportIDList);
|
||||
executorService.submit(() -> {
|
||||
//错误数据检查集合。 如果错误数据出现超过20次,则取消该条数据的检查
|
||||
Map<String,Integer> errorDataCheckMap = new HashMap<>();
|
||||
while (performaneReportIDList.size()>0) {
|
||||
Map<String, Integer> errorDataCheckMap = new HashMap<>();
|
||||
while (performaneReportIDList.size() > 0) {
|
||||
List<String> selectList = new ArrayList<>(performaneReportIDList);
|
||||
for (String loadTestReportId:selectList) {
|
||||
for (String loadTestReportId : selectList) {
|
||||
LoadTestReportWithBLOBs loadTestReportFromDatabase = loadTestReportMapper.selectByPrimaryKey(loadTestReportId);
|
||||
if(loadTestReportFromDatabase == null){
|
||||
if (loadTestReportFromDatabase == null) {
|
||||
//检查错误数据
|
||||
if(errorDataCheckMap.containsKey(loadTestReportId)){
|
||||
if(errorDataCheckMap.get(loadTestReportId)>10){
|
||||
if (errorDataCheckMap.containsKey(loadTestReportId)) {
|
||||
if (errorDataCheckMap.get(loadTestReportId) > 10) {
|
||||
performaneReportIDList.remove(loadTestReportId);
|
||||
}else {
|
||||
errorDataCheckMap.put(loadTestReportId,errorDataCheckMap.get(loadTestReportId)+1);
|
||||
} else {
|
||||
errorDataCheckMap.put(loadTestReportId, errorDataCheckMap.get(loadTestReportId) + 1);
|
||||
}
|
||||
}else {
|
||||
errorDataCheckMap.put(loadTestReportId,1);
|
||||
} else {
|
||||
errorDataCheckMap.put(loadTestReportId, 1);
|
||||
}
|
||||
}else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(),
|
||||
} else if (StringUtils.equalsAny(loadTestReportFromDatabase.getStatus(),
|
||||
PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) {
|
||||
performaneReportIDList.remove(loadTestReportId);
|
||||
}
|
||||
}
|
||||
if(performaneReportIDList.isEmpty()){
|
||||
for (String string: updatePerformaneReportIDList) {
|
||||
if (performaneReportIDList.isEmpty()) {
|
||||
for (String string : updatePerformaneReportIDList) {
|
||||
TestPlanLoadCaseEventDTO eventDTO = new TestPlanLoadCaseEventDTO();
|
||||
eventDTO.setReportId(string);
|
||||
eventDTO.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
||||
eventDTO.setStatus(PerformanceTestStatus.Completed.name());
|
||||
this.updatePerformanceTestStatus(eventDTO);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
try {
|
||||
//查询定时任务是否关闭
|
||||
Thread.sleep(1000 * 10);// 检查 loadtest 的状态
|
||||
|
@ -505,7 +517,7 @@ public class TestPlanReportService {
|
|||
|
||||
public void updatePerformanceTestStatus(TestPlanLoadCaseEventDTO eventDTO) {
|
||||
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) {
|
||||
|
|
|
@ -33,6 +33,7 @@ import io.metersphere.service.SystemParameterService;
|
|||
import io.metersphere.track.Factory.ReportComponentFactory;
|
||||
import io.metersphere.track.domain.ReportComponent;
|
||||
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.QueryTestPlanRequest;
|
||||
import io.metersphere.track.request.testplan.AddTestPlanRequest;
|
||||
|
@ -128,6 +129,8 @@ public class TestPlanService {
|
|||
private ApiScenarioMapper apiScenarioMapper;
|
||||
@Resource
|
||||
private TestCaseTestMapper testCaseTestMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||
|
||||
public synchronized String addTestPlan(AddTestPlanRequest testPlan) {
|
||||
if (getTestPlanByName(testPlan.getName()).size() > 0) {
|
||||
|
@ -173,7 +176,7 @@ public class TestPlanService {
|
|||
return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlan());
|
||||
}
|
||||
|
||||
public int editTestPlan(TestPlanDTO testPlan) {
|
||||
public int editTestPlan(TestPlanDTO testPlan, Boolean isSendMessage) {
|
||||
checkTestPlanExist(testPlan);
|
||||
TestPlan res = testPlanMapper.selectByPrimaryKey(testPlan.getId()); // 先查一次库
|
||||
testPlan.setUpdateTime(System.currentTimeMillis());
|
||||
|
@ -211,7 +214,7 @@ public class TestPlanService {
|
|||
extScheduleMapper.updateNameByResourceID(testPlan.getId(), testPlan.getName());// 同步更新该测试的定时任务的name
|
||||
i = testPlanMapper.updateByPrimaryKeyWithBLOBs(testPlan); // 更新
|
||||
}
|
||||
if (!StringUtils.isBlank(testPlan.getStatus())) {
|
||||
if (!StringUtils.isBlank(testPlan.getStatus()) && isSendMessage) {
|
||||
BeanUtils.copyBean(testPlans, getTestPlan(testPlan.getId()));
|
||||
String context = getTestPlanContext(testPlans, NoticeConstants.Event.UPDATE);
|
||||
User user = userMapper.selectByPrimaryKey(testPlans.getCreator());
|
||||
|
@ -397,7 +400,7 @@ public class TestPlanService {
|
|||
testPlanDTO.setId(testPlanId);
|
||||
if(statusList.size() == 0) { // 原先status不是prepare, 但删除所有关联用例的情况
|
||||
testPlanDTO.setStatus(TestPlanStatus.Prepare.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
editTestPlan(testPlanDTO, false);
|
||||
return;
|
||||
}
|
||||
int passNum = 0, prepareNum = 0, failNum = 0;
|
||||
|
@ -414,13 +417,13 @@ public class TestPlanService {
|
|||
}
|
||||
if(passNum == statusList.size()) { // 全部通过
|
||||
testPlanDTO.setStatus(TestPlanStatus.Completed.name());
|
||||
this.editTestPlan(testPlanDTO);
|
||||
this.editTestPlan(testPlanDTO, false);
|
||||
} else if(prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束
|
||||
testPlanDTO.setStatus(TestPlanStatus.Finished.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
editTestPlan(testPlanDTO, false);
|
||||
} else if(prepareNum != 0) { // 进行中
|
||||
testPlanDTO.setStatus(TestPlanStatus.Underway.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
editTestPlan(testPlanDTO, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -863,12 +866,13 @@ public class TestPlanService {
|
|||
* @return
|
||||
*/
|
||||
public String runScenarioCase(SchedulePlanScenarioExecuteRequest request) {
|
||||
String returnId = "";
|
||||
MsTestPlan testPlan = new MsTestPlan();
|
||||
testPlan.setHashTree(new LinkedList<>());
|
||||
HashTree jmeterHashTree = new ListedHashTree();
|
||||
Map<String, Map<String, String>> testPlanScenarioIdMap = request.getTestPlanScenarioIDMap();
|
||||
|
||||
for (Map.Entry<String, Map<String, String>> entry : testPlanScenarioIdMap.entrySet()) {
|
||||
String testPlanID = entry.getKey();
|
||||
Map<String, String> planScenarioIdMap = entry.getValue();
|
||||
List<ApiScenarioWithBLOBs> apiScenarios = extApiScenarioMapper.selectIds(new ArrayList<>(planScenarioIdMap.keySet()));
|
||||
try {
|
||||
|
@ -918,23 +922,27 @@ public class TestPlanService {
|
|||
scenarios.add(scenario);
|
||||
// 创建场景报告
|
||||
//不同的运行模式,第二个参数入参不同
|
||||
apiAutomationService.createScenarioReport(group.getName(),
|
||||
APIScenarioReportResult report = apiAutomationService.createScenarioReport(group.getName(),
|
||||
planScenarioID + ":" + request.getTestPlanReportId(),
|
||||
item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
||||
group.setHashTree(scenarios);
|
||||
testPlan.getHashTree().add(group);
|
||||
|
||||
apiScenarioReportMapper.insert(report);
|
||||
returnId = request.getId();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
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();
|
||||
// 调用执行方法
|
||||
jMeterService.runDefinition(request.getId(), jmeterHashTree, request.getReportId(), runMode);
|
||||
return request.getId();
|
||||
|
||||
return returnId;
|
||||
}
|
||||
|
||||
public void run(String testPlanID, String projectID, String userId, String triggerMode) {
|
||||
|
@ -966,37 +974,21 @@ public class TestPlanService {
|
|||
|
||||
LogUtil.info("-------------- start testplan schedule ----------");
|
||||
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());
|
||||
}
|
||||
|
||||
//执行场景执行任务
|
||||
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(testPlanReport.getId());
|
||||
this.runScenarioCase(scenarioRequest);
|
||||
LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------");
|
||||
}
|
||||
boolean apiCaseIsExcuting = false;
|
||||
boolean scenarioIsExcuting = false;
|
||||
boolean performaceIsExcuting = false;
|
||||
String apiCaseIdArray = "";
|
||||
String scenarioCaseIdArray = "";
|
||||
String performanceCaseIdArray = "";
|
||||
String planReportId = UUID.randomUUID().toString();
|
||||
//创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数
|
||||
TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(planReportId,testPlanID,userId,triggerMode,
|
||||
apiTestCaseIdMap.size()>0,planScenarioIdMap.size()>0,performanceIdMap.size()>0,
|
||||
JSONArray.toJSONString(new ArrayList<>(apiTestCaseIdMap.keySet())),JSONArray.toJSONString(new ArrayList<>(planScenarioIdMap.keySet())),JSONArray.toJSONString(new ArrayList<>(performanceIdMap.values())));
|
||||
|
||||
TestPlanReport testPlanReport = testPlanReportService.genTestPlanReport(saveRequest);
|
||||
|
||||
//执行性能测试任务
|
||||
List<String> performaneReportIDList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
||||
|
@ -1016,20 +1008,76 @@ public class TestPlanService {
|
|||
testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId());
|
||||
testPlanLoadCase.setLoadReportId(reportId);
|
||||
testPlanLoadCaseService.update(testPlanLoadCase);
|
||||
|
||||
//更新关联处的报告
|
||||
TestPlanLoadCase loadCase = new TestPlanLoadCaseDTO();
|
||||
loadCase.setId(id);
|
||||
loadCase.setLoadReportId(reportId);
|
||||
testPlanLoadCaseService.update(loadCase);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//更新关联处的报告
|
||||
TestPlanLoadCase loadCase = new TestPlanLoadCaseDTO();
|
||||
loadCase.setId(id);
|
||||
loadCase.setLoadReportId(reportId);
|
||||
testPlanLoadCaseService.update(loadCase);
|
||||
if(StringUtils.isEmpty(reportId)){
|
||||
performaceIsExcuting = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(performaceIsExcuting){
|
||||
performanceCaseIdArray= JSONArray.toJSONString(new ArrayList<>(performanceIdMap.values()));
|
||||
}
|
||||
|
||||
if (!performaneReportIDList.isEmpty()) {
|
||||
//性能测试时保存性能测试报告ID,在结果返回时用于捕捉并进行
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ values ('test_plan_list',
|
|||
'[{"id":"name","label":"名称"},{"id":"userName","label":"负责人"},{"id":"status","label":"当前状态"},{"id":"stage","label":"测试阶段"},{"id":"testRate","label":"测试进度"},{"id":"projectName","label":"所属项目"},{"id":"plannedStartTime","label":"计划开始"},{"id":"plannedEndTime","label":"计划结束"},{"id":"actualStartTime","label":"实际开始"},{"id":"actualEndTime","label":"实际结束"},{"id":"tags","label":"标签"},{"id":"executionTimes","label":"执行次数"},{"id":"passRate","label":"通过率"}]');
|
||||
insert into system_header (type, props)
|
||||
values ('test_case_list',
|
||||
'[{"id":"tags","label":"标签"},{"id":"nodePath","label":"所属模块"},{"id":"updateTime","label":"更新时间"},{"id":"num","label":"ID"},{"id":"name","label":"名称"},{"id":"priority","label":"用例等级"},{"id":"reviewStatus","label":"评审状态"}]');
|
||||
'[{"id":"num","label":"ID"},{"id":"name","label":"名称"},{"id":"priority","label":"用例等级"},{"id":"reviewStatus","label":"评审状态"},{"id":"tags","label":"标签"},{"id":"nodePath","label":"所属模块"},{"id":"updateTime","label":"更新时间"}]');
|
||||
insert into system_header (type, props)
|
||||
values ('test_plan_scenario_case',
|
||||
'[{"id":"num","label":"ID"},{"id":"name","label":"名称"},{"id":"level","label":"用例等级"},{"id":"tagNames","label":"标签"},{"id":"userId","label":"创建人"},{"id":"updateTime","label":"最后更新时间"},{"id":"stepTotal","label":"通过"},{"id":"lastResult","label":"失败"},{"id":"passRate","label":"通过率"}]');
|
||||
|
|
|
@ -643,7 +643,7 @@ export default {
|
|||
|
||||
if(lastIndex < this.currentApiIndexInApiShowArray){
|
||||
//上移
|
||||
if(this.needAsyncSelect){
|
||||
// if(this.needAsyncSelect){
|
||||
//进行判断:是否还需要为apiShowArray 增加数据。 由于在当前数据前后最多展现2条数据,
|
||||
//可得: apiStepIndex-1- 2 < apiInfoArray,需要添加数据
|
||||
let dataIndex = this.apiStepIndex -3;
|
||||
|
@ -657,11 +657,11 @@ export default {
|
|||
if(this.apiShowArray.length > (this.currentApiIndexInApiShowArray+3)){
|
||||
this.apiShowArray.pop();
|
||||
}
|
||||
}
|
||||
// }
|
||||
this.apiStepIndex --;
|
||||
}else if(lastIndex > this.currentApiIndexInApiShowArray){
|
||||
//下滚
|
||||
if(this.needAsyncSelect){
|
||||
// if(this.needAsyncSelect){
|
||||
//进行判断:是否还需要为apiShowArray 增加数据。 由于在当前数据前后最多展现2条数据,
|
||||
//可得: apiStepIndex+1+ 2 < apiInfoArray,需要添加数据
|
||||
let dataIndex = this.apiStepIndex +3;
|
||||
|
@ -678,7 +678,7 @@ export default {
|
|||
let itemHeight = this.$refs.apiDocInfoDivItem[0].offsetHeight+10;
|
||||
this.$refs.apiDocInfoDiv.scrollTop = (apiDocDivScrollTop-itemHeight);
|
||||
}
|
||||
}
|
||||
// }
|
||||
this.apiStepIndex ++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,12 +126,13 @@ export default {
|
|||
let apiTest = this.$store.state.test;
|
||||
if (apiTest && apiTest.name) {
|
||||
this.$set(this.test, "name", apiTest.name);
|
||||
let blob = new Blob([apiTest.jmx.xml], {type: "application/octet-stream"});
|
||||
let suffixIndex = apiTest.jmx.name.lastIndexOf(".jmx");
|
||||
let jmxName = apiTest.jmx.name.substring(0, suffixIndex) + "_" + new Date().getTime() + ".jmx";
|
||||
let file = new File([blob], jmxName); // 保证每次从接口测试都能创建新的性能测试
|
||||
this.$refs.basicConfig.beforeUploadJmx(file);
|
||||
this.$refs.basicConfig.handleUpload({file: file});
|
||||
if (apiTest.jmx.scenarioId) {
|
||||
this.$refs.basicConfig.importScenario(apiTest.jmx.scenarioId);
|
||||
this.$refs.basicConfig.handleUpload();
|
||||
}
|
||||
if (apiTest.jmx.caseId) {
|
||||
this.$refs.basicConfig.importCase(apiTest.jmx);
|
||||
}
|
||||
if (JSON.stringify(apiTest.jmx.attachFiles) != "{}") {
|
||||
let attachFiles = [];
|
||||
for (let fileID in apiTest.jmx.attachFiles) {
|
||||
|
|
|
@ -116,6 +116,7 @@ import MsTableOperatorButton from "@/business/components/common/components/MsTab
|
|||
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
|
||||
import ExistFiles from "@/business/components/performance/test/components/ExistFiles";
|
||||
import ExistScenarios from "@/business/components/performance/test/components/ExistScenarios";
|
||||
import {findThreadGroup} from "@/business/components/performance/test/model/ThreadGroup";
|
||||
|
||||
export default {
|
||||
name: "PerformanceBasicConfig",
|
||||
|
@ -329,12 +330,30 @@ export default {
|
|||
}
|
||||
return true;
|
||||
},
|
||||
beforeUploadJmx(file) {
|
||||
this.$refs.existFiles.beforeUploadFile(file);
|
||||
importScenario(scenarioId) {
|
||||
this.$refs.existScenarios.selectIds.add(scenarioId);
|
||||
},
|
||||
handleUpload(file) {
|
||||
importCase(caseObj) {
|
||||
console.log("case: ", caseObj);
|
||||
let suffixIndex = caseObj.name.lastIndexOf(".jmx");
|
||||
let jmxName = caseObj.name.substring(0, suffixIndex) + "_" + new Date().getTime() + ".jmx";
|
||||
let threadGroups = findThreadGroup(caseObj.xml, jmxName);
|
||||
threadGroups.forEach(tg => {
|
||||
tg.options = {};
|
||||
});
|
||||
this.fileChange(threadGroups);
|
||||
let file = new File([caseObj.xml], jmxName);
|
||||
this.uploadList.push(file);
|
||||
this.tableData.push({
|
||||
name: file.name,
|
||||
size: (file.size / 1024).toFixed(2) + ' KB',
|
||||
type: 'JMX',
|
||||
updateTime: file.lastModified,
|
||||
});
|
||||
},
|
||||
handleUpload() {
|
||||
// 从api创建的测试
|
||||
this.$refs.existFiles.handleUpload(file, true);
|
||||
this.$refs.existScenarios.handleImport();
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -468,7 +468,6 @@ export default {
|
|||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$get(url).then(res => {
|
||||
console.log(res.data.data)
|
||||
const data = res.data.data.map(item => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
|
@ -640,8 +639,8 @@ export default {
|
|||
if (tmp.steps == null) {
|
||||
tmp.steps = []
|
||||
}
|
||||
tmp.tags = JSON.parse(tmp.tags);
|
||||
Object.assign(this.form, tmp);
|
||||
console.log(this.form.selected)
|
||||
this.form.module = testCase.nodeId;
|
||||
this.getFileMetaData(testCase);
|
||||
/* testCase.selected = JSON.parse(testCase.testId);
|
||||
|
|
|
@ -395,6 +395,9 @@ export default {
|
|||
item.tags = JSON.parse(item.tags);
|
||||
}
|
||||
})*/
|
||||
this.tableData.forEach((item) => {
|
||||
item.tags = JSON.parse(item.tags);
|
||||
})
|
||||
if (this.$refs.table) {
|
||||
this.$refs.table.doLayout()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue