refactor(场景自动化): 兼容历史数据
This commit is contained in:
parent
57e5adb222
commit
de897cb7c5
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue