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 63bbb6cfcd..c02b3d405c 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 @@ -904,7 +904,7 @@ public class ElementUtil { testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("BeanShellSamplerGui")); } else { testElement.setProperty("scriptLanguage", vo.getScriptLanguage()); - testElement.setProperty("script", vo.getScript()); + testElement.setProperty(ElementConstants.SCRIPT, vo.getScript()); } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java index 65dae64403..3d9da90745 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertions.java @@ -222,7 +222,7 @@ public class MsAssertions extends MsTestElement { scriptLanguage = "rhino"; } assertion.setProperty("scriptLanguage", scriptLanguage); - assertion.setProperty("script", assertionJSR223.getScript()); + assertion.setProperty(ElementConstants.SCRIPT, assertionJSR223.getScript()); return assertion; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java index 807962e1de..9fb2696714 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java @@ -205,9 +205,9 @@ public class MsLoopController extends MsTestElement { sampler.setName("MS_CLEAR_LOOPS_VAR_" + ms_current_timer); sampler.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); - sampler.setProperty("scriptLanguage", "beanshell"); - ScriptFilter.verify("beanshell", this.getName(), script()); - sampler.setProperty("script", "vars.put(\"" + ms_current_timer + "\", null);"); + sampler.setProperty("scriptLanguage", ElementConstants.BEANSHELL); + ScriptFilter.verify(ElementConstants.BEANSHELL, this.getName(), script()); + sampler.setProperty(ElementConstants.SCRIPT, "vars.put(\"" + ms_current_timer + "\", null);"); hashTree.add(sampler); } @@ -235,11 +235,11 @@ public class MsLoopController extends MsTestElement { jsr223PreProcessor.setName("循环超时处理"); jsr223PreProcessor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName()); jsr223PreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); - jsr223PreProcessor.setProperty("scriptLanguage", "beanshell"); + jsr223PreProcessor.setProperty("scriptLanguage", ElementConstants.BEANSHELL); - ScriptFilter.verify("beanshell", this.getName(), script()); + ScriptFilter.verify(ElementConstants.BEANSHELL, this.getName(), script()); - jsr223PreProcessor.setProperty("script", script()); + jsr223PreProcessor.setProperty(ElementConstants.SCRIPT, script()); hashTree.add(jsr223PreProcessor); return hashTree; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java index e2b5bccdce..c2b63a2d55 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java @@ -74,7 +74,7 @@ public class MsExtract extends MsTestElement { shell.setProperty(TestElement.TEST_CLASS, JSR223PostProcessor.class.getName()); shell.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); shell.setProperty("cacheKey", false); - shell.setProperty("script", "io.metersphere.utils.JMeterVars.addVars(prev.getResourceId(),vars," + "\"" + extract.toString() + "\"" + ");"); + shell.setProperty(ElementConstants.SCRIPT, "io.metersphere.utils.JMeterVars.addVars(prev.getResourceId(),vars," + "\"" + extract.toString() + "\"" + ");"); samplerHashTree.add(shell); } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/shell/filter/ScriptFilter.java b/api-test/backend/src/main/java/io/metersphere/api/dto/shell/filter/ScriptFilter.java index fe54e51af1..9f4c075c4d 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/shell/filter/ScriptFilter.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/shell/filter/ScriptFilter.java @@ -1,5 +1,6 @@ package io.metersphere.api.dto.shell.filter; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.plugin.core.utils.LogUtil; import org.apache.commons.io.IOUtils; @@ -34,7 +35,7 @@ public class ScriptFilter { if (StringUtils.isNotEmpty(script)) { final StringBuffer buffer = new StringBuffer(); switch (language) { - case "beanshell": + case ElementConstants.BEANSHELL: blackList(buffer, script, beanshell); break; case "python": diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/JmeterDefinitionParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/JmeterDefinitionParser.java index 6b773fd69b..a635c7291b 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/JmeterDefinitionParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/JmeterDefinitionParser.java @@ -29,11 +29,12 @@ import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.parse.ApiImportAbstractParser; -import io.metersphere.api.parse.scenario.MsJmeterParser; +import io.metersphere.api.parse.scenario.JMeterParser; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentExample; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.constants.RequestTypeConstants; import io.metersphere.commons.enums.ApiTestDataStatus; @@ -346,7 +347,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser { +public class JMeterParser extends ApiImportAbstractParser { private final String ENV_NAME = "导入数据环境"; /** * todo 存放单个请求下的Header 为了和平台对应 @@ -103,7 +103,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { MsScenario scenario = new MsScenario(); scenario.setReferenced("IMPORT"); - jmterHashTree(testPlan, scenario); + formatHashTree(testPlan, scenario); this.projectId = request.getProjectId(); ScenarioImport scenarioImport = new ScenarioImport(); scenarioImport.setData(parseObj(scenario, request)); @@ -656,7 +656,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { JSR223Assertion jsr223Assertion = (JSR223Assertion) key; msAssertionJSR223.setName(jsr223Assertion.getName()); msAssertionJSR223.setDesc(jsr223Assertion.getName()); - msAssertionJSR223.setScript(jsr223Assertion.getPropertyAsString("script")); + msAssertionJSR223.setScript(jsr223Assertion.getPropertyAsString(ElementConstants.SCRIPT)); msAssertionJSR223.setScriptLanguage(jsr223Assertion.getPropertyAsString("scriptLanguage")); assertions.setName(jsr223Assertion.getName()); @@ -687,7 +687,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { return null; } - private void jmterHashTree(HashTree tree, MsTestElement scenario) { + private void formatHashTree(HashTree tree, MsTestElement scenario) { for (Object key : tree.keySet()) { MsTestElement elementNode; if (CollectionUtils.isEmpty(scenario.getHashTree())) { @@ -734,7 +734,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { JSR223Sampler jsr223Sampler = (JSR223Sampler) key; elementNode = new MsJSR223Processor(); BeanUtils.copyBean(elementNode, jsr223Sampler); - ((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString("script")); + ((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223Processor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); } // 后置脚本 @@ -742,7 +742,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { JSR223PostProcessor jsr223Sampler = (JSR223PostProcessor) key; elementNode = new MsJSR223PostProcessor(); BeanUtils.copyBean(elementNode, jsr223Sampler); - ((MsJSR223PostProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString("script")); + ((MsJSR223PostProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223PostProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); } else if (key instanceof BeanShellPostProcessor) { elementNode = getMsTestElement((BeanShellPostProcessor) key); @@ -754,7 +754,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { JSR223PreProcessor jsr223Sampler = (JSR223PreProcessor) key; elementNode = new MsJSR223PreProcessor(); BeanUtils.copyBean(elementNode, jsr223Sampler); - ((MsJSR223PreProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString("script")); + ((MsJSR223PreProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223PreProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); } // 断言规则 @@ -851,7 +851,7 @@ public class MsJmeterParser extends ApiImportAbstractParser { // 递归子项 HashTree node = tree.get(key); if (node != null) { - jmterHashTree(node, elementNode); + formatHashTree(node, elementNode); } } } @@ -862,8 +862,8 @@ public class MsJmeterParser extends ApiImportAbstractParser { elementNode = new MsJSR223PreProcessor(); BeanUtils.copyBean(elementNode, beanShellPreProcessor); ((MsJSR223PreProcessor) elementNode).setJsrEnable(false); - ((MsJSR223PreProcessor) elementNode).setScript(beanShellPreProcessor.getPropertyAsString("script")); - ((MsJSR223PreProcessor) elementNode).setScriptLanguage(beanShellPreProcessor.getPropertyAsString("scriptLanguage")); + ((MsJSR223PreProcessor) elementNode).setScript(beanShellPreProcessor.getPropertyAsString(ElementConstants.SCRIPT)); + ((MsJSR223PreProcessor) elementNode).setScriptLanguage(ElementConstants.BEANSHELL); return elementNode; } @@ -873,8 +873,8 @@ public class MsJmeterParser extends ApiImportAbstractParser { elementNode = new MsJSR223PostProcessor(); ((MsJSR223PostProcessor) elementNode).setJsrEnable(false); BeanUtils.copyBean(elementNode, beanShellPostProcessor); - ((MsJSR223PostProcessor) elementNode).setScript(beanShellPostProcessor.getPropertyAsString("script")); - ((MsJSR223PostProcessor) elementNode).setScriptLanguage(beanShellPostProcessor.getPropertyAsString("scriptLanguage")); + ((MsJSR223PostProcessor) elementNode).setScript(beanShellPostProcessor.getPropertyAsString(ElementConstants.SCRIPT)); + ((MsJSR223PostProcessor) elementNode).setScriptLanguage(ElementConstants.BEANSHELL); return elementNode; } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/ScenarioImportParserFactory.java b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/ScenarioImportParserFactory.java index 8c27360bf6..de7347f254 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/ScenarioImportParserFactory.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/ScenarioImportParserFactory.java @@ -11,7 +11,7 @@ public class ScenarioImportParserFactory { } else if (StringUtils.equals(ApiImportPlatform.Postman.name(), platform)) { return new PostmanScenarioParser(); } else if (StringUtils.equals(ApiImportPlatform.Jmeter.name(), platform)) { - return new MsJmeterParser(); + return new JMeterParser(); } else if (StringUtils.equals(ApiImportPlatform.Har.name(), platform)) { return new HarScenarioParser(); } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/constants/ElementConstants.java b/api-test/backend/src/main/java/io/metersphere/commons/constants/ElementConstants.java index 8d3de1490d..f91a8448c6 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/constants/ElementConstants.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/constants/ElementConstants.java @@ -49,4 +49,8 @@ public class ElementConstants { this.add(ElementConstants.AUTH_MANAGER); this.add(ElementConstants.ABS_SAMPLER); }}; + + public static final String SCRIPT = "script"; + public static final String BEANSHELL = "beanshell"; + } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java index 4214957224..c378cd6c54 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java @@ -37,7 +37,7 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil { public static final String BODY_RAW = "body_raw"; public static final String REQUEST = "request"; public static final String BODY_XML = "body_xml"; - public static final String SCRIPT = "script"; + public static final String SCRIPT = ElementConstants.SCRIPT; @Override public String diffResponse(String newValue, String oldValue) { diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java index 13e26f1879..70017b3ff4 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java @@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.assertions.MsAssertionRegex; import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.StorageConstants; import io.metersphere.dto.FileInfoDTO; import io.metersphere.dto.JmeterRunRequestDTO; @@ -36,7 +37,7 @@ public class HashTreeUtil { public static final String VALUE = "value"; public static final String ENABLE = "enable"; public static final String NAME = "name"; - public static final String SCRIPT = "script"; + public static final String SCRIPT = ElementConstants.SCRIPT; public Map> getEnvParamsDataByHashTree(HashTree hashTree, BaseEnvironmentService apiTestEnvironmentService) { Map> returnMap = new HashMap<>(); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java index db602c47a1..079a3f56bd 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockApiUtils.java @@ -5,6 +5,7 @@ import io.metersphere.api.dto.mock.MockConfigRequestParams; import io.metersphere.api.dto.mock.RequestMockParams; import io.metersphere.api.dto.shell.filter.ScriptFilter; import io.metersphere.api.exec.generator.JSONSchemaGenerator; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.enums.MockParamConditionEnums; import io.metersphere.commons.exception.MSException; @@ -268,14 +269,14 @@ public class MockApiUtils { public String getResultByResponseResult(String projectId, JSONObject bodyObj, String url, Map headerMap, RequestMockParams requestMockParams, boolean useScript) { MockScriptEngineUtils scriptEngineUtils = new MockScriptEngineUtils(); ScriptEngine scriptEngine = null; - String scriptLanguage = "beanshell"; + String scriptLanguage = ElementConstants.BEANSHELL; String script = null; if (useScript) { if (bodyObj.has("scriptObject")) { try { JSONObject scriptObj = bodyObj.optJSONObject("scriptObject"); scriptLanguage = scriptObj.optString("scriptLanguage"); - script = scriptObj.optString("script"); + script = scriptObj.optString(ElementConstants.SCRIPT); } catch (Exception e) { LogUtil.error(e); } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java index 5361a6fd3a..a263fb7880 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java @@ -2,6 +2,7 @@ package io.metersphere.commons.utils.mock; import io.metersphere.api.dto.mock.RequestMockParams; +import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.JSONUtil; @@ -86,9 +87,9 @@ public class MockScriptEngineUtils { return null; } String preScript = StringUtils.EMPTY; - if (StringUtils.equalsIgnoreCase(scriptLanguage, "beanshell")) { + if (StringUtils.equalsIgnoreCase(scriptLanguage, ElementConstants.BEANSHELL)) { ScriptEngineManager scriptEngineFactory = new ScriptEngineManager(); - engine = scriptEngineFactory.getEngineByName("beanshell"); + engine = scriptEngineFactory.getEngineByName(ElementConstants.BEANSHELL); preScript = this.genBeanshellPreScript(url, headerMap, requestMockParams); } else if (StringUtils.equalsIgnoreCase(scriptLanguage, "python")) { ScriptEngineManager scriptEngineFactory = new ScriptEngineManager(); diff --git a/api-test/frontend/src/business/automation/scenario/common/Jsr233ProcessorContent.vue b/api-test/frontend/src/business/automation/scenario/common/Jsr233ProcessorContent.vue index 115e638657..57fdda70ed 100644 --- a/api-test/frontend/src/business/automation/scenario/common/Jsr233ProcessorContent.vue +++ b/api-test/frontend/src/business/automation/scenario/common/Jsr233ProcessorContent.vue @@ -174,6 +174,9 @@ export default { if (this.jsr223Processor.jsrEnable === null || this.jsr223Processor.jsrEnable === undefined) { this.$set(this.jsr223Processor, 'jsrEnable', true); } + if (!this.jsr223Processor.scriptLanguage) { + this.$set(this.jsr223Processor, 'scriptLanguage', 'beanshell'); + } this.jsr223ProcessorData = this.jsr223Processor; }, props: {