feat(接口测试): 导入的mqtt支持ms显示

--story=1010741 --user=王孝刚
【Bug转需求】[接口测试-MQTT]github#20278在MS平台已安装MQTT插件的情况下,上传包含MQTT取样器的JMX文件时,MQTT插件相关配置仍显示为原生xml,建议优化
https://www.tapd.cn/55049933/s/1320257
This commit is contained in:
wxg0103 2022-12-29 16:18:18 +08:00 committed by fit2-zhao
parent a9c5fe283b
commit d4b43e273a
1 changed files with 24 additions and 0 deletions

View File

@ -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<ScenarioImport> {
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<ScenarioImport> {
}
}
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;