From d4b43e273a28759b820b9e79ed573a462d3ec143 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 29 Dec 2022 16:18:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84mqtt=E6=94=AF=E6=8C=81ms=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1010741 --user=王孝刚 【Bug转需求】[接口测试-MQTT]github#20278在MS平台已安装MQTT插件的情况下,上传包含MQTT取样器的JMX文件时,MQTT插件相关配置仍显示为原生xml,建议优化 https://www.tapd.cn/55049933/s/1320257 --- .../api/parse/scenario/JMeterParser.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 f760680d8a..c2d24061a8 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 @@ -81,6 +81,7 @@ import org.apache.jorphan.collections.HashTree; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.*; @@ -823,6 +824,14 @@ public class JMeterParser extends ApiImportAbstractParser { elementNode.setName(transactionController.getName()); ((MsTransactionController) elementNode).setGenerateParentSample(transactionController.isGenerateParentSample()); ((MsTransactionController) elementNode).setIncludeTimers(transactionController.isIncludeTimers()); + } 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")) { + elementNode = getMqttElement(key, "io.metersphere.plugin.mqtt.sampler.MqttDisConnectSampler"); + } else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.PubSampler")) { + elementNode = getMqttElement(key, "io.metersphere.plugin.mqtt.sampler.MqttPubSampler"); + } else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.SubSampler")) { + elementNode = getMqttElement(key, "io.metersphere.plugin.mqtt.sampler.MqttSubSampler"); } // 平台不能识别的Jmeter步骤 else { @@ -866,6 +875,21 @@ public class JMeterParser extends ApiImportAbstractParser { } } + private static MsTestElement getMqttElement(Object key, String className) { + MsTestElement elementNode; + try { + Class clazz = null; + clazz = Class.forName(className); + Object instance = clazz.getConstructor().newInstance(); + Method methods2 = clazz.getMethod("importJmx", Object.class); + Object invoke = methods2.invoke(instance, key); + elementNode = (MsTestElement) invoke; + } catch (Exception e) { + throw new RuntimeException(e); + } + return elementNode; + } + public static MsTestElement getMsTestElement(BeanShellPreProcessor key) { MsTestElement elementNode; BeanShellPreProcessor beanShellPreProcessor = key;