From bbb218d60a5cb7d382fb29fe43448f385af28f23 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Sat, 20 Feb 2021 15:56:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90jmx?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=87=BD=E6=95=B0=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0tcp/sql/dubbl=E7=9A=84=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E8=8A=82=E7=82=B9=E8=BD=AC=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改生成jmx文件函数的逻辑,增加tcp/sql/dubbl的类名节点转化 --- .../api/service/APITestService.java | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 781ca72078..97cb243d15 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -463,33 +463,69 @@ public class APITestService { /** * @param jmxString 原JMX文件 - * @param testName 某些节点要替换的testName + * @param testNameParam 某些节点要替换的testName * @param isFromScenario 是否来源于场景 (来源于场景的话,testName要进行处理) * @return */ - public String updateJmxString(String jmxString, String testName, boolean isFromScenario) { - if (isFromScenario) { - //如果调用源来自场景, 原testName是 案例<->场景 ,需要进行切分,只保留案例名 - String[] testNameArr = testName.split("<->"); - if (testNameArr.length > 0) { - testName = testNameArr[0]; - } - } + public String updateJmxString(String jmxString, String testNameParam, boolean isFromScenario) { try { //将ThreadGroup的testname改为接口名称 Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板 Element root = doc.getRootElement(); Element rootHashTreeElement = root.element("hashTree"); Element innerHashTreeElement = rootHashTreeElement.elements("hashTree").get(0); - Element theadGroupElement = innerHashTreeElement.elements("ThreadGroup").get(0); - theadGroupElement.attribute("testname").setText(testName); - List thirdHashTreeElementList = innerHashTreeElement.elements("hashTree"); + + Element theadGroupElement = innerHashTreeElement.elements("ThreadGroup").get(0); + theadGroupElement.attribute("testname").setText(testNameParam); + for (Element element : thirdHashTreeElementList) { + String testName = testNameParam; List 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 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 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 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); + } + //检查有没有自定义参数 List scriptHashTreeElementList = element.elements("hashTree"); for (Element scriptHashTreeElement : scriptHashTreeElementList) {