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 71bcb99f86..1ea5523f52 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 @@ -4,6 +4,9 @@ import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +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.assertions.MsAssertions; import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.configurations.MsHeaderManager; @@ -16,6 +19,9 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; import io.metersphere.api.dto.definition.request.timer.MsConstantTimer; +import io.metersphere.api.service.ApiDefinitionService; +import io.metersphere.base.domain.ApiDefinitionWithBLOBs; +import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import lombok.Data; import org.apache.jmeter.protocol.http.control.AuthManager; @@ -50,7 +56,7 @@ import java.util.List; MsJSR223PreProcessor.class, MsTestPlan.class, MsThreadGroup.class, AuthManager.class, MsAssertions.class, MsExtract.class, MsTCPSampler.class, MsDubboSampler.class, MsJDBCSampler.class, MsConstantTimer.class, MsIfController.class, MsScenario.class}, typeKey = "type") @Data -public class MsTestElement { +public abstract class MsTestElement { private String type; @JSONField(ordinal = 1) private String id; @@ -106,6 +112,19 @@ public class MsTestElement { return jmeterTestPlanHashTree; } + public void getRefElement(MsTestElement element) { + try { + ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId()); + 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/MsDubboSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 7cafdada30..c00425cfdc 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -52,6 +52,13 @@ public class MsDubboSampler extends MsTestElement { private List attachmentArgs; public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + if (this.getReferenced() != null && this.getReferenced().equals("Deleted")) { + return; + } + if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + this.getRefElement(this); + } + final HashTree testPlanTree = new ListedHashTree(); testPlanTree.add(dubboConfig()); tree.set(dubboSample(), testPlanTree); 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 5106f1209d..5da51841a5 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 @@ -86,6 +86,9 @@ public class MsHTTPSamplerProxy extends MsTestElement { private List arguments; public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + this.getRefElement(this); + } HTTPSamplerProxy sampler = new HTTPSamplerProxy(); sampler.setEnabled(true); sampler.setName(this.getName()); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index 3c0ca2c866..64eaecb497 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -40,6 +40,9 @@ public class MsJDBCSampler extends MsTestElement { private String environmentId; public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + this.getRefElement(this); + } final HashTree samplerHashTree = tree.add(jdbcSampler()); tree.add(jdbcDataSource()); tree.add(arguments(this.getName() + " Variables", this.getVariables())); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index def4cda1b6..9a563e0cb5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -50,6 +50,9 @@ public class MsTCPSampler extends MsTestElement { private String request; public void toHashTree(HashTree tree, List hashTree, ParameterConfig config) { + if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + this.getRefElement(this); + } final HashTree samplerHashTree = new ListedHashTree(); samplerHashTree.add(tcpConfig()); tree.set(tcpSampler(), samplerHashTree); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index ae38edc769..5851ca24ec 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -105,6 +105,10 @@ public class ApiDefinitionService { return apiDefinitionMapper.selectByPrimaryKey(id); } + public ApiDefinitionWithBLOBs getBLOBs(String id) { + return apiDefinitionMapper.selectByPrimaryKey(id); + } + public void create(SaveApiDefinitionRequest request, List bodyFiles) { List bodyUploadIds = new ArrayList<>(request.getBodyUploadIds()); createTest(request); diff --git a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue index 47e671124b..94a25f0aa0 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiComponent.vue @@ -12,7 +12,7 @@ {{request.type!= 'create' ? request.name:''}} - 引用不存在 + {{$t('api_test.automation.reference_deleted')}} {{ $t('api_test.scenario.reference') }} @@ -62,6 +62,17 @@ return {loading: false, reqOptions: REQ_METHOD,} }, created() { + if (this.request.id && this.request.referenced === 'REF') { + this.$get("/api/definition/get/" + this.request.id, response => { + if (response.data) { + this.request.name = response.data.name; + this.reload(); + } else { + this.request.referenced = "Deleted"; + } + }) + } + if (this.request.protocol === 'HTTP') { try { let urlObject = new URL(this.request.url); diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioComponent.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioComponent.vue index 44f57f0b39..156b04d636 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioComponent.vue @@ -6,7 +6,7 @@
{{scenario.index}}
{{scenario.name}}
- 引用不存在 + {{$t('api_test.automation.reference_deleted')}} {{ $t('api_test.scenario.reference') }} diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 968213f16b..230e296b21 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -239,8 +239,8 @@ - - {{ $t('commons.copy') }} + {{$t('api_test.scenario.reference')}} + {{ $t('commons.copy') }} @@ -362,7 +362,7 @@ watch: {}, methods: { nodeClick(e) { - if (e.referenced != 'REF') { + if (e.referenced != 'REF' && e.referenced != 'Deleted') { this.operatingElements = ELEMENTS.get(e.type); } else { this.operatingElements = []; diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index a22a3005d9..8a972a1987 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit a22a3005d9bd254793fcf634d72539cbdf31be3a +Subproject commit 8a972a198775b3783ed6e4cef27197e53d1ebdc8 diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index c686cafc36..654b9a7570 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -584,6 +584,7 @@ export default { }, report_name_info: 'Please enter the registration name', save_case_info: 'Please save the use case first', + reference_deleted: 'Reference deleted', }, environment: { name: "Environment Name", diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 35bffd407f..8dfb0f5608 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -583,6 +583,7 @@ export default { }, report_name_info: '请输入报名名称', save_case_info: '请先保存用例', + reference_deleted: '引用已删除', }, environment: { name: "环境名称", diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 0b668fb8bc..e877b4631b 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -583,6 +583,7 @@ export default { }, report_name_info: '請輸入報名名稱', save_case_info: '請先保存用例', + reference_deleted: '引用已删除', }, environment: { name: "環境名稱",