fix(接口自动化): 修复场景引用步骤问题

--bug=1007929 --user=赵勇 接口自动化场景下接口详情无法展开或展开补全 https://www.tapd.cn/55049933/s/1067831
This commit is contained in:
fit2-zhao 2021-11-15 17:46:04 +08:00 committed by fit2-zhao
parent 4558beb2ef
commit 7a2ba0e9f8
8 changed files with 80 additions and 45 deletions

View File

@ -393,47 +393,65 @@ public class ElementUtil {
}
}
public static void mergeHashTree(List<MsTestElement> sourceHashTree, List<MsTestElement> targetHashTree) {
List<String> sourceIds = new ArrayList<>();
List<String> delIds = new ArrayList<>();
Map<String, MsTestElement> updateMap = new HashMap<>();
if (CollectionUtils.isEmpty(sourceHashTree)) {
public static void mergeHashTree(MsTestElement element, LinkedList<MsTestElement> targetHashTree) {
try {
LinkedList<MsTestElement> sourceHashTree = element.getHashTree();
if (CollectionUtils.isNotEmpty(sourceHashTree) && CollectionUtils.isNotEmpty(targetHashTree) && sourceHashTree.size() < targetHashTree.size()) {
element.setHashTree(targetHashTree);
return;
}
List<String> sourceIds = new ArrayList<>();
List<String> delIds = new ArrayList<>();
Map<String, MsTestElement> updateMap = new HashMap<>();
if (CollectionUtils.isEmpty(sourceHashTree)) {
if (CollectionUtils.isNotEmpty(targetHashTree)) {
element.setHashTree(targetHashTree);
}
return;
}
if (CollectionUtils.isNotEmpty(targetHashTree)) {
sourceHashTree.addAll(targetHashTree);
for (MsTestElement item : targetHashTree) {
if (StringUtils.isNotEmpty(item.getId())) {
updateMap.put(item.getId(), item);
}
}
}
return;
}
if (CollectionUtils.isNotEmpty(targetHashTree)) {
for (MsTestElement item : targetHashTree) {
updateMap.put(item.getId(), item);
}
}
// 找出待更新内容和源已经被删除的内容
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
for (int i = 0; i < sourceHashTree.size(); i++) {
MsTestElement source = sourceHashTree.get(i);
if (source != null) {
sourceIds.add(source.getId());
if (!StringUtils.equals(source.getLabel(), "SCENARIO-REF-STEP")) {
if (StringUtils.isNotEmpty(source.getId()) && updateMap.containsKey(source.getId())) {
sourceHashTree.set(i, updateMap.get(source.getId()));
} else {
delIds.add(source.getId());
// 找出待更新内容和源已经被删除的内容
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
for (int i = 0; i < sourceHashTree.size(); i++) {
MsTestElement source = sourceHashTree.get(i);
if (source != null) {
sourceIds.add(source.getId());
if (!StringUtils.equals(source.getLabel(), "SCENARIO-REF-STEP") && StringUtils.isNotEmpty(source.getId())) {
if (updateMap.containsKey(source.getId())) {
sourceHashTree.set(i, updateMap.get(source.getId()));
} else {
delIds.add(source.getId());
}
}
// 历史数据兼容
if (StringUtils.isEmpty(source.getId()) && !StringUtils.equals(source.getLabel(), "SCENARIO-REF-STEP") && i < targetHashTree.size()) {
sourceHashTree.set(i, targetHashTree.get(i));
}
}
}
}
}
// 删除多余的步骤
sourceHashTree.removeIf(item -> item != null && delIds.contains(item.getId()));
// 补充新增的源引用步骤
if (CollectionUtils.isNotEmpty(targetHashTree)) {
for (MsTestElement item : targetHashTree) {
if (!sourceIds.contains(item.getId())) {
sourceHashTree.add(item);
// 删除多余的步骤
sourceHashTree.removeIf(item -> item != null && delIds.contains(item.getId()));
// 补充新增的源引用步骤
if (CollectionUtils.isNotEmpty(targetHashTree)) {
for (MsTestElement item : targetHashTree) {
if (!sourceIds.contains(item.getId())) {
sourceHashTree.add(item);
}
}
}
if (CollectionUtils.isNotEmpty(sourceHashTree)) {
element.setHashTree(sourceHashTree);
}
} catch (Exception e) {
element.setHashTree(targetHashTree);
}
}
}

View File

@ -129,7 +129,7 @@ public class MsDubboSampler extends MsTestElement {
}
if (proxy != null) {
if (StringUtils.equals(this.getRefType(), "CASE")) {
ElementUtil.mergeHashTree(this.getHashTree(), proxy.getHashTree());
ElementUtil.mergeHashTree(this, proxy.getHashTree());
} else {
this.setHashTree(proxy.getHashTree());
}

View File

@ -159,7 +159,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
if (proxy != null) {
if (StringUtils.equals(this.getRefType(), "CASE")) {
ElementUtil.mergeHashTree(this.getHashTree(), proxy.getHashTree());
ElementUtil.mergeHashTree(this, proxy.getHashTree());
} else {
this.setHashTree(proxy.getHashTree());
}

View File

@ -256,7 +256,7 @@ public class MsJDBCSampler extends MsTestElement {
}
if (proxy != null) {
if (StringUtils.equals(this.getRefType(), "CASE")) {
ElementUtil.mergeHashTree(this.getHashTree(), proxy.getHashTree());
ElementUtil.mergeHashTree(this, proxy.getHashTree());
} else {
this.setHashTree(proxy.getHashTree());
}

View File

@ -233,7 +233,7 @@ public class MsTCPSampler extends MsTestElement {
}
if (proxy != null) {
if (StringUtils.equals(this.getRefType(), "CASE")) {
ElementUtil.mergeHashTree(this.getHashTree(), proxy.getHashTree());
ElementUtil.mergeHashTree(this, proxy.getHashTree());
}else {
this.setHashTree(proxy.getHashTree());
}

View File

@ -407,6 +407,11 @@ export default {
},
mergeHashTree(targetHashTree) {
let sourceHashTree = this.request.hashTree;
//
if (sourceHashTree && targetHashTree && sourceHashTree.length < targetHashTree.length) {
this.request.hashTree = targetHashTree;
return;
}
let sourceIds = [];
let delIds = [];
let updateMap = new Map();
@ -420,18 +425,22 @@ export default {
return;
}
if (targetHashTree) {
for(let i in targetHashTree){
for (let i in targetHashTree) {
targetHashTree[i].disabled = true;
updateMap.set(targetHashTree[i].id, targetHashTree[i]);
if (targetHashTree[i].id) {
updateMap.set(targetHashTree[i].id, targetHashTree[i]);
}
}
}
if (sourceHashTree && sourceHashTree.length > 0) {
for (let index in sourceHashTree) {
let source = sourceHashTree[index];
sourceIds.push(source.id);
if (source.label !== 'SCENARIO-REF-STEP') {
if (source.id && updateMap.has(source.id)) {
Object.assign(sourceHashTree[index] , updateMap.get(source.id));
//
if (source.label !== 'SCENARIO-REF-STEP' && source.id) {
if (updateMap.has(source.id)) {
Object.assign(sourceHashTree[index], updateMap.get(source.id));
sourceHashTree[index].disabled = true;
sourceHashTree[index].label = '';
sourceHashTree[index].enable = updateMap.get(source.id).enable;
@ -439,6 +448,13 @@ export default {
delIds.push(source.id);
}
}
//
if (!source.id && source.label !== 'SCENARIO-REF-STEP' && index < targetHashTree.length) {
Object.assign(sourceHashTree[index], targetHashTree[index]);
sourceHashTree[index].disabled = true;
sourceHashTree[index].label = '';
sourceHashTree[index].enable = targetHashTree[index].enable;
}
}
}
//

View File

@ -1,5 +1,6 @@
import {ELEMENT_TYPE} from "@/business/components/api/automation/scenario/Setting";
import {Assertions, ConstantTimer, Extract, IfController, JSR223Processor, JDBCProcessor, LoopController, TransactionController, PluginController} from "@/business/components/api/definition/model/ApiTestModel";
import {getUUID} from "@/common/js/utils";
export function buttons(this_) {
let buttons = [
@ -176,11 +177,11 @@ export function setComponent(type, _this, plugin) {
_this.scenarioDefinition.push(new JDBCProcessor({type: "JDBCPostProcessor"}));
break;
case ELEMENT_TYPE.Assertions:
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Assertions({label: "SCENARIO-REF-STEP"})) :
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Assertions({label: "SCENARIO-REF-STEP",id:getUUID()})) :
_this.scenarioDefinition.push(new Assertions());
break;
case ELEMENT_TYPE.Extract:
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Extract({label: "SCENARIO-REF-STEP"})) :
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Extract({label: "SCENARIO-REF-STEP",id:getUUID()})) :
_this.scenarioDefinition.push(new Extract());
break;
case ELEMENT_TYPE.CustomizeReq:

View File

@ -171,7 +171,7 @@ export default {
this.reload();
},
addAssertions() {
let assertions = new Assertions();
let assertions = new Assertions({id:getUUID()});
if (!this.request.hashTree) {
this.request.hashTree = [];
}
@ -179,7 +179,7 @@ export default {
this.reload();
},
addExtract() {
let jsonPostProcessor = new Extract();
let jsonPostProcessor = new Extract({id:getUUID()});
if (!this.request.hashTree) {
this.request.hashTree = [];
}