# Conflicts:
#	backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java
This commit is contained in:
fit2-zhao 2021-02-20 15:57:24 +08:00
commit adda8ff8a1
3 changed files with 19 additions and 8 deletions

View File

@ -393,7 +393,7 @@ public class APITestController {
String testName = runRequest.getName();
//将jmx处理封装为通用方法
jmxString = apiTestService.updateJmxString(jmxString,testName,true);
jmxString = apiTestService.updateJmxString(jmxString,testName,false);
JmxInfoDTO dto = new JmxInfoDTO();
dto.setName(runRequest.getName() + ".jmx");

View File

@ -461,7 +461,20 @@ public class APITestService {
});
}
public String updateJmxString(String jmxString,String testName,boolean updateHTTPSamplerProxyName) {
/**
* @param jmxString 原JMX文件
* @param testName 某些节点要替换的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];
}
}
try {
//将ThreadGroup的testname改为接口名称
Document doc = DocumentHelper.parseText(jmxString);// 获取可续保保单列表报文模板
@ -473,12 +486,10 @@ public class APITestService {
List<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
for (Element element : thirdHashTreeElementList) {
if(updateHTTPSamplerProxyName){
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
for (Element itemElement : sampleProxyElementList) {
itemElement.attribute("testname").setText(testName);
}
}
//检查有没有自定义参数
List<Element> scriptHashTreeElementList = element.elements("hashTree");
for (Element scriptHashTreeElement : scriptHashTreeElementList) {

View File

@ -709,7 +709,7 @@ public class ApiAutomationService {
HashTree jmeterHashTree = generateHashTree(apiScenarios, request, null);
String jmx = testPlan.getJmx(jmeterHashTree);
jmx = apiTestService.updateJmxString(jmx, testName, false);
jmx = apiTestService.updateJmxString(jmx,testName,true);
//将ThreadGroup的testname改为接口名称
// Document doc = DocumentHelper.parseText(jmx);// 获取可续保保单列表报文模板