mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 03:58:33 +08:00
refactor(接口测试): 测试计划关联接口用例执行时生成脚本优化
This commit is contained in:
parent
559b3140bf
commit
cf0b10adf1
@ -83,23 +83,21 @@ public class ApiCaseExecuteService {
|
||||
if (StringUtils.equals(EnvironmentType.GROUP.toString(), request.getConfig().getEnvironmentType()) && StringUtils.isNotEmpty(request.getConfig().getEnvironmentGroupId())) {
|
||||
request.getConfig().setEnvMap(environmentGroupProjectService.getEnvMap(request.getConfig().getEnvironmentGroupId()));
|
||||
}
|
||||
LoggerUtil.debug("开始查询测试计划用例");
|
||||
LoggerUtil.info("开始查询测试计划用例", request.getPlanIds().size());
|
||||
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria().andIdIn(request.getPlanIds());
|
||||
example.setOrderByClause("`order` DESC");
|
||||
List<TestPlanApiCase> planApiCases = testPlanApiCaseMapper.selectByExample(example);
|
||||
List<TestPlanApiCase> planApiCases = this.selectByPlanApiCaseIds(request.getPlanIds());
|
||||
if (CollectionUtils.isEmpty(planApiCases)) {
|
||||
return responseDTOS;
|
||||
}
|
||||
if (StringUtils.isEmpty(request.getTriggerMode())) {
|
||||
request.setTriggerMode(ApiRunMode.API_PLAN.name());
|
||||
}
|
||||
LoggerUtil.debug("查询到测试计划用例 " + planApiCases.size());
|
||||
LoggerUtil.info("查询到测试计划用例 " + planApiCases.size());
|
||||
|
||||
Map<String, ApiDefinitionExecResultWithBLOBs> executeQueue = request.isRerun() ? request.getExecuteQueue() : new LinkedHashMap<>();
|
||||
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? ApiReportStatus.PENDING.name()
|
||||
: ApiReportStatus.RUNNING.name();
|
||||
|
||||
String status = StringUtils.equals(request.getConfig().getMode(), RunModeConstants.SERIAL.toString())
|
||||
? ApiReportStatus.PENDING.name() : ApiReportStatus.RUNNING.name();
|
||||
|
||||
// 查出用例
|
||||
List<String> apiCaseIds = planApiCases.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
|
||||
@ -117,23 +115,24 @@ public class ApiCaseExecuteService {
|
||||
//处理环境配置为空时的情况
|
||||
RunModeConfigDTO runModeConfigDTO = new RunModeConfigDTO();
|
||||
BeanUtils.copyBean(runModeConfigDTO, request.getConfig());
|
||||
if (MapUtils.isEmpty(runModeConfigDTO.getEnvMap())) {
|
||||
ApiTestCase testCase = caseMap.get(testPlanApiCase.getApiCaseId());
|
||||
if (testCase != null) {
|
||||
runModeConfigDTO.setEnvMap(new HashMap<>() {{
|
||||
this.put(testCase.getProjectId(), testPlanApiCase.getEnvironmentId());
|
||||
}});
|
||||
}
|
||||
ApiTestCase testCase = caseMap.get(testPlanApiCase.getApiCaseId());
|
||||
if (testCase == null) {
|
||||
continue;
|
||||
}
|
||||
ApiDefinitionExecResultWithBLOBs report = ApiDefinitionExecResultUtil.addResult(request, runModeConfigDTO, testPlanApiCase, status, caseMap, resourcePoolId);
|
||||
if (MapUtils.isEmpty(runModeConfigDTO.getEnvMap())) {
|
||||
runModeConfigDTO.setEnvMap(new HashMap<>() {{
|
||||
this.put(testCase.getProjectId(), testPlanApiCase.getEnvironmentId());
|
||||
}});
|
||||
}
|
||||
ApiDefinitionExecResultWithBLOBs report = ApiDefinitionExecResultUtil.addResult(request, runModeConfigDTO, testPlanApiCase, status, testCase, resourcePoolId);
|
||||
executeQueue.put(testPlanApiCase.getId(), report);
|
||||
responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode()));
|
||||
LoggerUtil.debug("预生成测试用例结果报告:" + report.getName() + ", ID " + report.getId());
|
||||
LoggerUtil.info("预生成测试用例结果报告:" + report.getName(), report.getId());
|
||||
}
|
||||
apiCaseResultService.batchSave(executeQueue);
|
||||
}
|
||||
|
||||
LoggerUtil.debug("开始生成测试计划队列");
|
||||
LoggerUtil.info("开始生成测试计划队列");
|
||||
String reportType = request.getConfig().getReportType();
|
||||
String poolId = request.getConfig().getResourcePoolId();
|
||||
String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name();
|
||||
@ -157,6 +156,16 @@ public class ApiCaseExecuteService {
|
||||
return responseDTOS;
|
||||
}
|
||||
|
||||
public List<TestPlanApiCase> selectByPlanApiCaseIds(List<String> planApiCaseIds) {
|
||||
if (CollectionUtils.isEmpty(planApiCaseIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
TestPlanApiCaseExample example = new TestPlanApiCaseExample();
|
||||
example.createCriteria().andIdIn(planApiCaseIds);
|
||||
example.setOrderByClause("`order` DESC");
|
||||
return testPlanApiCaseMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public Map<String, List<String>> checkEnv(List<ApiTestCaseWithBLOBs> caseList) {
|
||||
Map<String, List<String>> projectEnvMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(caseList)) {
|
||||
|
@ -8,10 +8,10 @@ import io.metersphere.base.domain.TestPlanApiCase;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ReportTypeConstants;
|
||||
import io.metersphere.commons.constants.TriggerMode;
|
||||
import io.metersphere.commons.enums.StorageEnums;
|
||||
import io.metersphere.dto.RunModeConfigDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -27,7 +27,7 @@ public class ApiDefinitionExecResultUtil {
|
||||
apiResult.setStartTime(System.currentTimeMillis());
|
||||
apiResult.setEndTime(System.currentTimeMillis());
|
||||
apiResult.setTriggerMode(TriggerMode.BATCH.name());
|
||||
apiResult.setActuator("LOCAL");
|
||||
apiResult.setActuator(StorageEnums.LOCAL.name());
|
||||
if (config != null && GenerateHashTreeUtil.isResourcePool(config.getResourcePoolId()).isPool()) {
|
||||
apiResult.setActuator(config.getResourcePoolId());
|
||||
}
|
||||
@ -42,31 +42,33 @@ public class ApiDefinitionExecResultUtil {
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public static ApiDefinitionExecResultWithBLOBs addResult(BatchRunDefinitionRequest request, RunModeConfigDTO runModeConfigDTO, TestPlanApiCase key, String status,
|
||||
Map<String, ApiTestCase> caseMap, String poolId) {
|
||||
public static ApiDefinitionExecResultWithBLOBs addResult(
|
||||
BatchRunDefinitionRequest request,
|
||||
RunModeConfigDTO runModeConfigDTO,
|
||||
TestPlanApiCase key,
|
||||
String status,
|
||||
ApiTestCase testCase,
|
||||
String poolId) {
|
||||
|
||||
ApiDefinitionExecResultWithBLOBs apiResult = new ApiDefinitionExecResultWithBLOBs();
|
||||
apiResult.setId(UUID.randomUUID().toString());
|
||||
apiResult.setCreateTime(System.currentTimeMillis());
|
||||
apiResult.setStartTime(System.currentTimeMillis());
|
||||
apiResult.setEndTime(System.currentTimeMillis());
|
||||
apiResult.setReportType(ReportTypeConstants.API_INDEPENDENT.name());
|
||||
ApiTestCase testCase = caseMap.get(key.getApiCaseId());
|
||||
if (testCase != null) {
|
||||
apiResult.setName(testCase.getName());
|
||||
apiResult.setProjectId(testCase.getProjectId());
|
||||
apiResult.setVersionId(testCase.getVersionId());
|
||||
}
|
||||
apiResult.setTriggerMode(request.getTriggerMode());
|
||||
apiResult.setActuator("LOCAL");
|
||||
apiResult.setActuator(StorageEnums.LOCAL.name());
|
||||
if (StringUtils.isNotEmpty(poolId)) {
|
||||
apiResult.setActuator(poolId);
|
||||
}
|
||||
if (StringUtils.isEmpty(request.getUserId())) {
|
||||
if (SessionUtils.getUser() != null) {
|
||||
apiResult.setUserId(SessionUtils.getUser().getId());
|
||||
}
|
||||
} else {
|
||||
apiResult.setUserId(request.getUserId());
|
||||
apiResult.setUserId(request.getUserId());
|
||||
if (StringUtils.isEmpty(apiResult.getUserId())) {
|
||||
apiResult.setUserId(SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
apiResult.setResourceId(key.getId());
|
||||
@ -92,7 +94,7 @@ public class ApiDefinitionExecResultUtil {
|
||||
apiResult.setStartTime(System.currentTimeMillis());
|
||||
apiResult.setEndTime(System.currentTimeMillis());
|
||||
apiResult.setTriggerMode(TriggerMode.BATCH.name());
|
||||
apiResult.setActuator("LOCAL");
|
||||
apiResult.setActuator(StorageEnums.LOCAL.name());
|
||||
apiResult.setUserId(userId);
|
||||
apiResult.setResourceId(resourceId);
|
||||
apiResult.setStartTime(System.currentTimeMillis());
|
||||
|
@ -26,6 +26,7 @@ import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.*;
|
||||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.enums.StorageEnums;
|
||||
import io.metersphere.commons.enums.*;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
@ -997,7 +998,7 @@ public class ApiDefinitionService {
|
||||
apiReportEnvConfig.setResourcePoolName(resourcePool.getName());
|
||||
}
|
||||
} else {
|
||||
apiReportEnvConfig.setResourcePoolName("LOCAL");
|
||||
apiReportEnvConfig.setResourcePoolName(StorageEnums.LOCAL.name());
|
||||
}
|
||||
return apiReportEnvConfig;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
|
||||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.enums.StorageEnums;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.NodeDTO;
|
||||
@ -203,7 +204,7 @@ public class ExtApiTaskService extends TaskService {
|
||||
if (StringUtils.isEmpty(reportId)) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(actuator) && !StringUtils.equals(actuator, "LOCAL")) {
|
||||
if (StringUtils.isNotEmpty(actuator) && !StringUtils.equals(actuator, StorageEnums.LOCAL.name())) {
|
||||
if (poolMap.containsKey(actuator)) {
|
||||
poolMap.get(actuator).add(reportId);
|
||||
} else {
|
||||
|
@ -790,7 +790,7 @@ public class ApiScenarioReportService {
|
||||
if (initModel.getConfig() != null && StringUtils.isNotBlank(initModel.getConfig().getResourcePoolId())) {
|
||||
report.setActuator(initModel.getConfig().getResourcePoolId());
|
||||
} else {
|
||||
report.setActuator("LOCAL");
|
||||
report.setActuator(StorageEnums.LOCAL.name());
|
||||
}
|
||||
report.setTriggerMode(initModel.getTriggerMode());
|
||||
report.setReportVersion(2);
|
||||
|
@ -10,6 +10,7 @@ import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.constants.ReportTypeConstants;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.enums.StorageEnums;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
import io.metersphere.dto.RequestResult;
|
||||
@ -714,7 +715,7 @@ public class ApiScenarioReportStructureService {
|
||||
dto.setPoolName(resourcePool.getName());
|
||||
}
|
||||
} else {
|
||||
dto.setPoolName("LOCAL");
|
||||
dto.setPoolName(StorageEnums.LOCAL.name());
|
||||
}
|
||||
if (runModeConfigDTO != null && StringUtils.isNotBlank(runModeConfigDTO.getMode())) {
|
||||
dto.setMode(runModeConfigDTO.getMode());
|
||||
|
@ -19,6 +19,7 @@ import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ElementConstants;
|
||||
import io.metersphere.commons.constants.ReportTypeConstants;
|
||||
import io.metersphere.commons.enums.ApiReportStatus;
|
||||
import io.metersphere.commons.enums.StorageEnums;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.constants.RunModeConstants;
|
||||
@ -111,7 +112,7 @@ public class ApiScenarioRerunService {
|
||||
config.setMode(RunModeConstants.PARALLEL.toString());
|
||||
}
|
||||
config.setReportType(RunModeConstants.SET_REPORT.toString());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reportResults.get(0).getActuator(), "LOCAL")) {
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reportResults.get(0).getActuator(), StorageEnums.LOCAL.name())) {
|
||||
config.setResourcePoolId(reportResults.get(0).getActuator());
|
||||
}
|
||||
request.setConfig(config);
|
||||
@ -165,7 +166,7 @@ public class ApiScenarioRerunService {
|
||||
config.setMode(RunModeConstants.PARALLEL.toString());
|
||||
}
|
||||
config.setReportName(reportDTO.getName());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reportDTO.getActuator(), "LOCAL")) {
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reportDTO.getActuator(), StorageEnums.LOCAL.name())) {
|
||||
config.setResourcePoolId(reportDTO.getActuator());
|
||||
}
|
||||
config.setReportType(RunModeConstants.SET_REPORT.toString());
|
||||
@ -241,7 +242,7 @@ public class ApiScenarioRerunService {
|
||||
continue;
|
||||
}
|
||||
runModeConfig.setReportType(report.getReportType());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(report.getActuator(), "LOCAL")) {
|
||||
if (!StringUtils.equalsAnyIgnoreCase(report.getActuator(), StorageEnums.LOCAL.name())) {
|
||||
runModeConfig.setResourcePoolId(report.getActuator());
|
||||
}
|
||||
executeQueue.put(testPlanApiCase.getId(), report);
|
||||
@ -293,7 +294,7 @@ public class ApiScenarioRerunService {
|
||||
// 执行配置
|
||||
RunModeConfigDTO config = new RunModeConfigDTO();
|
||||
config.setMode(RunModeConstants.PARALLEL.toString());
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reports.get(0).getActuator(), "LOCAL")) {
|
||||
if (!StringUtils.equalsAnyIgnoreCase(reports.get(0).getActuator(), StorageEnums.LOCAL.name())) {
|
||||
config.setResourcePoolId(reports.get(0).getActuator());
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
<font-awesome-icon class="icon global focusing" :icon="['fas', 'tasks']"/>
|
||||
</el-badge>
|
||||
</div>
|
||||
<font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']" v-else/>
|
||||
<font-awesome-icon @click="open('API')" class="icon global focusing" :icon="['fas', 'tasks']" v-else/>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<el-drawer
|
||||
@ -300,6 +300,7 @@ export default {
|
||||
this.activeName = activeName;
|
||||
}
|
||||
this.init(true);
|
||||
this.taskVisible = true;
|
||||
setTimeout(this.showTaskCenter, 2000);
|
||||
},
|
||||
getPercentage(status) {
|
||||
|
Loading…
Reference in New Issue
Block a user