diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java index ce580ed8da..9242bb2a23 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsTestElement.java @@ -27,8 +27,10 @@ import io.metersphere.api.dto.definition.request.variable.ScenarioVariable; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.LoopConstants; import io.metersphere.commons.constants.MsTestElementConstants; @@ -158,12 +160,23 @@ public abstract class MsTestElement { ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(element.getId()); - if (apiDefinition != null) { - element.setProjectId(apiDefinition.getProjectId()); - element = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { - }); - hashTree.add(element); + if (StringUtils.equals(element.getRefType(), "CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(element.getId()); + if (bloBs != null) { + element.setProjectId(bloBs.getProjectId()); + element = mapper.readValue(bloBs.getRequest(), new TypeReference() { + }); + hashTree.add(element); + } + } else { + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(element.getId()); + if (apiDefinition != null) { + element.setProjectId(apiDefinition.getProjectId()); + element = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { + }); + hashTree.add(element); + } } } catch (Exception ex) { ex.printStackTrace(); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 3df2442f58..b78fa5071b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -2,6 +2,9 @@ package io.metersphere.api.dto.definition.request.sampler; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.auth.MsAuthManager; @@ -11,10 +14,10 @@ import io.metersphere.api.dto.scenario.HttpConfig; import io.metersphere.api.dto.scenario.HttpConfigCondition; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.service.ApiDefinitionService; -import io.metersphere.api.service.ApiModuleService; -import io.metersphere.api.service.ApiTestEnvironmentService; +import io.metersphere.api.service.ApiTestCaseService; import io.metersphere.base.domain.ApiDefinition; -import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.ConditionType; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; @@ -102,6 +105,35 @@ public class MsHTTPSamplerProxy extends MsTestElement { @JSONField(ordinal = 36) private MsAuthManager authManager; + public void setRefElement() { + try { + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + if (StringUtils.equals(this.getRefType(), "CASE")) { + ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); + if (bloBs != null) { + this.setProjectId(bloBs.getProjectId()); + MsHTTPSamplerProxy proxy = mapper.readValue(bloBs.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + } + } else { + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + if (apiDefinition != null) { + this.setProjectId(apiDefinition.getProjectId()); + MsHTTPSamplerProxy proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference() { + }); + this.setHashTree(proxy.getHashTree()); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + LogUtil.error(ex.getMessage()); + } + } + @Override public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { // 非导出操作,且不是启用状态则跳过执行 @@ -109,7 +141,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { return; } if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { - this.getRefElement(this); + this.setRefElement(); + hashTree = this.getHashTree(); } HTTPSamplerProxy sampler = new HTTPSamplerProxy(); sampler.setEnabled(this.isEnable()); diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 180b05750b..3b37ef8a6b 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -180,6 +180,9 @@ } }, addTab(tab) { + if(tab.name==='default'){ + this.$refs.apiScenarioList.search(); + } if (!this.projectId) { this.$warning(this.$t('commons.check_project_tip')); return; diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioEnv.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioEnv.vue index 85bbcc697e..c705b6c980 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioEnv.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioEnv.vue @@ -12,7 +12,7 @@ {{ $t('api_test.environment.environment_config') }} diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 8f057411e1..10bfe76800 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -553,8 +553,6 @@ export default { if (!(environment.config instanceof Object)) { environment.config = JSON.parse(environment.config); } - environment.name = environment.name + (environment.config.httpConfig.socket ? - (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : ''); }); }); }, diff --git a/frontend/src/business/components/api/automation/scenario/EnvSelect.vue b/frontend/src/business/components/api/automation/scenario/EnvSelect.vue index 23b8e387cf..44d5c268d1 100644 --- a/frontend/src/business/components/api/automation/scenario/EnvSelect.vue +++ b/frontend/src/business/components/api/automation/scenario/EnvSelect.vue @@ -3,7 +3,7 @@
diff --git a/frontend/src/business/components/api/automation/scenario/common/RunMode.vue b/frontend/src/business/components/api/automation/scenario/common/RunMode.vue index 456534d58c..fc764501bb 100644 --- a/frontend/src/business/components/api/automation/scenario/common/RunMode.vue +++ b/frontend/src/business/components/api/automation/scenario/common/RunMode.vue @@ -19,7 +19,7 @@ {{ $t("run_mode.set_report") }}
-
+
{{ $t("run_mode.report_name") }}: {{ $t('api_test.environment.environment_config') }} diff --git a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue index 36937ae2cc..f732fef954 100644 --- a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue +++ b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue @@ -79,8 +79,7 @@ return environment.name; } } - return environment.name + (environment.config.httpConfig.socket ? - (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : ''); + return environment.name; } return ""; }, diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index ed6844a605..c1fefc5fbb 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -632,6 +632,9 @@ export default { row.request = JSON.parse(row.request); row.request.name = row.id; row.request.useEnvironment = environment.id; + let map = new Map; + map.set(row.projectId,environment.id); + row.environmentMap = map; runData.push(row.request); /*触发执行操作*/ let testPlan = new TestPlan(); diff --git a/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue b/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue index c07d9d5d1b..1b865d6350 100644 --- a/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue +++ b/frontend/src/business/components/api/definition/components/reference/ApiExtendBtns.vue @@ -46,7 +46,7 @@ this.$warning(this.$t('api_test.automation.save_case_info')) } }, - createPerformance(row){ + createPerformance(row) { /** * 思路:调用后台创建性能测试的方法,把当前案例的hashTree在后台转化为jmx并文件创建性能测试。 * 然后跳转到修改性能测试的页面 @@ -61,7 +61,7 @@ this.runData = []; this.singleLoading = true; this.row.request.name = this.row.id; - this.row.request.useEnvironment = this.environment.id; + this.row.request.useEnvironment = this.environment; this.runData.push(this.row.request); /*触发执行操作*/ let testPlan = new TestPlan(); @@ -71,18 +71,21 @@ this.runData.forEach(item => { threadGroup.hashTree.push(item); }) - let reqObj = {id: this.row.id, + let reqObj = { + id: this.row.id, testElement: testPlan, type: this.type, - name:this.row.name, - projectId:getCurrentProjectID(), + name: this.row.name, + projectId: getCurrentProjectID(), + environmentMap: new Map([ + [getCurrentProjectID(), this.environment.id] + ]), }; let bodyFiles = getBodyUploadFiles(reqObj, this.runData); reqObj.reportId = "run"; // let url = "/api/genPerformanceTest"; let url = "/api/genPerformanceTestXml"; - this.$fileUpload(url, null, bodyFiles, reqObj, response => { let jmxObj = {}; jmxObj.name = response.data.name; @@ -97,12 +100,6 @@ this.$router.push({ path: "/performance/test/create" }) - // let performanceId = response.data; - // if(performanceId!=null){ - // this.$router.push({ - // path: "/performance/test/edit/"+performanceId, - // }) - // } }, erro => { this.$emit('runRefresh', {}); }); diff --git a/frontend/src/business/components/api/test/components/environment/EnvironmentHttpConfig.vue b/frontend/src/business/components/api/test/components/environment/EnvironmentHttpConfig.vue index dc2a75032a..3c94b47d81 100644 --- a/frontend/src/business/components/api/test/components/environment/EnvironmentHttpConfig.vue +++ b/frontend/src/business/components/api/test/components/environment/EnvironmentHttpConfig.vue @@ -22,7 +22,7 @@ {{$t('commons.update')}}
- +
@@ -36,7 +36,7 @@
- +