diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenrioExportJmx.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenrioExportJmx.java index bd42d877bc..6bba2dddd5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenrioExportJmx.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenrioExportJmx.java @@ -3,11 +3,14 @@ package io.metersphere.api.dto.automation; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter public class ApiScenrioExportJmx { private String name; private String jmx; + List files; public ApiScenrioExportJmx(String name, String jmx) { this.name = name; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java index c05bedc7b9..66bfed1007 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java @@ -3,8 +3,10 @@ package io.metersphere.api.dto.definition.request.processors; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; +import io.metersphere.api.dto.RunningParamKeys; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.commons.constants.DelimiterConstants; import lombok.Data; import lombok.EqualsAndHashCode; @@ -15,6 +17,7 @@ import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; +import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -32,6 +35,27 @@ public class MsJSR223Processor extends MsTestElement { @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + //替换Metersphere环境变量 + if(StringUtils.isEmpty(this.getUseEnviroment())){ + if(config.getConfig() != null){ + if(config.getProjectId() != null){ + String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); + this.setUseEnviroment(evnId); + }else { + Collection evnConfigList = config.getConfig().values(); + if(evnConfigList!=null && !evnConfigList.isEmpty()){ + for (EnvironmentConfig configItem : evnConfigList) { + String evnId = configItem.getApiEnvironmentid(); + this.setUseEnviroment(evnId); + break; + } + } + } + + } + } + script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnviroment()+".\""); + // 非导出操作,且不是启用状态则跳过执行 if (!config.isOperating() && !this.isEnable()) { return; 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 e4544b648b..747552b019 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -47,6 +47,7 @@ import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testplan.FileOperationRequest; import io.metersphere.track.service.TestPlanScenarioCaseService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; @@ -1657,6 +1658,19 @@ public class ApiAutomationService { String jmx = generateJmx(item); if (StringUtils.isNotEmpty(jmx)) { ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(jmx, null, true).getXml()); + //扫描需要哪些文件 + JmxInfoDTO dto = apiTestService.updateJmxString(jmx, item.getName(), true); + if(MapUtils.isNotEmpty(dto.getAttachFiles())){ + List fileList = new ArrayList<>(); + for (String fileName: dto.getAttachFiles().values()) { + if(!fileList.contains(fileName)){ + fileList.add(fileName); + } + } + if(!fileList.isEmpty()){ + scenrioExportJmx.setFiles(fileList); + } + } resList.add(scenrioExportJmx); } } diff --git a/frontend/src/business/components/api/definition/components/mock/MockConfig.vue b/frontend/src/business/components/api/definition/components/mock/MockConfig.vue index 3b1db7a1dc..02bc7ff61e 100644 --- a/frontend/src/business/components/api/definition/components/mock/MockConfig.vue +++ b/frontend/src/business/components/api/definition/components/mock/MockConfig.vue @@ -42,7 +42,7 @@ -