refactor(接口测试): 重构jmx解析脚本组件所属语言方法

This commit is contained in:
Jianguo-Genius 2024-10-29 17:26:29 +08:00 committed by Craftsman
parent 58014ab961
commit ad97ee0ef9
3 changed files with 24 additions and 7 deletions

View File

@ -12,10 +12,11 @@ public class JSR223PostProcessConverter extends AbstractMsElementConverter<JSR22
@Override @Override
public void toMsElement(AbstractMsTestElement parent, JSR223PostProcessor element, HashTree hashTree) { public void toMsElement(AbstractMsTestElement parent, JSR223PostProcessor element, HashTree hashTree) {
ScriptProcessor msScriptElement = new ScriptProcessor(); ScriptProcessor msScriptElement = new ScriptProcessor();
msScriptElement.setScriptLanguage(element.getScriptLanguage()); String scriptLanguage = element.getScriptLanguage();
if (StringUtil.isBlank(msScriptElement.getScriptLanguage())) { if (StringUtil.isBlank(scriptLanguage)) {
msScriptElement.setScriptLanguage(element.getPropertyAsString("scriptLanguage")); scriptLanguage = element.getPropertyAsString("scriptLanguage");
} }
msScriptElement.setScriptLanguage(ConverterUtils.parseScriptLanguage(scriptLanguage));
msScriptElement.setEnable(element.isEnabled()); msScriptElement.setEnable(element.isEnabled());
msScriptElement.setName(element.getPropertyAsString("TestElement.name")); msScriptElement.setName(element.getPropertyAsString("TestElement.name"));
msScriptElement.setScript(element.getPropertyAsString("script")); msScriptElement.setScript(element.getPropertyAsString("script"));

View File

@ -11,12 +11,12 @@ import org.apache.jorphan.collections.HashTree;
public class JSR223PreProcessConverter extends AbstractMsElementConverter<JSR223PreProcessor> { public class JSR223PreProcessConverter extends AbstractMsElementConverter<JSR223PreProcessor> {
@Override @Override
public void toMsElement(AbstractMsTestElement parent, JSR223PreProcessor element, HashTree hashTree) { public void toMsElement(AbstractMsTestElement parent, JSR223PreProcessor element, HashTree hashTree) {
ScriptProcessor msScriptElement = new ScriptProcessor(); ScriptProcessor msScriptElement = new ScriptProcessor();
msScriptElement.setScriptLanguage(element.getScriptLanguage()); String scriptLanguage = element.getScriptLanguage();
if (StringUtil.isBlank(msScriptElement.getScriptLanguage())) { if (StringUtil.isBlank(scriptLanguage)) {
msScriptElement.setScriptLanguage(element.getPropertyAsString("scriptLanguage")); scriptLanguage = element.getPropertyAsString("scriptLanguage");
} }
msScriptElement.setScriptLanguage(ConverterUtils.parseScriptLanguage(scriptLanguage));
msScriptElement.setEnable(element.isEnabled()); msScriptElement.setEnable(element.isEnabled());
msScriptElement.setName(element.getPropertyAsString("TestElement.name")); msScriptElement.setName(element.getPropertyAsString("TestElement.name"));
msScriptElement.setScript(element.getPropertyAsString("script")); msScriptElement.setScript(element.getPropertyAsString("script"));

View File

@ -9,7 +9,9 @@ import io.metersphere.project.api.processor.ExtractPostProcessor;
import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.MsProcessor;
import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.api.processor.SQLProcessor;
import io.metersphere.project.api.processor.extract.MsExtract; import io.metersphere.project.api.processor.extract.MsExtract;
import io.metersphere.project.constants.ScriptLanguageType;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.testelement.AbstractTestElement; import org.apache.jmeter.testelement.AbstractTestElement;
import java.util.LinkedList; 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;
}
}
} }