refactor(测试跟踪): 测试计划保存的配置信息的运行环境信息用于默认值

--user=郭雨琦
This commit is contained in:
guoyuqi 2022-08-02 11:25:22 +08:00 committed by xiaomeinvG
parent bcca8cae07
commit 118575abb9
3 changed files with 24 additions and 22 deletions

View File

@ -215,6 +215,12 @@ public class TestPlanController {
return testPlanService.runPlan(testplanRunRequest); return testPlanService.runPlan(testplanRunRequest);
} }
@PostMapping("/run/save")
public String runAndSave(@RequestBody TestPlanRunRequest testplanRunRequest) {
testPlanService.updateRunModeConfig(testplanRunRequest);
return testPlanService.runPlan(testplanRunRequest);
}
@PostMapping(value = "/run/batch") @PostMapping(value = "/run/batch")
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class) @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class)
public void runBatch(@RequestBody TestPlanRunRequest request) { public void runBatch(@RequestBody TestPlanRunRequest request) {

View File

@ -975,30 +975,27 @@ public class TestPlanService {
LogUtil.error(e); LogUtil.error(e);
} }
if (runModeConfig == null) { if (runModeConfig == null) {
runModeConfig = buildRunModeConfigDTO();
}
//环境参数为空时依据测试计划保存的环境执行
if ((StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && StringUtils.isBlank(runModeConfig.getEnvironmentGroupId()))
|| (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()))) {
TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanID); TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanID);
if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) {
JSONObject json = JSONObject.parseObject(testPlanWithBLOBs.getRunModeConfig()); try {
TestPlanRequestUtil.changeStringToBoolean(json); JSONObject json = JSONObject.parseObject(testPlanWithBLOBs.getRunModeConfig());
TestPlanRunRequest testPlanRunRequest = JSON.toJavaObject(json, TestPlanRunRequest.class); TestPlanRequestUtil.changeStringToBoolean(json);
if (StringUtils.equals("GROUP", testPlanRunRequest.getEnvironmentType()) && StringUtils.isBlank(testPlanRunRequest.getEnvironmentGroupId())) { TestPlanRunRequest testPlanRunRequest = JSON.toJavaObject(json, TestPlanRunRequest.class);
runModeConfig = buildRunModeConfigDTO(); if (testPlanRunRequest != null) {
} else { String envType = testPlanRunRequest.getEnvironmentType();
runModeConfig = new RunModeConfigDTO(); Map<String, String> envMap = testPlanRunRequest.getEnvMap();
runModeConfig.setMode(testPlanRunRequest.getMode()); String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId();
runModeConfig.setReportType(testPlanRunRequest.getReportType()); runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanID);
if (testPlanRunRequest.getEnvMap() == null) {
runModeConfig.setEnvMap(new HashMap<>());
} else {
runModeConfig.setEnvMap(testPlanRunRequest.getEnvMap());
} }
runModeConfig.setOnSampleError(testPlanRunRequest.isOnSampleError()); } catch (Exception e) {
LogUtil.error("获取测试计划保存的环境信息出错!", e);
} }
} else {
runModeConfig = buildRunModeConfigDTO();
}
} else {
if (runModeConfig.getEnvMap() == null) {
runModeConfig.setEnvMap(new HashMap<>());
} }
} }
if (planReportId == null) { if (planReportId == null) {
@ -2129,7 +2126,6 @@ public class TestPlanService {
String testPlanId = testplanRunRequest.getTestPlanId(); String testPlanId = testplanRunRequest.getTestPlanId();
RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId); RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId);
String apiRunConfig = JSONObject.toJSONString(runModeConfig); String apiRunConfig = JSONObject.toJSONString(runModeConfig);
updatePlan(testplanRunRequest, testPlanId);
return this.run(testPlanId, testplanRunRequest.getProjectId(), return this.run(testPlanId, testplanRunRequest.getProjectId(),
testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), testplanRunRequest.getReportId(), apiRunConfig); testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), testplanRunRequest.getReportId(), apiRunConfig);

View File

@ -814,7 +814,7 @@ export default {
param.headlessEnabled = config.headlessEnabled; param.headlessEnabled = config.headlessEnabled;
if (config.isRun === true) { if (config.isRun === true) {
this.$refs.taskCenter.open(); this.$refs.taskCenter.open();
this.result = this.$post('test/plan/run/', param, () => { this.result = this.$post('test/plan/run/save', param, () => {
this.$success(this.$t('commons.run_success')); this.$success(this.$t('commons.run_success'));
}); });
} else { } else {