refactor(接口测试): 优化引用场景加载处理,减少前后端交互
This commit is contained in:
parent
36988fbbb4
commit
165f63215e
|
@ -175,7 +175,7 @@ public class ApiAutomationController {
|
||||||
|
|
||||||
@GetMapping("/getApiScenario/{id}")
|
@GetMapping("/getApiScenario/{id}")
|
||||||
public ApiScenarioWithBLOBs getScenarioDefinition(@PathVariable String id) {
|
public ApiScenarioWithBLOBs getScenarioDefinition(@PathVariable String id) {
|
||||||
return apiAutomationService.getApiScenario(id);
|
return apiAutomationService.getNewApiScenario(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/getApiScenarioEnv")
|
@PostMapping("/getApiScenarioEnv")
|
||||||
|
|
|
@ -647,6 +647,54 @@ public class ApiAutomationService {
|
||||||
return apiScenarioMapper.selectByPrimaryKey(id);
|
return apiScenarioMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApiScenarioWithBLOBs getNewApiScenario(String id) {
|
||||||
|
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(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")) {
|
||||||
|
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(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());
|
||||||
|
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")) {
|
||||||
|
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (element != null && element.containsKey("hashTree")) {
|
||||||
|
JSONArray elementJSONArray = element.getJSONArray("hashTree");
|
||||||
|
dataFormatting(elementJSONArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String setDomain(ApiScenarioEnvRequest request) {
|
public String setDomain(ApiScenarioEnvRequest request) {
|
||||||
Boolean enable = request.getEnvironmentEnable();
|
Boolean enable = request.getEnvironmentEnable();
|
||||||
String scenarioDefinition = request.getDefinition();
|
String scenarioDefinition = request.getDefinition();
|
||||||
|
|
|
@ -108,56 +108,13 @@ export default {
|
||||||
created() {
|
created() {
|
||||||
if (this.scenario.num) {
|
if (this.scenario.num) {
|
||||||
this.isShowNum = true;
|
this.isShowNum = true;
|
||||||
|
this.getWorkspaceId(this.scenario.projectId);
|
||||||
|
} else {
|
||||||
|
this.isSameSpace = false;
|
||||||
}
|
}
|
||||||
if (!this.scenario.projectId) {
|
if (!this.scenario.projectId) {
|
||||||
this.scenario.projectId = getCurrentProjectID();
|
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.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
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.isSameSpace = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
components: {ApiBaseComponent, MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
|
components: {ApiBaseComponent, MsSqlBasisParameters, MsTcpBasisParameters, MsDubboBasisParameters, MsApiRequestForm},
|
||||||
data() {
|
data() {
|
||||||
|
@ -181,34 +138,6 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
run() {
|
||||||
this.scenario.run = true;
|
this.scenario.run = true;
|
||||||
let runScenario = JSON.parse(JSON.stringify(this.scenario));
|
let runScenario = JSON.parse(JSON.stringify(this.scenario));
|
||||||
|
|
Loading…
Reference in New Issue