parent
85cd5077f5
commit
c737b01c27
|
@ -463,108 +463,43 @@ public class APITestService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 更新jmx数据,处理jmx里的各种参数
|
||||||
|
*
|
||||||
|
* 注: 与1.7分支合并时,如果该方法产生冲突,请以master为准
|
||||||
|
* @author song tianyang
|
||||||
* @param jmxString 原JMX文件
|
* @param jmxString 原JMX文件
|
||||||
* @param testNameParam 某些节点要替换的testName
|
* @param testNameParam 某些节点要替换的testName
|
||||||
* @param isFromScenario 是否来源于场景 (来源于场景的话,testName要进行处理)
|
* @param isFromScenario 是否来源于场景 (来源于场景的话,testName要进行处理)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String updateJmxString(String jmxString, String testNameParam, boolean isFromScenario) {
|
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 {
|
try {
|
||||||
//将ThreadGroup的testname改为接口名称
|
//将ThreadGroup的testname改为接口名称
|
||||||
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
|
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
|
||||||
Element root = doc.getRootElement();
|
Element root = doc.getRootElement();
|
||||||
Element rootHashTreeElement = root.element("hashTree");
|
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);
|
List<Element> innerHashTreeElementList = rootHashTreeElement.elements("hashTree");
|
||||||
theadGroupElement.attribute("testname").setText(testNameParam);
|
for (Element innerHashTreeElement : innerHashTreeElementList) {
|
||||||
|
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
|
||||||
for (Element element : thirdHashTreeElementList) {
|
List<Element> theadGroupElementList = innerHashTreeElement.elements("ThreadGroup");
|
||||||
String testName = testNameParam;
|
for (Element theadGroupElement : theadGroupElementList) {
|
||||||
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
|
if(StringUtils.isNotEmpty(testNameParam)){
|
||||||
for (Element itemElement : sampleProxyElementList) {
|
theadGroupElement.attribute(attribute_testName).setText(testNameParam);
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//检查有没有自定义参数
|
for (Element element : thirdHashTreeElementList) {
|
||||||
List<Element> scriptHashTreeElementList = element.elements("hashTree");
|
String testName = testNameParam;
|
||||||
for (Element scriptHashTreeElement : scriptHashTreeElementList) {
|
|
||||||
boolean isRemove = false;
|
|
||||||
List<Element> removeElement = new ArrayList<>();
|
|
||||||
List<Element> scriptElementItemList = scriptHashTreeElement.elements();
|
|
||||||
for (Element hashTreeItemElement : scriptElementItemList) {
|
|
||||||
String className = hashTreeItemElement.attributeValue("testclass");
|
|
||||||
String qname = hashTreeItemElement.getQName().getName();
|
|
||||||
|
|
||||||
if (isRemove) {
|
//更新请求类节点的部份属性
|
||||||
if (org.apache.commons.lang3.StringUtils.equals("hashTree", qname)) {
|
this.updateRequestElementInfo(element,testNameParam,requestElementNameArr,isFromScenario);
|
||||||
removeElement.add(hashTreeItemElement);
|
//检查有无jmeter不是别的自定义参数
|
||||||
}
|
this.checkPrivateFunctionNode(element);
|
||||||
}
|
|
||||||
isRemove = false;
|
|
||||||
if (org.apache.commons.lang3.StringUtils.equals(className, "JSR223PostProcessor")) {
|
|
||||||
List<Element> scriptElements = hashTreeItemElement.elements("stringProp");
|
|
||||||
for (Element scriptElement : scriptElements) {
|
|
||||||
String scriptName = scriptElement.attributeValue("name");
|
|
||||||
String contentValue = scriptElement.getStringValue();
|
|
||||||
|
|
||||||
if ("script".equals(scriptName) && contentValue.startsWith("io.metersphere.api.jmeter.JMeterVars.addVars")) {
|
|
||||||
isRemove = true;
|
|
||||||
removeElement.add(hashTreeItemElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Element itemElement : removeElement) {
|
|
||||||
scriptHashTreeElement.remove(itemElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jmxString = root.asXML();
|
jmxString = root.asXML();
|
||||||
|
@ -573,4 +508,69 @@ public class APITestService {
|
||||||
}
|
}
|
||||||
return jmxString;
|
return jmxString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkPrivateFunctionNode(Element element) {
|
||||||
|
List<Element> scriptHashTreeElementList = element.elements("hashTree");
|
||||||
|
for (Element scriptHashTreeElement : scriptHashTreeElementList) {
|
||||||
|
boolean isRemove = false;
|
||||||
|
List<Element> removeElement = new ArrayList<>();
|
||||||
|
List<Element> scriptElementItemList = scriptHashTreeElement.elements();
|
||||||
|
for (Element hashTreeItemElement : scriptElementItemList) {
|
||||||
|
String className = hashTreeItemElement.attributeValue("testclass");
|
||||||
|
String qname = hashTreeItemElement.getQName().getName();
|
||||||
|
|
||||||
|
if (isRemove) {
|
||||||
|
if (org.apache.commons.lang3.StringUtils.equals("hashTree", qname)) {
|
||||||
|
removeElement.add(hashTreeItemElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isRemove = false;
|
||||||
|
if (org.apache.commons.lang3.StringUtils.equals(className, "JSR223PostProcessor")) {
|
||||||
|
List<Element> scriptElements = hashTreeItemElement.elements("stringProp");
|
||||||
|
for (Element scriptElement : scriptElements) {
|
||||||
|
String scriptName = scriptElement.attributeValue("name");
|
||||||
|
String contentValue = scriptElement.getStringValue();
|
||||||
|
|
||||||
|
if ("script".equals(scriptName) && contentValue.startsWith("io.metersphere.api.jmeter.JMeterVars.addVars")) {
|
||||||
|
isRemove = true;
|
||||||
|
removeElement.add(hashTreeItemElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Element itemElement : removeElement) {
|
||||||
|
scriptHashTreeElement.remove(itemElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue