提交 de897cb7 编写于 作者: S shiziyuan9527 提交者: BugKing

refactor(场景自动化): 兼容历史数据

上级 57e5adb2
......@@ -89,6 +89,7 @@ public class MsScenario extends MsTestElement {
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
this.setName(scenario.getName());
this.setProjectId(scenario.getProjectId());
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
});
// 场景变量
......
......@@ -126,8 +126,14 @@ public class MsHTTPSamplerProxy extends MsTestElement {
config.setConfig(getEnvironmentConfig(useEnvironment));
}
// 1.8 之前历史数据
if (StringUtils.isEmpty(this.getProjectId()) && config.getConfig() != null && !config.getConfig().isEmpty()) {
// 数据兼容处理
if(config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())){
// 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据
this.setProjectId(getParentProjectId());
} else {
// 1.8 之前 数据
this.setProjectId("historyProjectID");
}
......@@ -279,6 +285,17 @@ public class MsHTTPSamplerProxy extends MsTestElement {
return false;
}
private String getParentProjectId() {
MsTestElement parent = this.getParent();
while(parent != null) {
if (StringUtils.isNotBlank(parent.getProjectId())) {
return parent.getProjectId();
}
parent = parent.getParent();
}
return "";
}
private String getRestParameters(String path) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(path);
......
......@@ -409,6 +409,7 @@ public class ApiAutomationService {
} else if (StringUtils.equals(tr.getType(), "scenario")) {
if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
env.getProjectIds().add(apiScenario.getProjectId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
......@@ -432,6 +433,7 @@ public class ApiAutomationService {
if (!tr.isEnable()) {
continue;
}
env.getProjectIds().add(tr.getProjectId());
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env);
}
......@@ -476,6 +478,7 @@ public class ApiAutomationService {
} else if (StringUtils.equals(tr.getType(), "scenario")) {
if (tr.isEnable()) {
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
env.getProjectIds().add(apiScenario.getProjectId());
String scenarioDefinition = apiScenario.getScenarioDefinition();
JSONObject element1 = JSON.parseObject(scenarioDefinition);
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
......@@ -499,6 +502,7 @@ public class ApiAutomationService {
if (!tr.isEnable()) {
continue;
}
env.getProjectIds().add(tr.getProjectId());
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
getHashTree(tr.getHashTree(), env);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册