From c7dfb4160b7ad58dd1192f0cd78571f3778ca407 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Tue, 19 Jan 2021 16:16:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=94=B9"=E4=B8=80=E4=BB=B6=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95"=E6=97=B6?= =?UTF-8?q?=E5=8E=8B=E5=8A=9B=E9=85=8D=E7=BD=AE=E4=B8=8B=E6=96=B9=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改图标、修改"一件创建性能测试"时压力配置下方显示的内容 --- .../api/controller/APITestController.java | 18 ++++++++++++++- .../controller/ApiAutomationController.java | 2 +- .../api/service/ApiAutomationService.java | 23 ++++++++++++++++++- .../job/sechedule/ApiScenarioTestJob.java | 2 +- .../automation/scenario/ApiScenarioList.vue | 7 +----- .../track/plan/components/TestPlanList.vue | 4 ++-- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java index a6ea2420b6..c45fdb9f25 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -13,6 +13,7 @@ import io.metersphere.api.dto.definition.RunDefinitionRequest; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter; import io.metersphere.api.service.*; +import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiTest; import io.metersphere.base.domain.LoadTest; import io.metersphere.base.domain.Schedule; @@ -34,6 +35,10 @@ import org.apache.http.entity.ContentType; import org.apache.jorphan.collections.HashTree; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -383,9 +388,20 @@ public class APITestController { } @PostMapping(value = "/genPerformanceTestXml", consumes = {"multipart/form-data"}) - public JmxInfoDTO genPerformanceTest(@RequestPart("request") RunDefinitionRequest runRequest, @RequestPart(value = "files") List bodyFiles) { + public JmxInfoDTO genPerformanceTest(@RequestPart("request") RunDefinitionRequest runRequest, @RequestPart(value = "files") List bodyFiles) throws Exception { HashTree hashTree = runRequest.getTestElement().generateHashTree(); String jmxString = runRequest.getTestElement().getJmx(hashTree); + + String testName = runRequest.getName(); + //将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); + jmxString = root.asXML(); + JmxInfoDTO dto = new JmxInfoDTO(); dto.setName(runRequest.getName()+".jmx"); dto.setXml(jmxString); diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index fd7706dff5..6da2ea66b8 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -127,7 +127,7 @@ public class ApiAutomationController { } @PostMapping(value = "/genPerformanceTestJmx") - public JmxInfoDTO genPerformanceTestJmx(@RequestBody RunScenarioRequest runRequest) { + public JmxInfoDTO genPerformanceTestJmx(@RequestBody RunScenarioRequest runRequest) throws Exception { runRequest.setExecuteType(ExecuteType.Completed.name()); return apiAutomationService.genPerformanceTestJmx(runRequest); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 6547e96ab4..5075d99e40 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -42,11 +42,17 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; +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.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -586,7 +592,7 @@ public class ApiAutomationService { request, ApiScenarioTestJob.getJobKey(request.getResourceId()), ApiScenarioTestJob.getTriggerKey(request.getResourceId()), ApiScenarioTestJob.class); } - public JmxInfoDTO genPerformanceTestJmx(RunScenarioRequest request) { + public JmxInfoDTO genPerformanceTestJmx(RunScenarioRequest request) throws Exception { List apiScenarios = null; List ids = request.getScenarioIds(); if (request.isSelectAllDate()) { @@ -594,11 +600,26 @@ public class ApiAutomationService { request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds()); } apiScenarios = extApiScenarioMapper.selectIds(ids); + String testName = ""; + if(!apiScenarios.isEmpty()){ + testName = apiScenarios.get(0).getName(); + } MsTestPlan testPlan = new MsTestPlan(); testPlan.setHashTree(new LinkedList<>()); HashTree jmeterHashTree = generateHashTree(apiScenarios, request, false); + + String jmx = testPlan.getJmx(jmeterHashTree); + //将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(); + String name = request.getName() + ".jmx"; JmxInfoDTO dto = new JmxInfoDTO(); diff --git a/backend/src/main/java/io/metersphere/job/sechedule/ApiScenarioTestJob.java b/backend/src/main/java/io/metersphere/job/sechedule/ApiScenarioTestJob.java index 42fe6de8e7..f238615e37 100644 --- a/backend/src/main/java/io/metersphere/job/sechedule/ApiScenarioTestJob.java +++ b/backend/src/main/java/io/metersphere/job/sechedule/ApiScenarioTestJob.java @@ -30,13 +30,13 @@ public class ApiScenarioTestJob extends MsScheduleJob { @Override public void execute(JobExecutionContext context) throws JobExecutionException { + JobKey jobKey = context.getTrigger().getJobKey(); JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); String resourceId = jobDataMap.getString("resourceId"); this.userId = jobDataMap.getString("userId"); this.expression = jobDataMap.getString("expression"); this.projectID = jobDataMap.getString("projectId"); - if(resourceId!=null){ scenarioIds = new ArrayList<>(); scenarioIds.add(resourceId); diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 0fb81a74e9..cb789b2788 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -75,14 +75,9 @@ - - - - - - diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index 59b6991858..b6f68ba8c7 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -121,10 +121,10 @@ @deleteClick="handleDelete(scope.row)">