From ad97ee0ef9a62118be6c0113cf197f2e49267f4a Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Tue, 29 Oct 2024 17:26:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84jmx=E8=A7=A3=E6=9E=90=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=89=80=E5=B1=9E=E8=AF=AD=E8=A8=80=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms/http/post/JSR223PostProcessConverter.java | 7 ++++--- .../ms/http/pre/JSR223PreProcessConverter.java | 8 ++++---- .../io/metersphere/api/utils/ConverterUtils.java | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/http/post/JSR223PostProcessConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/http/post/JSR223PostProcessConverter.java index 2a5e3af9d6..0ea0f8bbc2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/http/post/JSR223PostProcessConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/ms/http/post/JSR223PostProcessConverter.java @@ -12,10 +12,11 @@ public class JSR223PostProcessConverter extends AbstractMsElementConverter { @Override public void toMsElement(AbstractMsTestElement parent, JSR223PreProcessor element, HashTree hashTree) { - ScriptProcessor msScriptElement = new ScriptProcessor(); - msScriptElement.setScriptLanguage(element.getScriptLanguage()); - if (StringUtil.isBlank(msScriptElement.getScriptLanguage())) { - msScriptElement.setScriptLanguage(element.getPropertyAsString("scriptLanguage")); + String scriptLanguage = element.getScriptLanguage(); + if (StringUtil.isBlank(scriptLanguage)) { + scriptLanguage = element.getPropertyAsString("scriptLanguage"); } + msScriptElement.setScriptLanguage(ConverterUtils.parseScriptLanguage(scriptLanguage)); msScriptElement.setEnable(element.isEnabled()); msScriptElement.setName(element.getPropertyAsString("TestElement.name")); msScriptElement.setScript(element.getPropertyAsString("script")); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ConverterUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ConverterUtils.java index f5bb92cf47..955d2d6abf 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ConverterUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ConverterUtils.java @@ -9,7 +9,9 @@ import io.metersphere.project.api.processor.ExtractPostProcessor; import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.api.processor.extract.MsExtract; +import io.metersphere.project.constants.ScriptLanguageType; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.testelement.AbstractTestElement; import java.util.LinkedList; @@ -148,4 +150,18 @@ public class ConverterUtils { } } + + public static String parseScriptLanguage(String scriptLanguage) { + if (StringUtils.equalsIgnoreCase(scriptLanguage, "beanshell")) { + return ScriptLanguageType.BEANSHELL_JSR233.name(); + } else if (StringUtils.equalsIgnoreCase(scriptLanguage, "groovy")) { + return ScriptLanguageType.GROOVY.name(); + } else if (StringUtils.equalsIgnoreCase(scriptLanguage, "javascript")) { + return ScriptLanguageType.JAVASCRIPT.name(); + } else if (StringUtils.equalsIgnoreCase(scriptLanguage, "python")) { + return ScriptLanguageType.PYTHON.name(); + } else { + return scriptLanguage; + } + } }