refactor(场景自动化): 兼容历史数据
This commit is contained in:
parent
cb6ca38e78
commit
654b2e9159
|
@ -89,6 +89,7 @@ public class MsScenario extends MsTestElement {
|
||||||
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
||||||
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
JSONObject element = JSON.parseObject(scenario.getScenarioDefinition());
|
||||||
this.setName(scenario.getName());
|
this.setName(scenario.getName());
|
||||||
|
this.setProjectId(scenario.getProjectId());
|
||||||
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
hashTree = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
|
||||||
});
|
});
|
||||||
// 场景变量
|
// 场景变量
|
||||||
|
|
|
@ -126,8 +126,14 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
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");
|
this.setProjectId("historyProjectID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +285,17 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
return false;
|
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) {
|
private String getRestParameters(String path) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append(path);
|
stringBuffer.append(path);
|
||||||
|
|
|
@ -409,6 +409,7 @@ public class ApiAutomationService {
|
||||||
} else if (StringUtils.equals(tr.getType(), "scenario")) {
|
} else if (StringUtils.equals(tr.getType(), "scenario")) {
|
||||||
if (tr.isEnable()) {
|
if (tr.isEnable()) {
|
||||||
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
|
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
|
||||||
|
env.getProjectIds().add(apiScenario.getProjectId());
|
||||||
String scenarioDefinition = apiScenario.getScenarioDefinition();
|
String scenarioDefinition = apiScenario.getScenarioDefinition();
|
||||||
JSONObject element1 = JSON.parseObject(scenarioDefinition);
|
JSONObject element1 = JSON.parseObject(scenarioDefinition);
|
||||||
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
|
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
|
||||||
|
@ -432,6 +433,7 @@ public class ApiAutomationService {
|
||||||
if (!tr.isEnable()) {
|
if (!tr.isEnable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
env.getProjectIds().add(tr.getProjectId());
|
||||||
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
|
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
|
||||||
getHashTree(tr.getHashTree(), env);
|
getHashTree(tr.getHashTree(), env);
|
||||||
}
|
}
|
||||||
|
@ -476,6 +478,7 @@ public class ApiAutomationService {
|
||||||
} else if (StringUtils.equals(tr.getType(), "scenario")) {
|
} else if (StringUtils.equals(tr.getType(), "scenario")) {
|
||||||
if (tr.isEnable()) {
|
if (tr.isEnable()) {
|
||||||
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
|
ApiScenarioDTO apiScenario = getApiScenario(tr.getId());
|
||||||
|
env.getProjectIds().add(apiScenario.getProjectId());
|
||||||
String scenarioDefinition = apiScenario.getScenarioDefinition();
|
String scenarioDefinition = apiScenario.getScenarioDefinition();
|
||||||
JSONObject element1 = JSON.parseObject(scenarioDefinition);
|
JSONObject element1 = JSON.parseObject(scenarioDefinition);
|
||||||
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
|
LinkedList<MsTestElement> hashTree1 = mapper.readValue(element1.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>(){});
|
||||||
|
@ -499,6 +502,7 @@ public class ApiAutomationService {
|
||||||
if (!tr.isEnable()) {
|
if (!tr.isEnable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
env.getProjectIds().add(tr.getProjectId());
|
||||||
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
|
if (CollectionUtils.isNotEmpty(tr.getHashTree())) {
|
||||||
getHashTree(tr.getHashTree(), env);
|
getHashTree(tr.getHashTree(), env);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue