Merge branch 'v1.7' of github.com:metersphere/metersphere into v1.7
This commit is contained in:
commit
8aaa11fb0b
|
@ -31,6 +31,7 @@ import io.metersphere.service.CheckPermissionService;
|
|||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
import io.metersphere.track.request.testplan.SaveTestPlanRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
|
@ -378,6 +379,7 @@ public class APITestController {
|
|||
schedule.setEnable(request.isEnable());
|
||||
apiAutomationService.updateSchedule(schedule);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/historicalDataUpgrade")
|
||||
public String historicalDataUpgrade(@RequestBody SaveHistoricalDataUpgrade request) {
|
||||
return historicalDataUpgradeService.upgrade(request);
|
||||
|
@ -390,27 +392,8 @@ public class APITestController {
|
|||
|
||||
String testName = runRequest.getName();
|
||||
|
||||
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<Element> thirdHashTreeElementList =innerHashTreeElement.elements("hashTree");
|
||||
for (Element element:thirdHashTreeElementList) {
|
||||
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
|
||||
for (Element itemElement: sampleProxyElementList) {
|
||||
itemElement.attribute("testname").setText(testName);
|
||||
}
|
||||
}
|
||||
|
||||
jmxString = root.asXML();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
//将jmx处理封装为通用方法
|
||||
jmxString = apiTestService.updateJmxString(jmxString,testName,true);
|
||||
|
||||
JmxInfoDTO dto = new JmxInfoDTO();
|
||||
dto.setName(runRequest.getName() + ".jmx");
|
||||
|
|
|
@ -32,6 +32,9 @@ import io.metersphere.track.service.TestCaseService;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -457,4 +460,88 @@ public class APITestService {
|
|||
copyBodyFiles(test.getId(), sourceId);
|
||||
});
|
||||
}
|
||||
|
||||
public String updateJmxString(String jmxString,String testName,boolean updateHTTPSamplerProxyName) {
|
||||
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<Element> thirdHashTreeElementList = innerHashTreeElement.elements("hashTree");
|
||||
for (Element element : thirdHashTreeElementList) {
|
||||
List<Element> sampleProxyElementList = element.elements("HTTPSamplerProxy");
|
||||
for (Element itemElement : sampleProxyElementList) {
|
||||
if(updateHTTPSamplerProxyName){
|
||||
itemElement.attribute("testname").setText(testName);
|
||||
}
|
||||
}
|
||||
List<Element> tcpSamplerList = element.elements("TCPSampler");
|
||||
for (Element itemElement : tcpSamplerList) {
|
||||
if(updateHTTPSamplerProxyName){
|
||||
itemElement.attribute("testname").setText(testName);
|
||||
}
|
||||
}
|
||||
List<Element> jdbcSamplerList = element.elements("JDBCSampler");
|
||||
for (Element itemElement : jdbcSamplerList) {
|
||||
if(updateHTTPSamplerProxyName){
|
||||
itemElement.attribute("testname").setText(testName);
|
||||
}
|
||||
}
|
||||
List<Element> dubboSampleList = element.elements("DubboSample");
|
||||
for (Element itemElement : dubboSampleList) {
|
||||
if(updateHTTPSamplerProxyName){
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
//检查有没有自定义参数
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
jmxString = root.asXML();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jmxString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ public class ApiAutomationService {
|
|||
@Resource
|
||||
private ApiScenarioMapper apiScenarioMapper;
|
||||
@Resource
|
||||
private APITestService apiTestService;
|
||||
@Resource
|
||||
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
|
@ -680,14 +682,17 @@ public class ApiAutomationService {
|
|||
|
||||
HashTree jmeterHashTree = generateHashTree(apiScenarios, request, null);
|
||||
String jmx = testPlan.getJmx(jmeterHashTree);
|
||||
|
||||
jmx = apiTestService.updateJmxString(jmx,testName,false);
|
||||
|
||||
//将ThreadGroup的testname改为接口名称
|
||||
Document doc = DocumentHelper.parseText(jmx);// 获取可续保保单列表报文模板
|
||||
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);
|
||||
jmx = root.asXML();
|
||||
// Document doc = DocumentHelper.parseText(jmx);// 获取可续保保单列表报文模板
|
||||
// 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);
|
||||
// jmx = root.asXML();
|
||||
|
||||
String name = request.getName() + ".jmx";
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ public class TestPlanService {
|
|||
testPlan.setActualEndTime(null);
|
||||
} // 已完成->进行中,结束时间置空
|
||||
} else if (!res.getStatus().equals(TestPlanStatus.Prepare.name()) &&
|
||||
testPlan.getStatus().equals(TestPlanStatus.Prepare.name())) {
|
||||
TestPlanStatus.Prepare.name().equals(testPlan.getStatus())) {
|
||||
testPlan.setActualStartTime(null);
|
||||
testPlan.setActualEndTime(null);
|
||||
} // 非未开始->未开始,时间都置空
|
||||
|
@ -193,7 +193,7 @@ public class TestPlanService {
|
|||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add(testPlan.getPrincipal());
|
||||
AddTestPlanRequest testPlans = new AddTestPlanRequest();
|
||||
int i = testPlanMapper.updateByPrimaryKey(testPlan); // 更新
|
||||
int i = testPlanMapper.updateByPrimaryKeySelective(testPlan); // 更新
|
||||
if (!StringUtils.isBlank(testPlan.getStatus())) {
|
||||
BeanUtils.copyBean(testPlans, getTestPlan(testPlan.getId()));
|
||||
String context = getTestPlanContext(testPlans, NoticeConstants.Event.UPDATE);
|
||||
|
|
Loading…
Reference in New Issue