refactor(接口测试): 优化引用场景加载处理,减少前后端交互
This commit is contained in:
parent
d544daeee4
commit
a44605376b
|
@ -175,7 +175,7 @@ public class ApiAutomationController {
|
|||
|
||||
@GetMapping("/getApiScenario/{id}")
|
||||
public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) {
|
||||
return apiAutomationService.getApiScenario(id);
|
||||
return apiAutomationService.getNewApiScenario(id);
|
||||
}
|
||||
|
||||
@PostMapping("/getApiScenarioEnv")
|
||||
|
|
|
@ -665,6 +665,58 @@ public class ApiAutomationService {
|
|||
return extApiScenarioMapper.selectById(id);
|
||||
}
|
||||
|
||||
public ApiScenarioDTO getNewApiScenario(String id) {
|
||||
ApiScenarioDTO scenarioWithBLOBs = extApiScenarioMapper.selectById(id);
|
||||
if (scenarioWithBLOBs != null && StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
|
||||
JSONObject element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
this.dataFormatting(element);
|
||||
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(element));
|
||||
}
|
||||
return scenarioWithBLOBs;
|
||||
}
|
||||
|
||||
public void dataFormatting(JSONArray hashTree) {
|
||||
for (int i = 0; i < hashTree.size(); i++) {
|
||||
JSONObject element = hashTree.getJSONObject(i);
|
||||
if (element != null && StringUtils.equalsIgnoreCase(element.getString("type"), "scenario")) {
|
||||
ApiScenarioDTO scenarioWithBLOBs = extApiScenarioMapper.selectById(element.getString("id"));
|
||||
if (scenarioWithBLOBs != null && StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
element.put("referenced", "REF");
|
||||
}
|
||||
element.put("num", scenarioWithBLOBs.getNum());
|
||||
element.put("versionName", scenarioWithBLOBs.getVersionName());
|
||||
element.put("versionEnable", scenarioWithBLOBs.getVersionEnable());
|
||||
hashTree.set(i, element);
|
||||
}
|
||||
}
|
||||
if (element.containsKey("hashTree")) {
|
||||
JSONArray elementJSONArray = element.getJSONArray("hashTree");
|
||||
dataFormatting(elementJSONArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dataFormatting(JSONObject element) {
|
||||
if (element != null && StringUtils.equalsIgnoreCase(element.getString("type"), "scenario")) {
|
||||
ApiScenarioDTO scenarioWithBLOBs = extApiScenarioMapper.selectById(element.getString("id"));
|
||||
if (scenarioWithBLOBs != null && StringUtils.isNotEmpty(scenarioWithBLOBs.getScenarioDefinition())) {
|
||||
if (StringUtils.equalsIgnoreCase(element.getString("referenced"), "REF")) {
|
||||
element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition());
|
||||
element.put("referenced", "REF");
|
||||
}
|
||||
element.put("num", scenarioWithBLOBs.getNum());
|
||||
element.put("versionName", scenarioWithBLOBs.getVersionName());
|
||||
element.put("versionEnable", scenarioWithBLOBs.getVersionEnable());
|
||||
}
|
||||
}
|
||||
if (element != null && element.containsKey("hashTree")) {
|
||||
JSONArray elementJSONArray = element.getJSONArray("hashTree");
|
||||
dataFormatting(elementJSONArray);
|
||||
}
|
||||
}
|
||||
|
||||
public String setDomain(ApiScenarioEnvRequest request) {
|
||||
Boolean enable = request.getEnvironmentEnable();
|
||||
String scenarioDefinition = request.getDefinition();
|
||||
|
|
|
@ -119,60 +119,13 @@ export default {
|
|||
created() {
|
||||
if (this.scenario.num) {
|
||||
this.isShowNum = true;
|
||||
this.getWorkspaceId(this.scenario.projectId);
|
||||
} else {
|
||||
this.isSameSpace = false;
|
||||
}
|
||||
if (!this.scenario.projectId) {
|
||||
this.scenario.projectId = getCurrentProjectID();
|
||||
}
|
||||
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) {
|
||||
let scenarios = JSON.parse(JSON.stringify(this.scenario.hashTree));
|
||||
let map = new Map();
|
||||
this.formatResult(map, scenarios);
|
||||
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
|
||||
if (response.data) {
|
||||
this.scenario.loaded = true;
|
||||
let obj = {};
|
||||
if (response.data.scenarioDefinition) {
|
||||
obj = JSON.parse(response.data.scenarioDefinition);
|
||||
this.scenario.hashTree = obj.hashTree;
|
||||
}
|
||||
this.scenario.projectId = response.data.projectId;
|
||||
const pro = this.projectList.find(p => p.id === response.data.projectId);
|
||||
if (!pro) {
|
||||
this.scenario.projectId = getCurrentProjectID();
|
||||
}
|
||||
if (this.scenario.hashTree) {
|
||||
this.setDisabled(this.scenario.hashTree, this.scenario.projectId);
|
||||
}
|
||||
if (response.data.num) {
|
||||
this.scenario.num = response.data.num;
|
||||
this.getWorkspaceId(response.data.projectId);
|
||||
}
|
||||
this.scenario.versionName = response.data.versionName;
|
||||
this.scenario.versionEnable = response.data.versionEnable;
|
||||
this.scenario.name = response.data.name;
|
||||
this.scenario.headers = obj.headers;
|
||||
this.scenario.variables = obj.variables;
|
||||
this.scenario.environmentMap = obj.environmentMap;
|
||||
this.setResult(this.scenario.hashTree, map);
|
||||
this.$emit('refReload');
|
||||
}
|
||||
})
|
||||
} else if (this.scenario.id && (this.scenario.referenced === 'Copy' || this.scenario.referenced === 'Created') && !this.scenario.loaded) {
|
||||
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
|
||||
if (response.data) {
|
||||
if (response.data.num) {
|
||||
this.scenario.num = response.data.num;
|
||||
this.getWorkspaceId(response.data.projectId);
|
||||
} else {
|
||||
this.isSameSpace = false
|
||||
}
|
||||
this.scenario.versionName = response.data.versionName;
|
||||
this.scenario.versionEnable = response.data.versionEnable;
|
||||
} else {
|
||||
this.isSameSpace = false
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
components: {ApiBaseComponent, MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
|
||||
data() {
|
||||
|
@ -196,34 +149,6 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
formatResult(map, scenarios) {
|
||||
scenarios.forEach(item => {
|
||||
if (this.stepFilter.get("AllSamplerProxy").indexOf(item.type) !== -1 && item.requestResult) {
|
||||
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
|
||||
if (map.has(key)) {
|
||||
map.get(key).push(...item.requestResult);
|
||||
} else {
|
||||
map.set(key, item.requestResult);
|
||||
}
|
||||
}
|
||||
if (item.hashTree && item.hashTree.length > 0) {
|
||||
this.formatResult(map, item.hashTree);
|
||||
}
|
||||
})
|
||||
},
|
||||
setResult(array, scenarios) {
|
||||
if (array && scenarios) {
|
||||
array.forEach(item => {
|
||||
let key = (item.id ? item.id : item.resourceId) + "_" + item.index;
|
||||
if (scenarios.has(key)) {
|
||||
item.requestResult = scenarios.get(key);
|
||||
}
|
||||
if (item.hashTree && item.hashTree.length > 0) {
|
||||
this.setResult(item.hashTree, scenarios);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
run() {
|
||||
this.scenario.run = true;
|
||||
let runScenario = JSON.parse(JSON.stringify(this.scenario));
|
||||
|
|
Loading…
Reference in New Issue