refactor(接口自动化): 优化部分代码

This commit is contained in:
fit2-zhao 2021-05-07 15:48:08 +08:00 committed by fit2-zhao
parent d62c155df6
commit 6bf4b4a308
5 changed files with 13 additions and 16 deletions

View File

@ -16,6 +16,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.FileUtils;
import lombok.Data; import lombok.Data;
@ -122,7 +123,7 @@ public class MsScenario extends MsTestElement {
this.environmentMap = new HashMap<>(16); this.environmentMap = new HashMap<>(16);
if (StringUtils.isNotBlank(environmentId)) { if (StringUtils.isNotBlank(environmentId)) {
// 兼容1.8之前 没有environmentMap但有environmentId的数据 // 兼容1.8之前 没有environmentMap但有environmentId的数据
this.environmentMap.put("historyProjectID", environmentId); this.environmentMap.put(RunModeConstants.HIS_PRO_ID.toString(), environmentId);
} }
} }
if (this.environmentMap != null && !this.environmentMap.isEmpty()) { if (this.environmentMap != null && !this.environmentMap.isEmpty()) {

View File

@ -147,12 +147,6 @@ public abstract class MsTestElement {
return jmeterTestPlanHashTree; return jmeterTestPlanHashTree;
} }
public HashTree generateHashTree() {
HashTree jmeterTestPlanHashTree = new ListedHashTree();
this.toHashTree(jmeterTestPlanHashTree, this.hashTree, new ParameterConfig());
return jmeterTestPlanHashTree;
}
public Arguments addArguments(ParameterConfig config) { public Arguments addArguments(ParameterConfig config) {
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {

View File

@ -23,6 +23,7 @@ import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.commons.constants.ConditionType; import io.metersphere.commons.constants.ConditionType;
import io.metersphere.commons.constants.DelimiterConstants; import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -185,22 +186,22 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
// 数据兼容处理 // 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) { if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据 // 1.8 前后 混合数据
this.setProjectId(getParentProjectId()); this.setProjectId(getParentProjectId());
} else if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
// 1.8 之后 当前正常数据
} else { } else {
// 1.8 之前 数据 // 1.8 之前 数据
if (config.getConfig() != null) { if (config.getConfig() != null) {
if (config.getConfig().containsKey("historyProjectID")) { if (!config.getConfig().containsKey(RunModeConstants.HIS_PRO_ID.toString())) {
this.setProjectId("historyProjectID");
} else {
// 测试计划执行 // 测试计划执行
Iterator<String> it = config.getConfig().keySet().iterator(); Iterator<String> it = config.getConfig().keySet().iterator();
if (it.hasNext()) { if (it.hasNext()) {
this.setProjectId(it.next()); this.setProjectId(it.next());
} }
} else {
this.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
} }
} }
} }

View File

@ -20,6 +20,7 @@ import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants; import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -91,8 +92,8 @@ public class MsJDBCSampler extends MsTestElement {
} else { } else {
// 1.8 之前 数据 // 1.8 之前 数据
if (config.getConfig() != null) { if (config.getConfig() != null) {
if (config.getConfig().containsKey("historyProjectID")) { if (config.getConfig().containsKey(RunModeConstants.HIS_PRO_ID.toString())) {
this.setProjectId("historyProjectID"); this.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
} else { } else {
// 测试计划执行 // 测试计划执行
Iterator<String> it = config.getConfig().keySet().iterator(); Iterator<String> it = config.getConfig().keySet().iterator();

View File

@ -2,7 +2,7 @@ package io.metersphere.commons.constants;
public enum RunModeConstants { public enum RunModeConstants {
SERIAL("serial"), SET_REPORT("setReport"), PARALLEL("parallel"); SERIAL("serial"), SET_REPORT("setReport"), PARALLEL("parallel"), HIS_PRO_ID("historyProjectID");
private String value; private String value;