From 08c01b4443a5075caa91a502d3e3e9b2c1b8378f Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 8 Jul 2022 11:39:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=8E=BB=E6=8E=89=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5Postma?= =?UTF-8?q?n=E7=94=A8=E4=BE=8B=E4=B8=AD=E7=9A=84=E5=89=8D=E7=BD=AE?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014726 --user=王孝刚 【接口测试】github#15535,通过Postman导入的接口自动化用例,在有前置脚本的情况下,导入至MS平台,显示的脚本类型为不存在的rhino https://www.tapd.cn/55049933/s/1197819 --- .../parse/PostmanAbstractParserParser.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java b/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java index d133df1d57..cd1a687d97 100644 --- a/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java +++ b/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java @@ -2,7 +2,6 @@ package io.metersphere.api.parse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.response.HttpResponse; import io.metersphere.api.dto.parse.postman.*; @@ -12,17 +11,14 @@ import io.metersphere.commons.constants.MsRequestBodyType; import io.metersphere.commons.constants.PostmanRequestBodyMode; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.plugin.core.MsTestElement; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; public abstract class PostmanAbstractParserParser extends ApiImportAbstractParser { @@ -47,7 +43,6 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa request.setArguments(parseKeyValue(url == null ? new ArrayList<>() : url.getQuery())); request.setHeaders(parseKeyValue(requestDesc.getHeader())); addBodyHeader(request); - addPreScript(request, requestItem.getEvent()); return request; } @@ -110,37 +105,6 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa return value; } - private void addPreScript(MsHTTPSamplerProxy request, List event) { - if (request != null && CollectionUtils.isNotEmpty(event)) { - StringBuilder scriptStr = new StringBuilder(); - event = event.stream() - .filter(item -> item.getScript() != null) - .collect(Collectors.toList()); - event.forEach(item -> { - PostmanScript script = item.getScript(); - if (script != null && item.getListen().contains("prerequest")) { - List exec = script.getExec(); - if (CollectionUtils.isNotEmpty(exec)) { - exec.forEach(col -> { - if (StringUtils.isNotEmpty(col)) { - scriptStr.append(col + "\n"); - } - }); - } - } - }); - if (StringUtils.isNotBlank(scriptStr)) { - MsJSR223PreProcessor jsr223PreProcessor = new MsJSR223PreProcessor(); - jsr223PreProcessor.setName("JSR223PreProcessor"); - jsr223PreProcessor.setScriptLanguage("rhino"); - jsr223PreProcessor.setScript(parseVariable(scriptStr.toString())); - LinkedList hashTree = new LinkedList<>(); - hashTree.add(jsr223PreProcessor); - request.setHashTree(hashTree); - } - } - } - private List parseKeyValue(List postmanKeyValues) { if (postmanKeyValues == null) { return new ArrayList<>();