fix(测试计划): 测试计划接口执行相关
This commit is contained in:
parent
ffc3bfc934
commit
cdc255507b
|
@ -66,7 +66,11 @@ public class MessageListener {
|
|||
}
|
||||
// 集合报告不发送通知
|
||||
} else {
|
||||
try {
|
||||
apiReportSendNoticeService.sendNotice(dto);
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getParentQueueId())
|
||||
&& BooleanUtils.isTrue(dto.getChildCollectionExecuteOver())) {
|
||||
// 执行下一个测试集
|
||||
|
|
|
@ -42,9 +42,9 @@ public class ApiExecuteResourceService {
|
|||
ApiExecuteResourceType apiExecuteResourceType = EnumValidator.validateEnum(ApiExecuteResourceType.class, request.getResourceType());
|
||||
|
||||
switch (apiExecuteResourceType) {
|
||||
case API_SCENARIO, TEST_PLAN_API_SCENARIO ->
|
||||
case API_SCENARIO, TEST_PLAN_API_SCENARIO, PLAN_RUN_API_SCENARIO ->
|
||||
apiScenarioReportService.updateReportStatus(reportId, ExecStatus.RUNNING.name());
|
||||
case API_CASE, TEST_PLAN_API_CASE ->
|
||||
case API_CASE, TEST_PLAN_API_CASE, PLAN_RUN_API_CASE ->
|
||||
apiReportService.updateReportStatus(reportId, ExecStatus.RUNNING.name());
|
||||
default -> throw new MSException("不支持的资源类型: " + request.getResourceType());
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ public class ApiTestCaseBatchRunService {
|
|||
|
||||
public ApiReport getApiReport(ApiRunModeConfigDTO runModeConfig, ApiTestCase apiTestCase, String userId) {
|
||||
ApiReport apiReport = getApiReport(runModeConfig, userId);
|
||||
apiReport.setEnvironmentId(apiTestCaseService.getEnvId(runModeConfig, apiTestCase));
|
||||
apiReport.setEnvironmentId(apiTestCaseService.getEnvId(runModeConfig, apiTestCase.getEnvironmentId()));
|
||||
apiReport.setName(apiTestCase.getName() + "_" + DateUtils.getTimeString(System.currentTimeMillis()));
|
||||
apiReport.setProjectId(apiTestCase.getProjectId());
|
||||
apiReport.setTriggerMode(TaskTriggerMode.BATCH.name());
|
||||
|
|
|
@ -786,7 +786,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
apiExecuteService.setTestElementParam(msTestElement, apiTestCase.getProjectId(), request.getTaskItem());
|
||||
|
||||
// 设置环境信息
|
||||
apiParamConfig.setEnvConfig(environmentService.get(getEnvId(request.getRunModeConfig(), apiTestCase)));
|
||||
apiParamConfig.setEnvConfig(environmentService.get(getEnvId(request.getRunModeConfig(), apiTestCase.getEnvironmentId())));
|
||||
GetRunScriptResult runScriptResult = new GetRunScriptResult();
|
||||
// 记录请求数量
|
||||
runScriptResult.setRequestCount(1L);
|
||||
|
@ -804,12 +804,13 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
* 优先使用运行配置的环境
|
||||
* 没有则使用用例自身的环境
|
||||
*
|
||||
* @param runModeConfig
|
||||
* @param apiTestCase
|
||||
* @return
|
||||
*/
|
||||
public String getEnvId(ApiRunModeConfigDTO runModeConfig, ApiTestCase apiTestCase) {
|
||||
return StringUtils.isBlank(runModeConfig.getEnvironmentId()) ? apiTestCase.getEnvironmentId() : runModeConfig.getEnvironmentId();
|
||||
public String getEnvId(ApiRunModeConfigDTO runModeConfig, String caseEnvId) {
|
||||
if (StringUtils.isBlank(runModeConfig.getEnvironmentId()) || StringUtils.equals(runModeConfig.getEnvironmentId(), CommonConstants.DEFAULT_NULL_VALUE)) {
|
||||
return caseEnvId;
|
||||
}
|
||||
return runModeConfig.getEnvironmentId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -830,7 +831,7 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
|
||||
apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord));
|
||||
//初始化步骤
|
||||
apiReportService.insertApiReportStep(List.of(getApiReportStep(apiTestCase, reportId, 1L)));
|
||||
apiReportService.insertApiReportStep(List.of(getApiReportStep(apiTestCase.getId(), apiTestCase.getName(), reportId, 1L)));
|
||||
return apiTestCaseRecord;
|
||||
}
|
||||
|
||||
|
@ -846,12 +847,12 @@ public class ApiTestCaseService extends MoveNodeService {
|
|||
return apiReport;
|
||||
}
|
||||
|
||||
public ApiReportStep getApiReportStep(ApiTestCase apiTestCase, String reportId, long sort) {
|
||||
public ApiReportStep getApiReportStep(String stepId, String stepName, String reportId, long sort) {
|
||||
ApiReportStep apiReportStep = new ApiReportStep();
|
||||
apiReportStep.setReportId(reportId);
|
||||
apiReportStep.setStepId(apiTestCase.getId());
|
||||
apiReportStep.setStepId(stepId);
|
||||
apiReportStep.setSort(sort);
|
||||
apiReportStep.setName(apiTestCase.getName());
|
||||
apiReportStep.setName(stepName);
|
||||
apiReportStep.setStepType(ApiExecuteResourceType.API_CASE.name());
|
||||
return apiReportStep;
|
||||
}
|
||||
|
|
|
@ -327,7 +327,7 @@ public class ApiScenarioBatchRunService {
|
|||
|
||||
private ApiScenarioReport getScenarioReport(ApiRunModeConfigDTO runModeConfig, ApiScenario apiScenario, String userId) {
|
||||
ApiScenarioReport apiScenarioReport = getScenarioReport(runModeConfig, userId);
|
||||
apiScenarioReport.setEnvironmentId(apiScenarioRunService.getEnvId(runModeConfig, apiScenario));
|
||||
apiScenarioReport.setEnvironmentId(apiScenarioRunService.getEnvId(runModeConfig, apiScenario.getEnvironmentId()));
|
||||
apiScenarioReport.setName(apiScenario.getName() + "_" + DateUtils.getTimeString(System.currentTimeMillis()));
|
||||
apiScenarioReport.setProjectId(apiScenario.getProjectId());
|
||||
apiScenarioReport.setTriggerMode(TaskTriggerMode.BATCH.name());
|
||||
|
|
|
@ -30,10 +30,7 @@ import io.metersphere.project.dto.environment.http.HttpConfigModuleMatchRule;
|
|||
import io.metersphere.project.dto.environment.http.SelectModule;
|
||||
import io.metersphere.project.service.EnvironmentGroupService;
|
||||
import io.metersphere.project.service.EnvironmentService;
|
||||
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
||||
import io.metersphere.sdk.constants.ApiExecuteRunMode;
|
||||
import io.metersphere.sdk.constants.ExecStatus;
|
||||
import io.metersphere.sdk.constants.TaskTriggerMode;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.util.DateUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
|
@ -265,6 +262,11 @@ public class ApiScenarioRunService {
|
|||
|
||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request, String id) {
|
||||
ApiScenarioDetail apiScenarioDetail = getForRun(id);
|
||||
return getRunScript(request, apiScenarioDetail);
|
||||
}
|
||||
|
||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request, ApiScenarioDetail apiScenarioDetail) {
|
||||
String id = apiScenarioDetail.getId();
|
||||
TaskItem taskItem = request.getTaskItem();
|
||||
ApiRunModeConfigDTO runModeConfig = request.getRunModeConfig();
|
||||
String reportId = taskItem.getReportId();
|
||||
|
@ -278,8 +280,8 @@ public class ApiScenarioRunService {
|
|||
return null;
|
||||
}
|
||||
|
||||
String envId = getEnvId(runModeConfig, apiScenarioDetail);
|
||||
boolean envGroup = getEnvGroup(runModeConfig, apiScenarioDetail);
|
||||
String envId = getEnvId(runModeConfig, apiScenarioDetail.getEnvironmentId());
|
||||
boolean envGroup = getEnvGroup(runModeConfig, apiScenarioDetail.getGrouped());
|
||||
|
||||
// 解析生成待执行的场景树
|
||||
MsScenario msScenario = getMsScenario(apiScenarioDetail);
|
||||
|
@ -329,12 +331,25 @@ public class ApiScenarioRunService {
|
|||
* @param apiScenario
|
||||
* @return
|
||||
*/
|
||||
public String getEnvId(ApiRunModeConfigDTO runModeConfig, ApiScenario apiScenario) {
|
||||
return StringUtils.isBlank(runModeConfig.getEnvironmentId()) ? apiScenario.getEnvironmentId() : runModeConfig.getEnvironmentId();
|
||||
/**
|
||||
* 获取执行的环境ID
|
||||
* 优先使用运行配置的环境
|
||||
* 没有则使用用例自身的环境
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getEnvId(ApiRunModeConfigDTO runModeConfig, String caseEnvId) {
|
||||
if (StringUtils.isBlank(runModeConfig.getEnvironmentId()) || StringUtils.equals(runModeConfig.getEnvironmentId(), CommonConstants.DEFAULT_NULL_VALUE)) {
|
||||
return caseEnvId;
|
||||
}
|
||||
return runModeConfig.getEnvironmentId();
|
||||
}
|
||||
|
||||
public boolean getEnvGroup(ApiRunModeConfigDTO runModeConfig, ApiScenario apiScenario) {
|
||||
return StringUtils.isBlank(runModeConfig.getEnvironmentId()) ? apiScenario.getGrouped() : runModeConfig.getGrouped();
|
||||
public boolean getEnvGroup(ApiRunModeConfigDTO runModeConfig, boolean group) {
|
||||
if (StringUtils.isBlank(runModeConfig.getEnvironmentId()) || StringUtils.equals(runModeConfig.getEnvironmentId(), CommonConstants.DEFAULT_NULL_VALUE)) {
|
||||
return group;
|
||||
}
|
||||
return runModeConfig.getGrouped();
|
||||
}
|
||||
|
||||
private void updateReportWaitTime(String reportId, ApiScenarioParseParam parseParam) {
|
||||
|
|
|
@ -22,7 +22,7 @@ public class PlanRunApiCaseExecuteCallbackService implements ApiExecuteCallbackS
|
|||
private TestPlanExecuteService testPlanExecuteService;
|
||||
|
||||
@Resource
|
||||
private TestPlanApiCasePlanRunService testPlanApiCasePlanRunService;
|
||||
private PlanRunTestPlanApiCaseService planRunTestPlanApiCaseService;
|
||||
|
||||
public PlanRunApiCaseExecuteCallbackService() {
|
||||
ApiExecuteCallbackServiceInvoker.register(ApiExecuteResourceType.PLAN_RUN_API_CASE, this);
|
||||
|
@ -33,7 +33,7 @@ public class PlanRunApiCaseExecuteCallbackService implements ApiExecuteCallbackS
|
|||
*/
|
||||
@Override
|
||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
||||
return testPlanApiCasePlanRunService.getRunScript(request);
|
||||
return planRunTestPlanApiCaseService.getRunScript(request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ public class PlanRunApiCaseExecuteCallbackService implements ApiExecuteCallbackS
|
|||
*/
|
||||
@Override
|
||||
public void executeNextTask(ExecutionQueue queue, ExecutionQueueDetail queueDetail) {
|
||||
testPlanApiCasePlanRunService.executeNextTask(queue, queueDetail);
|
||||
planRunTestPlanApiCaseService.executeNextTask(queue, queueDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import io.metersphere.api.invoker.ApiExecuteCallbackServiceInvoker;
|
||||
import io.metersphere.api.service.ApiExecuteCallbackService;
|
||||
import io.metersphere.sdk.constants.ApiExecuteResourceType;
|
||||
import io.metersphere.sdk.dto.api.task.GetRunScriptRequest;
|
||||
import io.metersphere.sdk.dto.api.task.GetRunScriptResult;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2024-02-06 20:47
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class PlanRunApiScenarioExecuteCallbackService implements ApiExecuteCallbackService {
|
||||
@Resource
|
||||
private TestPlanExecuteService testPlanExecuteService;
|
||||
|
||||
@Resource
|
||||
private PlanRunTestPlanApiScenarioService planRunTestPlanApiScenarioService;
|
||||
|
||||
public PlanRunApiScenarioExecuteCallbackService() {
|
||||
ApiExecuteCallbackServiceInvoker.register(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析并返回执行脚本
|
||||
*/
|
||||
@Override
|
||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
||||
return planRunTestPlanApiScenarioService.getRunScript(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 串行时,执行下一个任务
|
||||
* @param queue
|
||||
* @param queueDetail
|
||||
*/
|
||||
@Override
|
||||
public void executeNextTask(ExecutionQueue queue, ExecutionQueueDetail queueDetail) {
|
||||
planRunTestPlanApiScenarioService.executeNextTask(queue, queueDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量串行的测试集执行时
|
||||
* 测试集下用例执行完成时回调
|
||||
* @param parentQueueId
|
||||
*/
|
||||
@Override
|
||||
public void executeNextCollection(String parentQueueId) {
|
||||
testPlanExecuteService.collectionExecuteQueueFinish(parentQueueId);
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestPlanApiCasePlanRunService {
|
||||
public class PlanRunTestPlanApiCaseService {
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
|
@ -153,6 +153,7 @@ public class TestPlanApiCasePlanRunService {
|
|||
TaskBatchRequestDTO taskRequest = apiTestCaseBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
||||
taskRequest.setTaskItems(taskItems);
|
||||
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
|
||||
taskRequest.getTaskInfo().setUserId(userId);
|
||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name());
|
||||
apiExecuteService.batchExecute(taskRequest);
|
||||
|
||||
|
@ -191,6 +192,7 @@ public class TestPlanApiCasePlanRunService {
|
|||
TaskRequestDTO taskRequest = testPlanApiCaseBatchRunService.getTaskRequestDTO(reportId, testPlanReportApiCase.getId(), apiTestCase, runModeConfig);
|
||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name());
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setUserId(queue.getUserId());
|
||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||
taskRequest.getTaskItem().setRequestCount(1L);
|
||||
|
|
@ -3,6 +3,7 @@ package io.metersphere.plan.service;
|
|||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiScenarioRecord;
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDetail;
|
||||
import io.metersphere.api.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.api.mapper.ExtApiScenarioMapper;
|
||||
import io.metersphere.api.service.ApiBatchRunBaseService;
|
||||
|
@ -10,18 +11,13 @@ import io.metersphere.api.service.ApiExecuteService;
|
|||
import io.metersphere.api.service.queue.ApiExecutionQueueService;
|
||||
import io.metersphere.api.service.queue.ApiExecutionSetService;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioReportService;
|
||||
import io.metersphere.plan.domain.TestPlan;
|
||||
import io.metersphere.plan.domain.TestPlanCollection;
|
||||
import io.metersphere.plan.domain.TestPlanReportApiScenario;
|
||||
import io.metersphere.plan.domain.TestPlanReportApiScenarioExample;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioRunService;
|
||||
import io.metersphere.plan.domain.*;
|
||||
import io.metersphere.plan.mapper.ExtTestPlanApiScenarioMapper;
|
||||
import io.metersphere.plan.mapper.TestPlanMapper;
|
||||
import io.metersphere.plan.mapper.TestPlanReportApiScenarioMapper;
|
||||
import io.metersphere.sdk.constants.ApiExecuteResourceType;
|
||||
import io.metersphere.sdk.dto.api.task.ApiRunModeConfigDTO;
|
||||
import io.metersphere.sdk.dto.api.task.TaskBatchRequestDTO;
|
||||
import io.metersphere.sdk.dto.api.task.TaskItem;
|
||||
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
||||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueue;
|
||||
import io.metersphere.sdk.dto.queue.ExecutionQueueDetail;
|
||||
import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue;
|
||||
|
@ -34,16 +30,13 @@ import org.apache.commons.collections.CollectionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestPlanApiScenarioPlanRunService {
|
||||
public class PlanRunTestPlanApiScenarioService {
|
||||
@Resource
|
||||
private ApiScenarioMapper apiScenarioMapper;
|
||||
@Resource
|
||||
|
@ -57,6 +50,8 @@ public class TestPlanApiScenarioPlanRunService {
|
|||
@Resource
|
||||
private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper;
|
||||
@Resource
|
||||
private ApiScenarioRunService apiScenarioRunService;
|
||||
@Resource
|
||||
private TestPlanMapper testPlanMapper;
|
||||
@Resource
|
||||
private TestPlanApiBatchRunBaseService testPlanApiBatchRunBaseService;
|
||||
|
@ -122,6 +117,7 @@ public class TestPlanApiScenarioPlanRunService {
|
|||
TaskBatchRequestDTO taskRequest = testPlanApiScenarioBatchRunService.getTaskBatchRequestDTO(testPlan.getProjectId(), runModeConfig);
|
||||
taskRequest.setTaskItems(taskItems);
|
||||
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
|
||||
taskRequest.getTaskInfo().setUserId(userId);
|
||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
||||
|
||||
// 如果有父队列,则初始化执行集合,以便判断是否执行完毕
|
||||
|
@ -151,6 +147,7 @@ public class TestPlanApiScenarioPlanRunService {
|
|||
Map<String, ApiScenario> apiScenarioMap, String userId) {
|
||||
List<ApiScenarioReport> apiScenarioReports = new ArrayList<>(testPlanReportApiScenarios.size());
|
||||
List<ApiScenarioRecord> apiScenarioRecords = new ArrayList<>(testPlanReportApiScenarios.size());
|
||||
Map<String, String> resourceReportMap = new HashMap<>();
|
||||
for (TestPlanReportApiScenario testPlanReportApiScenario : testPlanReportApiScenarios) {
|
||||
ApiScenario apiScenario = apiScenarioMap.get(testPlanReportApiScenario.getApiScenarioId());
|
||||
// 初始化报告
|
||||
|
@ -168,9 +165,10 @@ public class TestPlanApiScenarioPlanRunService {
|
|||
scenarioRecord.setApiScenarioId(apiScenario.getId());
|
||||
scenarioRecord.setApiScenarioReportId(apiScenarioReport.getId());
|
||||
apiScenarioRecords.add(scenarioRecord);
|
||||
resourceReportMap.put(testPlanReportApiScenario.getId(), apiScenarioReport.getId());
|
||||
}
|
||||
apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords);
|
||||
return apiScenarioRecords.stream().collect(Collectors.toMap(ApiScenarioRecord::getApiScenarioId, ApiScenarioRecord::getApiScenarioReportId));
|
||||
return resourceReportMap;
|
||||
}
|
||||
|
||||
private List<TestPlanReportApiScenario> getTestPlanReportApiScenarios(String testPlanReportId, TestPlanCollection collection) {
|
||||
|
@ -206,9 +204,19 @@ public class TestPlanApiScenarioPlanRunService {
|
|||
TaskItem taskItem = apiExecuteService.getTaskItem(reportId, queueDetail.getResourceId());
|
||||
taskRequest.setTaskItem(taskItem);
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setUserId(queue.getUserId());
|
||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||
taskRequest.getTaskInfo().setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name());
|
||||
|
||||
apiExecuteService.execute(taskRequest);
|
||||
}
|
||||
|
||||
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
||||
TaskItem taskItem = request.getTaskItem();
|
||||
TestPlanReportApiScenario testPlanReportApiScenario = testPlanReportApiScenarioMapper.selectByPrimaryKey(taskItem.getResourceId());
|
||||
ApiScenarioDetail apiScenarioDetail = apiScenarioRunService.getForRun(testPlanReportApiScenario.getApiScenarioId());
|
||||
apiScenarioDetail.setEnvironmentId(testPlanReportApiScenario.getEnvironmentId());
|
||||
apiScenarioDetail.setGrouped(testPlanReportApiScenario.getGrouped());
|
||||
return apiScenarioRunService.getRunScript(request, testPlanReportApiScenario.getApiScenarioId());
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package io.metersphere.plan.service;
|
|||
import io.metersphere.plan.domain.TestPlanCollection;
|
||||
import io.metersphere.plan.domain.TestPlanCollectionExample;
|
||||
import io.metersphere.plan.mapper.TestPlanCollectionMapper;
|
||||
import io.metersphere.sdk.constants.CommonConstants;
|
||||
import io.metersphere.sdk.dto.api.task.ApiRunModeConfigDTO;
|
||||
import io.metersphere.sdk.dto.api.task.ApiRunRetryConfig;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
|
@ -25,23 +26,27 @@ public class TestPlanApiBatchRunBaseService {
|
|||
}
|
||||
|
||||
public ApiRunModeConfigDTO getApiRunModeConfig(TestPlanCollection collection) {
|
||||
TestPlanCollection rootCollection = null;
|
||||
if (collection == null) {
|
||||
ApiRunModeConfigDTO runModeConfig = new ApiRunModeConfigDTO();
|
||||
runModeConfig.setPoolId(StringUtils.EMPTY);
|
||||
return runModeConfig;
|
||||
}
|
||||
TestPlanCollection rootCollection = getExtendedRootCollection(collection);
|
||||
ApiRunModeConfigDTO runModeConfig = getApiRunModeConfig(rootCollection, collection);
|
||||
return runModeConfig;
|
||||
}
|
||||
|
||||
public TestPlanCollection getExtendedRootCollection(TestPlanCollection collection) {
|
||||
if (BooleanUtils.isTrue(collection.getExtended())
|
||||
&& StringUtils.equalsIgnoreCase(collection.getParentId(), "NONE")) {
|
||||
&& !StringUtils.equals(collection.getParentId(), CommonConstants.DEFAULT_NULL_VALUE)) {
|
||||
TestPlanCollectionExample example = new TestPlanCollectionExample();
|
||||
example.createCriteria().andParentIdEqualTo(collection.getParentId());
|
||||
rootCollection = testPlanCollectionMapper.selectByExample(example)
|
||||
example.createCriteria().andIdEqualTo(collection.getParentId());
|
||||
return testPlanCollectionMapper.selectByExample(example)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
ApiRunModeConfigDTO runModeConfig = getApiRunModeConfig(rootCollection, collection);
|
||||
return runModeConfig;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApiRunModeConfigDTO getApiRunModeConfig(TestPlanCollection rootCollection, TestPlanCollection collection) {
|
||||
|
|
|
@ -222,7 +222,7 @@ public class TestPlanApiCaseBatchRunService {
|
|||
.collect(Collectors.toMap(ApiTestCase::getId, Function.identity()));
|
||||
|
||||
// 初始化报告,返回用例和报告的 map
|
||||
Map<String, String> caseReportMap = initParallelReport(runModeConfig, testPlanApiCases, apiCaseMap, userId);
|
||||
Map<String, String> caseReportMap = initApiReport(runModeConfig, testPlanApiCases, apiCaseMap, userId);
|
||||
|
||||
List<TaskItem> taskItems = new ArrayList<>(ids.size());
|
||||
|
||||
|
@ -252,13 +252,6 @@ public class TestPlanApiCaseBatchRunService {
|
|||
apiExecuteService.batchExecute(taskRequest);
|
||||
}
|
||||
|
||||
private Map<String, String> initParallelReport(ApiRunModeConfigDTO runModeConfig, List<TestPlanApiCase> testPlanApiCases, Map<String, ApiTestCase> caseMap, String userId) {
|
||||
// 初始化非集成报告
|
||||
List<ApiTestCaseRecord> apiTestCaseRecords = initApiReport(runModeConfig, testPlanApiCases, caseMap, userId);
|
||||
return apiTestCaseRecords.stream()
|
||||
.collect(Collectors.toMap(ApiTestCaseRecord::getApiTestCaseId, ApiTestCaseRecord::getApiReportId));
|
||||
}
|
||||
|
||||
public ApiReportStep getApiReportStep(String resourceId, ApiTestCase apiTestCase, String reportId, long sort) {
|
||||
ApiReportStep apiReportStep = new ApiReportStep();
|
||||
apiReportStep.setReportId(reportId);
|
||||
|
@ -289,7 +282,7 @@ public class TestPlanApiCaseBatchRunService {
|
|||
ApiTestCase apiTestCase = apiTestCaseMapper.selectByPrimaryKey(testPlanApiCase.getApiCaseId());
|
||||
|
||||
// 独立报告,执行到当前任务时初始化报告
|
||||
String reportId = initApiReport(runModeConfig, List.of(testPlanApiCase), Map.of(apiTestCase.getId(), apiTestCase), queue.getUserId()).get(0).getApiReportId();
|
||||
String reportId = initApiReport(runModeConfig, List.of(testPlanApiCase), Map.of(apiTestCase.getId(), apiTestCase), queue.getUserId()).get(testPlanApiCase.getId());
|
||||
TaskRequestDTO taskRequest = getTaskRequestDTO(reportId, testPlanApiCase.getId(), apiTestCase, runModeConfig);
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||
|
@ -326,11 +319,12 @@ public class TestPlanApiCaseBatchRunService {
|
|||
* @param runModeConfig
|
||||
* @return
|
||||
*/
|
||||
public List<ApiTestCaseRecord> initApiReport(ApiRunModeConfigDTO runModeConfig, List<TestPlanApiCase> testPlanApiCases,
|
||||
public Map<String, String> initApiReport(ApiRunModeConfigDTO runModeConfig, List<TestPlanApiCase> testPlanApiCases,
|
||||
Map<String, ApiTestCase> caseMap, String userId) {
|
||||
List<ApiReport> apiReports = new ArrayList<>();
|
||||
List<ApiTestCaseRecord> apiTestCaseRecords = new ArrayList<>();
|
||||
List<ApiReportStep> apiReportSteps = new ArrayList<>();
|
||||
Map<String, String> resourceReportMap = new HashMap<>();
|
||||
|
||||
for (TestPlanApiCase testPlanApiCase : testPlanApiCases) {
|
||||
ApiTestCase apiTestCase = caseMap.get(testPlanApiCase.getApiCaseId());
|
||||
|
@ -341,10 +335,11 @@ public class TestPlanApiCaseBatchRunService {
|
|||
ApiTestCaseRecord apiTestCaseRecord = apiTestCaseService.getApiTestCaseRecord(apiTestCase, apiReport);
|
||||
apiTestCaseRecords.add(apiTestCaseRecord);
|
||||
apiReportSteps.add(getApiReportStep(testPlanApiCase.getId(), apiTestCase, apiReport.getId(), 1));
|
||||
resourceReportMap.put(testPlanApiCase.getId(), apiReport.getId());
|
||||
}
|
||||
apiReportService.insertApiReport(apiReports, apiTestCaseRecords);
|
||||
apiReportService.insertApiReportStep(apiReportSteps);
|
||||
return apiTestCaseRecords;
|
||||
return resourceReportMap;
|
||||
}
|
||||
|
||||
private ApiReport getApiReport(ApiRunModeConfigDTO runModeConfig, TestPlanApiCase testPlanApiCase, ApiTestCase apiTestCase, String userId) {
|
||||
|
|
|
@ -665,6 +665,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
TaskItem taskItem = request.getTaskItem();
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(taskItem.getResourceId());
|
||||
ApiTestCase apiTestCase = apiTestCaseMapper.selectByPrimaryKey(testPlanApiCase.getApiCaseId());
|
||||
apiTestCase.setEnvironmentId(testPlanApiCase.getEnvironmentId());
|
||||
return apiTestCaseService.getRunScript(request, apiTestCase);
|
||||
}
|
||||
|
||||
|
@ -684,12 +685,12 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
apiReportService.insertApiReport(List.of(apiReport), List.of(apiTestCaseRecord));
|
||||
|
||||
//初始化步骤
|
||||
apiReportService.insertApiReportStep(List.of(getApiReportStep(apiTestCase, reportId)));
|
||||
apiReportService.insertApiReportStep(List.of(getApiReportStep(testPlanApiCase, apiTestCase, reportId)));
|
||||
return apiTestCaseRecord;
|
||||
}
|
||||
|
||||
public ApiReportStep getApiReportStep(ApiTestCase apiTestCase, String reportId) {
|
||||
ApiReportStep apiReportStep = apiTestCaseService.getApiReportStep(apiTestCase, reportId, 1L);
|
||||
public ApiReportStep getApiReportStep(TestPlanApiCase testPlanApiCase, ApiTestCase apiTestCase, String reportId) {
|
||||
ApiReportStep apiReportStep = apiTestCaseService.getApiReportStep(testPlanApiCase.getId(), apiTestCase.getName(), reportId, 1L);
|
||||
apiReportStep.setStepType(ApiExecuteResourceType.TEST_PLAN_API_CASE.name());
|
||||
return apiReportStep;
|
||||
}
|
||||
|
|
|
@ -210,6 +210,7 @@ public class TestPlanApiScenarioBatchRunService {
|
|||
|
||||
TaskBatchRequestDTO taskRequest = getTaskBatchRequestDTO(projectId, runModeConfig);
|
||||
taskRequest.setTaskItems(taskItems);
|
||||
taskRequest.getTaskInfo().setUserId(userId);
|
||||
taskRequest.getTaskInfo().setParentQueueId(parentQueueId);
|
||||
|
||||
apiExecuteService.batchExecute(taskRequest);
|
||||
|
@ -250,6 +251,7 @@ public class TestPlanApiScenarioBatchRunService {
|
|||
Map<String, ApiScenario> apiScenarioMap, String userId) {
|
||||
List<ApiScenarioReport> apiScenarioReports = new ArrayList<>(testPlanApiScenarios.size());
|
||||
List<ApiScenarioRecord> apiScenarioRecords = new ArrayList<>(testPlanApiScenarios.size());
|
||||
Map<String, String> resourceReportMap = new HashMap<>();
|
||||
for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) {
|
||||
ApiScenario apiScenario = apiScenarioMap.get(testPlanApiScenario.getApiScenarioId());
|
||||
// 初始化报告
|
||||
|
@ -259,9 +261,10 @@ public class TestPlanApiScenarioBatchRunService {
|
|||
// 创建报告和用例的关联关系
|
||||
ApiScenarioRecord apiScenarioRecord = apiScenarioRunService.getApiScenarioRecord(apiScenario, apiScenarioReport);
|
||||
apiScenarioRecords.add(apiScenarioRecord);
|
||||
resourceReportMap.put(testPlanApiScenario.getId(), apiScenarioReport.getId());
|
||||
}
|
||||
apiScenarioReportService.insertApiScenarioReport(apiScenarioReports, apiScenarioRecords);
|
||||
return apiScenarioRecords.stream().collect(Collectors.toMap(ApiScenarioRecord::getApiScenarioId, ApiScenarioRecord::getApiScenarioReportId));
|
||||
return resourceReportMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,6 +285,7 @@ public class TestPlanApiScenarioBatchRunService {
|
|||
TaskItem taskItem = apiExecuteService.getTaskItem(reportId, queueDetail.getResourceId());
|
||||
taskRequest.setTaskItem(taskItem);
|
||||
taskRequest.getTaskInfo().setQueueId(queue.getQueueId());
|
||||
taskRequest.getTaskInfo().setUserId(queue.getUserId());
|
||||
taskRequest.getTaskInfo().setParentQueueId(queue.getParentQueueId());
|
||||
|
||||
apiExecuteService.execute(taskRequest);
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.domain.ApiScenarioExample;
|
|||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.domain.ApiScenarioReportExample;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioDetail;
|
||||
import io.metersphere.api.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportMapper;
|
||||
import io.metersphere.api.service.ApiBatchRunBaseService;
|
||||
|
@ -335,6 +336,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
|||
public GetRunScriptResult getRunScript(GetRunScriptRequest request) {
|
||||
TaskItem taskItem = request.getTaskItem();
|
||||
TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(taskItem.getResourceId());
|
||||
ApiScenarioDetail apiScenarioDetail = apiScenarioRunService.getForRun(testPlanApiScenario.getApiScenarioId());
|
||||
apiScenarioDetail.setEnvironmentId(testPlanApiScenario.getEnvironmentId());
|
||||
apiScenarioDetail.setGrouped(testPlanApiScenario.getGrouped());
|
||||
return apiScenarioRunService.getRunScript(request, testPlanApiScenario.getApiScenarioId());
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,11 @@ public class TestPlanExecuteService {
|
|||
@Resource
|
||||
private TestPlanCollectionMapper testPlanCollectionMapper;
|
||||
@Resource
|
||||
private TestPlanApiCasePlanRunService testPlanApiCasePlanRunService;
|
||||
private PlanRunTestPlanApiCaseService planRunTestPlanApiCaseService;
|
||||
@Resource
|
||||
private TestPlanApiScenarioPlanRunService testPlanApiScenarioPlanRunService;
|
||||
private PlanRunTestPlanApiScenarioService planRunTestPlanApiScenarioService;
|
||||
@Resource
|
||||
private TestPlanApiBatchRunBaseService testPlanApiBatchRunBaseService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
@ -388,17 +390,19 @@ public class TestPlanExecuteService {
|
|||
try {
|
||||
boolean isFinish = false;
|
||||
TestPlanCollection collection = JSON.parseObject(testPlanExecutionQueue.getTestPlanCollectionJson(), TestPlanCollection.class);
|
||||
TestPlanCollection extendedRootCollection = testPlanApiBatchRunBaseService.getExtendedRootCollection(collection);
|
||||
String executeMethod = extendedRootCollection == null ? collection.getExecuteMethod() : extendedRootCollection.getExecuteMethod();
|
||||
if (StringUtils.equalsIgnoreCase(collection.getType(), CaseType.API_CASE.getKey())) {
|
||||
if (StringUtils.equals(collection.getExecuteMethod(), ApiBatchRunMode.PARALLEL.name())) {
|
||||
isFinish = testPlanApiCasePlanRunService.parallelExecute(testPlanExecutionQueue);
|
||||
if (StringUtils.equals(executeMethod, ApiBatchRunMode.PARALLEL.name())) {
|
||||
isFinish = planRunTestPlanApiCaseService.parallelExecute(testPlanExecutionQueue);
|
||||
} else {
|
||||
isFinish = testPlanApiCasePlanRunService.serialExecute(testPlanExecutionQueue);
|
||||
isFinish = planRunTestPlanApiCaseService.serialExecute(testPlanExecutionQueue);
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(collection.getType(), CaseType.SCENARIO_CASE.getKey())) {
|
||||
if (StringUtils.equals(collection.getExecuteMethod(), ApiBatchRunMode.PARALLEL.name())) {
|
||||
isFinish = testPlanApiScenarioPlanRunService.parallelExecute(testPlanExecutionQueue);
|
||||
if (StringUtils.equals(executeMethod, ApiBatchRunMode.PARALLEL.name())) {
|
||||
isFinish = planRunTestPlanApiScenarioService.parallelExecute(testPlanExecutionQueue);
|
||||
} else {
|
||||
isFinish = testPlanApiScenarioPlanRunService.serialExecute(testPlanExecutionQueue);
|
||||
isFinish = planRunTestPlanApiScenarioService.serialExecute(testPlanExecutionQueue);
|
||||
}
|
||||
}
|
||||
if (isFinish) {
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.apache.ibatis.session.SqlSession;
|
|||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -220,10 +222,12 @@ public class TestPlanReportService {
|
|||
|
||||
/**
|
||||
* 执行生成报告
|
||||
* 新开事务,避免异步执行查不到数据
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @param currentUser 当前用户
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public Map<String, String> genReportByExecution(String prepareReportId,TestPlanReportGenRequest request, String currentUser) {
|
||||
return genReport(prepareReportId,request, false, currentUser, "/test-plan/report/gen");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue