parent
d97772a36a
commit
2c7a65a5ec
|
@ -27,4 +27,5 @@ public class ApiScenarioRequest {
|
|||
private boolean isSelectThisWeedData;
|
||||
private long createTime = 0;
|
||||
private String executeStatus;
|
||||
private boolean notInTestPlan;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
|||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
|
@ -32,6 +33,8 @@ public class RunScenarioRequest {
|
|||
|
||||
private List<String> scenarioIds;
|
||||
|
||||
private Map<String,String> scenarioTestPlanIdMap;
|
||||
|
||||
/**
|
||||
* isSelectAllDate:选择的数据是否是全部数据(全部数据是不受分页影响的数据)
|
||||
* filters: 数据状态
|
||||
|
|
|
@ -397,8 +397,19 @@ public class ApiAutomationService {
|
|||
scenarios.add(scenario);
|
||||
// 创建场景报告
|
||||
if (reportIds != null) {
|
||||
createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
||||
//如果是测试计划页面触发的执行方式,生成报告时createScenarioReport第二个参数需要特殊处理
|
||||
if(StringUtils.equals(request.getRunMode(),ApiRunMode.SCENARIO_PLAN.name())){
|
||||
String testPlanScenarioId = item.getId();
|
||||
if(request.getScenarioTestPlanIdMap()!=null&&request.getScenarioTestPlanIdMap().containsKey(item.getId())){
|
||||
testPlanScenarioId = request.getScenarioTestPlanIdMap().get(item.getId());
|
||||
}
|
||||
createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
||||
}else{
|
||||
createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
|
||||
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
|
||||
}
|
||||
|
||||
reportIds.add(group.getName());
|
||||
}
|
||||
group.setHashTree(scenarios);
|
||||
|
|
|
@ -134,31 +134,41 @@ public class ApiScenarioReportService {
|
|||
}
|
||||
|
||||
public ApiScenarioReport updatePlanCase(TestResult result) {
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
||||
ScenarioResult scenarioResult = result.getScenarios().get(0);
|
||||
if (scenarioResult.getError() > 0) {
|
||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||
} else {
|
||||
testPlanApiScenario.setLastResult(ScenarioStatus.Success.name());
|
||||
// TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(result.getTestId());
|
||||
List<ScenarioResult> scenarioResultList = result.getScenarios();
|
||||
ApiScenarioReport returnReport = null;
|
||||
for (ScenarioResult scenarioResult :
|
||||
scenarioResultList) {
|
||||
ApiScenarioReport report = editReport(scenarioResult);
|
||||
// 报告详情内容
|
||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
|
||||
scenarioResult.setName(report.getScenarioName());
|
||||
newResult.addScenario(scenarioResult);
|
||||
|
||||
detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8));
|
||||
detail.setReportId(report.getId());
|
||||
detail.setProjectId(report.getProjectId());
|
||||
apiScenarioReportDetailMapper.insert(detail);
|
||||
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(report.getScenarioId());
|
||||
if(testPlanApiScenario!=null){
|
||||
report.setScenarioId(testPlanApiScenario.getApiScenarioId());
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||
if (scenarioResult.getError() > 0) {
|
||||
testPlanApiScenario.setLastResult(ScenarioStatus.Fail.name());
|
||||
} else {
|
||||
testPlanApiScenario.setLastResult(ScenarioStatus.Success.name());
|
||||
}
|
||||
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
||||
testPlanApiScenario.setPassRate(passRate);
|
||||
testPlanApiScenario.setReportId(report.getId());
|
||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||
}
|
||||
returnReport = report;
|
||||
}
|
||||
String passRate = new DecimalFormat("0%").format((float) scenarioResult.getSuccess() / (scenarioResult.getSuccess() + scenarioResult.getError()));
|
||||
testPlanApiScenario.setPassRate(passRate);
|
||||
// 存储场景报告
|
||||
ApiScenarioReport report = editReport(scenarioResult);
|
||||
// 报告详情内容
|
||||
ApiScenarioReportDetail detail = new ApiScenarioReportDetail();
|
||||
TestResult newResult = createTestResult(result.getTestId(), scenarioResult);
|
||||
scenarioResult.setName(report.getScenarioName());
|
||||
newResult.addScenario(scenarioResult);
|
||||
|
||||
detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8));
|
||||
detail.setReportId(report.getId());
|
||||
detail.setProjectId(report.getProjectId());
|
||||
apiScenarioReportDetailMapper.insert(detail);
|
||||
|
||||
testPlanApiScenario.setReportId(report.getId());
|
||||
testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario);
|
||||
return report;
|
||||
return returnReport;
|
||||
}
|
||||
|
||||
public ApiScenarioReport updateSchedulePlanCase(TestResult result) {
|
||||
|
|
|
@ -164,7 +164,13 @@
|
|||
<if test="request.executeStatus == 'executePass'">
|
||||
and api_scenario.last_result = 'Success'
|
||||
</if>
|
||||
|
||||
<if test="request.notInTestPlan == true ">
|
||||
and api_scenario.id not in (
|
||||
select pc.api_scenario_id
|
||||
from test_plan_api_scenario pc
|
||||
where pc.test_plan_id = #{request.planId}
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
order by
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
package io.metersphere.job.sechedule;
|
||||
|
||||
import io.metersphere.api.dto.automation.ExecuteType;
|
||||
import io.metersphere.api.dto.automation.RunScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.SchedulePlanScenarioExecuteRequest;
|
||||
import io.metersphere.api.dto.definition.RunCaseRequest;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
|
@ -19,13 +14,9 @@ import io.metersphere.track.dto.TestPlanLoadCaseDTO;
|
|||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||
import io.metersphere.track.request.testplan.RunTestPlanRequest;
|
||||
import io.metersphere.track.service.*;
|
||||
import org.python.antlr.ast.Str;
|
||||
import org.quartz.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 情景测试Job
|
||||
|
@ -130,7 +121,7 @@ public class TestPlanTestJob extends MsScheduleJob {
|
|||
scenarioRequest.setTestPlanID(this.resourceId);
|
||||
scenarioRequest.setRunMode(ApiRunMode.SCHEDULE_SCENARIO_PLAN.name());
|
||||
scenarioRequest.setTestPlanReportId(testPlanReport.getId());
|
||||
testPlanService.runApiCase(scenarioRequest);
|
||||
testPlanService.runScenarioCase(scenarioRequest);
|
||||
LogUtil.info("-------------- testplan schedule ---------- scenario case over -----------------");
|
||||
|
||||
//执行性能测试任务
|
||||
|
|
|
@ -22,9 +22,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -51,11 +49,12 @@ public class TestPlanScenarioCaseService {
|
|||
}
|
||||
|
||||
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
|
||||
List<String> ids = apiAutomationService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
request.setIds(ids);
|
||||
// List<String> ids = apiAutomationService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
|
||||
// if (CollectionUtils.isEmpty(ids)) {
|
||||
// return new ArrayList<>();
|
||||
// }
|
||||
// request.setIds(ids);
|
||||
request.setNotInTestPlan(true);
|
||||
return apiAutomationService.list(request);
|
||||
}
|
||||
|
||||
|
@ -88,11 +87,17 @@ public class TestPlanScenarioCaseService {
|
|||
public String run(RunScenarioRequest request) {
|
||||
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
|
||||
example.createCriteria().andIdIn(request.getPlanCaseIds());
|
||||
List<String> scenarioIds = testPlanApiScenarioMapper.selectByExample(example).stream()
|
||||
.map(TestPlanApiScenario::getApiScenarioId)
|
||||
.collect(Collectors.toList());
|
||||
scenarioIds.addAll(scenarioIds);
|
||||
List<TestPlanApiScenario> testPlanApiScenarioList = testPlanApiScenarioMapper.selectByExample(example);
|
||||
|
||||
List<String> scenarioIds = new ArrayList<>();
|
||||
Map<String,String> scenarioIdApiScarionMap = new HashMap<>();
|
||||
for (TestPlanApiScenario apiScenario:
|
||||
testPlanApiScenarioList) {
|
||||
scenarioIds.add(apiScenario.getApiScenarioId());
|
||||
scenarioIdApiScarionMap.put(apiScenario.getApiScenarioId(),apiScenario.getId());
|
||||
}
|
||||
request.setScenarioIds(scenarioIds);
|
||||
request.setScenarioTestPlanIdMap(scenarioIdApiScarionMap);
|
||||
request.setRunMode(ApiRunMode.SCENARIO_PLAN.name());
|
||||
return apiAutomationService.run(request);
|
||||
}
|
||||
|
|
|
@ -751,7 +751,7 @@ public class TestPlanService {
|
|||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public String runApiCase(SchedulePlanScenarioExecuteRequest request) {
|
||||
public String runScenarioCase(SchedulePlanScenarioExecuteRequest request) {
|
||||
MsTestPlan testPlan = new MsTestPlan();
|
||||
testPlan.setHashTree(new LinkedList<>());
|
||||
HashTree jmeterHashTree = new ListedHashTree();
|
||||
|
|
Loading…
Reference in New Issue