diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/JMeterParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/JMeterParser.java index 9a65086462..7ada2089e7 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/JMeterParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/JMeterParser.java @@ -335,9 +335,11 @@ public class JMeterParser extends ApiImportAbstractParser { samplerProxy.setUrl(this.getUrl(source)); samplerProxy.setPath(null); samplerProxy.setCustomizeReq(true); + samplerProxy.setIsRefEnvironment(false); } samplerProxy.setId(UUID.randomUUID().toString()); samplerProxy.setType(ElementConstants.HTTP_SAMPLER); + samplerProxy.setClazzName(MsHTTPSamplerProxy.class.getCanonicalName()); body.getKvs().add(new KeyValue()); body.getBinary().add(new KeyValue()); @@ -375,6 +377,7 @@ public class JMeterParser extends ApiImportAbstractParser { msTCPSampler.setUsername(tcpSampler.getProperty(ConfigTestElement.USERNAME).getStringValue()); msTCPSampler.setPassword(tcpSampler.getProperty(ConfigTestElement.PASSWORD).getStringValue()); msTCPSampler.setClassname(tcpSampler.getClassname()); + msTCPSampler.setClazzName(MsTCPSampler.class.getCanonicalName()); } private void convertDubboSample(MsDubboSampler elementNode, DubboSample sampler) { @@ -431,6 +434,7 @@ public class JMeterParser extends ApiImportAbstractParser { }); } elementNode.setAttachmentArgs(attachmentArgs); + elementNode.setClazzName(MsDubboSampler.class.getCanonicalName()); } /** @@ -558,6 +562,10 @@ public class JMeterParser extends ApiImportAbstractParser { msJDBCSampler.setDataSourceId(dataPools.getDataSources().get(jdbcSampler.getPropertyAsString("dataSource")).getId()); } msJDBCSampler.setVariables(new LinkedList<>()); + msJDBCSampler.setCustomizeReq(true); + msJDBCSampler.setIsRefEnvironment(false); + msJDBCSampler.setReferenced(ElementConstants.STEP_CREATED); + msJDBCSampler.setClazzName(MsJDBCSampler.class.getCanonicalName()); } private void convertMsExtract(MsExtract extract, Object key) { @@ -757,6 +765,7 @@ public class JMeterParser extends ApiImportAbstractParser { BeanUtils.copyBean(elementNode, jsr223Sampler); ((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223Processor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); + elementNode.setClazzName(MsJSR223Processor.class.getCanonicalName()); } // BeanShell自定义脚本 else if (key instanceof BeanShellSampler) { @@ -766,6 +775,7 @@ public class JMeterParser extends ApiImportAbstractParser { ((MsJSR223Processor) elementNode).setJsrEnable(false); ((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString("BeanShellSampler.query")); ((MsJSR223Processor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); + elementNode.setClazzName(MsJSR223Processor.class.getCanonicalName()); } // 后置脚本 else if (key instanceof JSR223PostProcessor) { @@ -774,6 +784,7 @@ public class JMeterParser extends ApiImportAbstractParser { BeanUtils.copyBean(elementNode, jsr223Sampler); ((MsJSR223PostProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223PostProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); + elementNode.setClazzName(MsJSR223PostProcessor.class.getCanonicalName()); } else if (key instanceof BeanShellPostProcessor) { elementNode = getMsTestElement((BeanShellPostProcessor) key); } else if (key instanceof BeanShellPreProcessor) { @@ -786,22 +797,26 @@ public class JMeterParser extends ApiImportAbstractParser { BeanUtils.copyBean(elementNode, jsr223Sampler); ((MsJSR223PreProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT)); ((MsJSR223PreProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage")); + elementNode.setClazzName(MsJSR223PreProcessor.class.getCanonicalName()); } // 断言规则 else if (key instanceof ResponseAssertion || key instanceof JSONPathAssertion || key instanceof XPath2Assertion || key instanceof JSR223Assertion || key instanceof DurationAssertion) { elementNode = new MsAssertions(); convertMsAssertions((MsAssertions) elementNode, key); + elementNode.setClazzName(MsAssertions.class.getCanonicalName()); } // 提取参数 else if (key instanceof RegexExtractor || key instanceof XPath2Extractor || key instanceof JSONPostProcessor) { elementNode = new MsExtract(); convertMsExtract((MsExtract) elementNode, key); + elementNode.setClazzName(MsExtract.class.getCanonicalName()); } // 定时器 else if (key instanceof ConstantTimer) { elementNode = new MsConstantTimer(); BeanUtils.copyBean(elementNode, key); elementNode.setType(ElementConstants.CONSTANT_TIMER); + elementNode.setClazzName(MsConstantTimer.class.getCanonicalName()); } // 次数循环控制器 else if (key instanceof LoopController) { @@ -814,6 +829,7 @@ public class JMeterParser extends ApiImportAbstractParser { countController.setLoops(String.valueOf(loopController.getLoops())); countController.setProceed(true); ((MsLoopController) elementNode).setCountController(countController); + elementNode.setClazzName(MsLoopController.class.getCanonicalName()); } // While循环控制器 else if (key instanceof WhileController) { @@ -825,6 +841,7 @@ public class JMeterParser extends ApiImportAbstractParser { MsWhileController countController = new MsWhileController(); countController.setValue(whileController.getCondition()); ((MsLoopController) elementNode).setWhileController(countController); + elementNode.setClazzName(MsWhileController.class.getCanonicalName()); } // Foreach 循环控制器 else if (key instanceof ForeachController) { @@ -837,12 +854,14 @@ public class JMeterParser extends ApiImportAbstractParser { countController.setInputVal(foreachController.getInputValString()); countController.setReturnVal(foreachController.getReturnValString()); ((MsLoopController) elementNode).setForEachController(countController); + elementNode.setClazzName(ForeachController.class.getCanonicalName()); } else if (key instanceof TransactionController) { TransactionController transactionController = (TransactionController) key; elementNode = new MsTransactionController(); elementNode.setName(transactionController.getName()); ((MsTransactionController) elementNode).setGenerateParentSample(transactionController.isGenerateParentSample()); ((MsTransactionController) elementNode).setIncludeTimers(transactionController.isIncludeTimers()); + elementNode.setClazzName(MsTransactionController.class.getCanonicalName()); } else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.ConnectSampler")) { elementNode = getMqttElement(key, "io.metersphere.plugin.mqtt.sampler.MqttConnectSampler"); } else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.DisConnectSampler")) { @@ -864,6 +883,7 @@ public class JMeterParser extends ApiImportAbstractParser { elementNode.setName(testElement.getName()); ((MsJmeterElement) elementNode).setJmeterElement(objToXml(key)); ((MsJmeterElement) elementNode).setElementType(key.getClass().getSimpleName()); + elementNode.setClazzName(MsJmeterElement.class.getCanonicalName()); } elementNode.setEnable(((TestElement) key).isEnabled()); elementNode.setResourceId(UUID.randomUUID().toString()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 189b99861d..eec5987c3c 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -65,6 +65,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; import org.jetbrains.annotations.NotNull; @@ -868,6 +869,7 @@ public class ApiScenarioService { public int getScenarioStep(List ids) { return extApiScenarioReferenceIdMapper.selectByScenarioIds(ids); } + public List getScenarioDetail(List ids) { if (CollectionUtils.isEmpty(ids)) { return new ArrayList<>(); @@ -2199,7 +2201,8 @@ public class ApiScenarioService { } else { //将复制的或者类型不是引用case的步骤赋予当前项目id,目的是为了运行的时候可以配置运行环境 object.put("projectId", projectId); - if (StringUtils.isEmpty(object.optString("url"))) { + if (StringUtils.isEmpty(object.optString("url")) + && StringUtils.equals(object.optString("type"), HTTPSamplerProxy.class.getCanonicalName())) { object.put("isRefEnvironment", true); } }