From 9d6ad8ae42a97f9d5146c92239ca664062156a3a Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 2 Feb 2023 17:47:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AA=E7=8E=AF=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E4=B8=8B=E6=AD=A5=E9=AA=A4=E6=9C=80=E7=BB=88=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=AA=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1022325 --user=赵勇 【接口测试】接口场景-次循环下自定义脚本切换语言后执行成功-显示状态失败 https://www.tapd.cn/55049933/s/1330932 --- .../dto/definition/request/ElementUtil.java | 71 +++++----------- .../scenario/component/ApiComponent.vue | 81 ------------------- .../scenario/component/Jsr233Processor.vue | 3 + 3 files changed, 24 insertions(+), 131 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index c9b7ee56ce..ff9852f175 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -68,6 +68,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; public class ElementUtil { private static final String PRE = "PRE"; @@ -402,61 +403,31 @@ public class ElementUtil { public static void mergeHashTree(MsTestElement element, LinkedList targetHashTree) { try { - LinkedList sourceHashTree = element.getHashTree(); - if (CollectionUtils.isNotEmpty(sourceHashTree) && CollectionUtils.isNotEmpty(targetHashTree) && sourceHashTree.size() < targetHashTree.size()) { + if (CollectionUtils.isNotEmpty(element.getHashTree()) + && CollectionUtils.isNotEmpty(targetHashTree) + && element.getHashTree().size() == targetHashTree.size()) { element.setHashTree(targetHashTree); return; } - List sourceIds = new ArrayList<>(); - List delIds = new ArrayList<>(); - Map updateMap = new HashMap<>(); - if (CollectionUtils.isEmpty(sourceHashTree)) { - if (CollectionUtils.isNotEmpty(targetHashTree)) { - element.setHashTree(targetHashTree); - } - return; - } - if (CollectionUtils.isNotEmpty(targetHashTree)) { - for (MsTestElement item : targetHashTree) { - if (StringUtils.isNotEmpty(item.getId())) { - 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") && 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)); - } - } - } - } + // 合并步骤 + List sourceList = Stream.of(element.getHashTree(), targetHashTree) + .flatMap(Collection::stream) + .distinct() + .collect(Collectors.toList()); - // 删除多余的步骤 - 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); - } + // 历史数据补充id + sourceList.forEach(item -> { + if (StringUtils.isBlank(item.getId())) { + item.setId(UUID.randomUUID().toString()); } - } - if (CollectionUtils.isNotEmpty(sourceHashTree)) { - element.setHashTree(sourceHashTree); - } + }); + + sourceList = sourceList.stream().collect(Collectors + .collectingAndThen( + Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MsTestElement::getId))), + ArrayList::new)); + + element.setHashTree((LinkedList) sourceList); } catch (Exception e) { element.setHashTree(targetHashTree); } diff --git a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue index 627a272d31..fcd472a25b 100644 --- a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue +++ b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue @@ -407,87 +407,6 @@ export default { copyRow() { this.$emit('copyRow', this.request, this.node); }, - setUrl(url) { - try { - new URL(url); - this.request.url = url; - } catch (e) { - if (url && (!url.startsWith('http://') || !url.startsWith('https://'))) { - if (!this.isCustomizeReq) { - this.request.path = url; - this.request.url = undefined; - } - } - } - }, - 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(); - if (!sourceHashTree || sourceHashTree.length == 0) { - if (targetHashTree) { - targetHashTree.forEach((item) => { - item.disabled = true; - }); - this.request.hashTree = targetHashTree; - } - return; - } - if (targetHashTree) { - for (let i in targetHashTree) { - targetHashTree[i].disabled = true; - 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' && 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; - } else { - 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; - } - } - } - // 删除多余的步骤 - delIds.forEach((item) => { - const removeIndex = sourceHashTree.findIndex((d) => d.id && d.id === item); - sourceHashTree.splice(removeIndex, 1); - }); - - // 补充新增的源引用步骤 - if (targetHashTree) { - targetHashTree.forEach((item) => { - if (sourceIds.indexOf(item.id) === -1) { - item.disabled = true; - this.request.hashTree.push(item); - } - }); - } - }, sort() { for (let i in this.request.hashTree) { this.request.hashTree[i].index = Number(i) + 1; diff --git a/api-test/frontend/src/business/automation/scenario/component/Jsr233Processor.vue b/api-test/frontend/src/business/automation/scenario/component/Jsr233Processor.vue index 6463b44aa8..39ce16a2e5 100644 --- a/api-test/frontend/src/business/automation/scenario/component/Jsr233Processor.vue +++ b/api-test/frontend/src/business/automation/scenario/component/Jsr233Processor.vue @@ -250,6 +250,9 @@ export default { } }, forStatus() { + if (!this.jsr223Processor.requestResult || this.jsr223Processor.requestResult.length == 0) { + this.reqSuccess = true; + } if (this.jsr223Processor && this.jsr223Processor.result && this.jsr223Processor.result.length > 0) { this.jsr223Processor.result.forEach((item) => { item.requestResult.forEach((req) => {