fix: 修复更新jmx文件时未更新dubbo节点信息的缺陷

修复更新jmx文件时未更新dubbo节点信息的缺陷
This commit is contained in:
song.tianyang 2021-02-22 11:41:19 +08:00
parent 85cd5077f5
commit c737b01c27
1 changed files with 86 additions and 86 deletions

View File

@ -463,77 +463,53 @@ public class APITestService {
}
/**
* 更新jmx数据处理jmx里的各种参数
*
* 与1.7分支合并时如果该方法产生冲突请以master为准
* @author song tianyang
* @param jmxString 原JMX文件
* @param testNameParam 某些节点要替换的testName
* @param isFromScenario 是否来源于场景 来源于场景的话testName要进行处理
* @return
*/
public String updateJmxString(String jmxString, String testNameParam, boolean isFromScenario) {
// 与1.7分支合并时如果该方法产生冲突请以master为准
String attribute_testName = "testname";
String [] requestElementNameArr = new String[]{"HTTPSamplerProxy","TCPSampler","JDBCSampler","DubboSample"};
try {
//将ThreadGroup的testname改为接口名称
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
Element root = doc.getRootElement();
Element rootHashTreeElement = root.element("hashTree");
Element innerHashTreeElement = rootHashTreeElement.elements("hashTree").get(0);
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
Element theadGroupElement = innerHashTreeElement.elements("ThreadGroup").get(0);
theadGroupElement.attribute("testname").setText(testNameParam);
List<Element> innerHashTreeElementList = rootHashTreeElement.elements("hashTree");
for (Element innerHashTreeElement : innerHashTreeElementList) {
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
List<Element> theadGroupElementList = innerHashTreeElement.elements("ThreadGroup");
for (Element theadGroupElement : theadGroupElementList) {
if(StringUtils.isNotEmpty(testNameParam)){
theadGroupElement.attribute(attribute_testName).setText(testNameParam);
}
}
for (Element element : thirdHashTreeElementList) {
String testName = testNameParam;
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
for (Element itemElement : sampleProxyElementList) {
if(isFromScenario){
testName = itemElement.attributeValue("testname");
String[] testNameArr = testName.split("<->");
if (testNameArr.length > 0) {
testName = testNameArr[0];
}
}
itemElement.attribute("testname").setText(testName);
}
List<Element> tcpSamplerList = element.elements("TCPSampler");
for (Element itemElement : tcpSamplerList) {
if(isFromScenario){
testName = itemElement.attributeValue("testname");
String[] testNameArr = testName.split("<->");
if (testNameArr.length > 0) {
testName = testNameArr[0];
}
}
itemElement.attribute("testname").setText(testName);
}
List<Element> jdbcSamplerList = element.elements("JDBCSampler");
for (Element itemElement : jdbcSamplerList) {
if(isFromScenario){
testName = itemElement.attributeValue("testname");
String[] testNameArr = testName.split("<->");
if (testNameArr.length > 0) {
testName = testNameArr[0];
}
}
itemElement.attribute("testname").setText(testName);
}
List<Element> dubboSampleList = element.elements("DubboSample");
for (Element itemElement : dubboSampleList) {
if(isFromScenario){
testName = itemElement.attributeValue("testname");
String[] testNameArr = testName.split("<->");
if (testNameArr.length > 0) {
testName = testNameArr[0];
}
}
itemElement.attribute("testname").setText(testName);
//dubbo节点要更新 标签guiClass testClass
itemElement.setName("io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample");
itemElement.attribute("testclass").setText("io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample");
itemElement.attribute("guiclass").setText("io.github.ningyu.jmeter.plugin.dubbo.gui.DubboSampleGui");
//更新请求类节点的部份属性
this.updateRequestElementInfo(element,testNameParam,requestElementNameArr,isFromScenario);
//检查有无jmeter不是别的自定义参数
this.checkPrivateFunctionNode(element);
}
}
jmxString = root.asXML();
} catch (Exception e) {
e.printStackTrace();
}
return jmxString;
}
//检查有没有自定义参数
private void checkPrivateFunctionNode(Element element) {
List<Element> scriptHashTreeElementList = element.elements("hashTree");
for (Element scriptHashTreeElement : scriptHashTreeElementList) {
boolean isRemove = false;
@ -548,6 +524,7 @@ public class APITestService {
removeElement.add(hashTreeItemElement);
}
}
isRemove = false;
if (org.apache.commons.lang3.StringUtils.equals(className, "JSR223PostProcessor")) {
List<Element> scriptElements = hashTreeItemElement.elements("stringProp");
@ -567,10 +544,33 @@ public class APITestService {
}
}
}
jmxString = root.asXML();
} catch (Exception e) {
e.printStackTrace();
}
return jmxString;
private void updateRequestElementInfo(Element element,String testNameParam,String [] requestElementNameArr,boolean isFromScenario){
String attribute_testName = "testname";
String scenarioCaseNameSplit = "<->";
String testName = testNameParam;
for(String requestElementName : requestElementNameArr){
List<Element> sampleProxyElementList = element.elements(requestElementName);
for (Element itemElement : sampleProxyElementList) {
if(isFromScenario){
testName = itemElement.attributeValue(attribute_testName);
String[] testNameArr = testName.split(scenarioCaseNameSplit);
if (testNameArr.length > 0) {
testName = testNameArr[0];
}
}
itemElement.attribute(attribute_testName).setText(testName);
//double的话有额外处理方式
if(StringUtils.equals(requestElementName,"DubboSample")){
//dubbo节点要更新 标签guiClass testClass
itemElement.setName("io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample");
itemElement.attribute("testclass").setText("io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample");
itemElement.attribute("guiclass").setText("io.github.ningyu.jmeter.plugin.dubbo.gui.DubboSampleGui");
}
}
}
}
}