refactor: 更新jmx文件的DubboDefaultConfigGui信息

更新jmx文件的DubboDefaultConfigGui信息
This commit is contained in:
song.tianyang 2021-02-22 16:43:19 +08:00
parent cb1b9b1d67
commit 608ba81baa
1 changed files with 39 additions and 12 deletions

View File

@ -464,13 +464,14 @@ public class APITestService {
/**
* 更新jmx数据处理jmx里的各种参数
*
* <p>
* 与1.7分支合并时如果该方法产生冲突请以master为准
* @author song tianyang
*
* @param jmxString 原JMX文件
* @param testNameParam 某些节点要替换的testName
* @param isFromScenario 是否来源于场景 来源于场景的话testName要进行处理
* @return
* @author song tianyang
*/
public String updateJmxString(String jmxString, String testNameParam, boolean isFromScenario) {
// 与1.7分支合并时如果该方法产生冲突请以master为准
@ -485,14 +486,19 @@ public class APITestService {
List<Element> innerHashTreeElementList = rootHashTreeElement.elements("hashTree");
for (Element innerHashTreeElement : innerHashTreeElementList) {
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
//转换DubboDefaultConfigGui
List<Element> configTestElementList = innerHashTreeElement.elements("ConfigTestElement");
for (Element configTestElement : configTestElementList) {
this.updateDubboDefaultConfigGuiElement(configTestElement);
}
List<Element> theadGroupElementList = innerHashTreeElement.elements("ThreadGroup");
for (Element theadGroupElement : theadGroupElementList) {
if (StringUtils.isNotEmpty(testNameParam)) {
theadGroupElement.attribute(attribute_testName).setText(testNameParam);
}
}
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
for (Element element : thirdHashTreeElementList) {
String testName = testNameParam;
@ -500,15 +506,36 @@ public class APITestService {
this.updateRequestElementInfo(element, testNameParam, requestElementNameArr, isFromScenario);
//检查有无jmeter不是别的自定义参数
this.checkPrivateFunctionNode(element);
//转换DubboDefaultConfigGui
List<Element> hashTreeConfigTestElementList = element.elements("ConfigTestElement");
for (Element configTestElement : hashTreeConfigTestElementList) {
this.updateDubboDefaultConfigGuiElement(configTestElement);
}
}
}
jmxString = root.asXML();
} catch (Exception e) {
e.printStackTrace();
}
if (!jmxString.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")) {
jmxString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + jmxString;
}
return jmxString;
}
private void updateDubboDefaultConfigGuiElement(Element configTestElement) {
String dubboDefaultConfigGuiClassName = "io.github.ningyu.jmeter.plugin.dubbo.gui.DubboDefaultConfigGui";
if (configTestElement == null) {
return;
}
String guiClassValue = configTestElement.attributeValue("guiclass");
if (StringUtils.equals(guiClassValue, "DubboDefaultConfigGui")) {
configTestElement.attribute("guiclass").setText(dubboDefaultConfigGuiClassName);
}
}
private void checkPrivateFunctionNode(Element element) {
List<Element> scriptHashTreeElementList = element.elements("hashTree");
for (Element scriptHashTreeElement : scriptHashTreeElementList) {