From 572dbfb07c299cab8b22121458aed9bcca5800ae Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 7 Apr 2021 18:55:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E6=A1=88=E4=BE=8B=E8=BD=AC=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=A2url=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决接口定义案例转性能测试丢url的问题 --- .../api/controller/APITestController.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 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 9a0b8f1f41..01290fc68e 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APITestController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -1,5 +1,6 @@ package io.metersphere.api.controller; +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.*; @@ -10,15 +11,14 @@ import io.metersphere.api.dto.datacount.response.ApiDataCountDTO; import io.metersphere.api.dto.datacount.response.ExecutedCaseInfoDTO; import io.metersphere.api.dto.datacount.response.TaskInfoResult; import io.metersphere.api.dto.definition.RunDefinitionRequest; +import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter; import io.metersphere.api.service.*; import io.metersphere.base.domain.*; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.ScheduleGroup; -import io.metersphere.commons.utils.CronUtils; -import io.metersphere.commons.utils.PageUtils; -import io.metersphere.commons.utils.Pager; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.controller.request.QueryScheduleRequest; import io.metersphere.controller.request.ScheduleRequest; import io.metersphere.dto.ScheduleDao; @@ -34,10 +34,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; +import java.util.*; import static io.metersphere.commons.utils.JsonPathUtils.getListJson; @@ -70,6 +67,8 @@ public class APITestController { private CheckPermissionService checkPermissionService; @Resource private HistoricalDataUpgradeService historicalDataUpgradeService; + @Resource + private ApiTestEnvironmentService environmentService; @GetMapping("recent/{count}") public List recentTest(@PathVariable int count) { @@ -396,7 +395,19 @@ public class APITestController { @PostMapping(value = "/genPerformanceTestXml", consumes = {"multipart/form-data"}) public JmxInfoDTO genPerformanceTest(@RequestPart("request") RunDefinitionRequest runRequest, @RequestPart(value = "files") List bodyFiles) throws Exception { - HashTree hashTree = runRequest.getTestElement().generateHashTree(); + + ParameterConfig config = new ParameterConfig(); + config.setProjectId(runRequest.getProjectId()); + + Map envConfig = new HashMap<>(); + Map map = runRequest.getEnvironmentMap(); + if (map != null && map.size() > 0) { + ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(runRequest.getProjectId())); + EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + envConfig.put(runRequest.getProjectId(), env); + config.setConfig(envConfig); + } + HashTree hashTree = runRequest.getTestElement().generateHashTree(config); String jmxString = runRequest.getTestElement().getJmx(hashTree); String testName = runRequest.getName();