From 98f3391c75ab7ea7ae70744532895b6ea72cfd2b Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 28 Jan 2021 14:50:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/dto/definition/request/MsTestElement.java | 13 ++++++++++--- .../request/processors/MsJSR223Processor.java | 8 +------- .../definition/request/sampler/MsDubboSampler.java | 11 +++-------- .../request/sampler/MsHTTPSamplerProxy.java | 12 +++--------- .../definition/request/sampler/MsJDBCSampler.java | 11 +++-------- .../definition/request/sampler/MsTCPSampler.java | 11 +++-------- .../commons/constants/MsTestElementConstants.java | 5 +++++ 7 files changed, 28 insertions(+), 43 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java 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 add5e31f44..01bcb6121e 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 @@ -30,6 +30,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.commons.constants.LoopConstants; +import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import lombok.Data; @@ -249,17 +250,17 @@ public abstract class MsTestElement { if (element.getParent() == null) { return element; } - if ("LoopController".equals(element.getType())) { + if (MsTestElementConstants.LoopController.name().equals(element.getType())) { return element; } return getRootParent(element.getParent()); } - protected String getParentName(MsTestElement element) { + protected String getParentName(MsTestElement element, ParameterConfig config) { if (element != null) { MsTestElement parent = this.getRootParent(element); if (parent != null) { - if ("LoopController".equals(parent.getType())) { + if (MsTestElementConstants.LoopController.name().equals(parent.getType())) { MsLoopController loopController = (MsLoopController) parent; if (StringUtils.equals(loopController.getLoopType(), LoopConstants.WHILE.name()) && loopController.getWhileController() != null) { return "While 循环-" + "${LoopCounterConfigXXX}"; @@ -274,6 +275,12 @@ public abstract class MsTestElement { return parent.getName(); } return element.getName(); + } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { + if (MsTestElementConstants.SCENARIO.name().equals(config.getStepType())) { + return config.getStep(); + } else { + return config.getStep() + "-" + "${LoopCounterConfigXXX}"; + } } return ""; } 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 82c37ab305..1d50b084ca 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 @@ -39,15 +39,9 @@ public class MsJSR223Processor extends MsTestElement { } else { processor.setName("JSR223Processor"); } - String name = this.getParentName(this.getParent()); + String name = this.getParentName(this.getParent(), config); if (StringUtils.isNotEmpty(name)) { processor.setName(this.getName() + "<->" + name); - } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { - if ("SCENARIO".equals(config.getStepType())) { - processor.setName(this.getName() + "<->" + config.getStep()); - } else { - processor.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}"); - } } processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName()); processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); 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 8c37f68bb1..7fdb15d3b9 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 @@ -12,6 +12,7 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConfigCenter; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndService; import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter; import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.commons.constants.MsTestElementConstants; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -62,7 +63,7 @@ public class MsDubboSampler extends MsTestElement { if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) { return; } - if (this.getReferenced() != null && "REF".equals(this.getReferenced())) { + if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { this.getRefElement(this); } @@ -77,15 +78,9 @@ public class MsDubboSampler extends MsTestElement { private DubboSample dubboSample(ParameterConfig config) { DubboSample sampler = new DubboSample(); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent()); + String name = this.getParentName(this.getParent(), config); if (StringUtils.isNotEmpty(name)) { sampler.setName(this.getName() + "<->" + name); - } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { - if ("SCENARIO".equals(config.getStepType())) { - sampler.setName(this.getName() + "<->" + config.getStep()); - } else { - sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}"); - } } sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui")); 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 8035e67fa3..b1a5ff5701 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 @@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager; import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.scenario.KeyValue; +import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ScriptEngineUtils; import lombok.Data; @@ -91,23 +92,16 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (!this.isEnable()) { return; } - if (this.getReferenced() != null && "REF".equals(this.getReferenced())) { + if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { this.getRefElement(this); } HTTPSamplerProxy sampler = new HTTPSamplerProxy(); sampler.setEnabled(true); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent()); + String name = this.getParentName(this.getParent(), config); if (StringUtils.isNotEmpty(name)) { sampler.setName(this.getName() + "<->" + name); - } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { - if ("SCENARIO".equals(config.getStepType())) { - sampler.setName(this.getName() + "<->" + config.getStep()); - } else { - sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}"); - } } - sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui")); sampler.setMethod(this.getMethod()); 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 26146e3565..3eb20a8b99 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 @@ -10,6 +10,7 @@ import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import lombok.Data; @@ -57,7 +58,7 @@ public class MsJDBCSampler extends MsTestElement { if (!this.isEnable()) { return; } - if (this.getReferenced() != null && "REF".equals(this.getReferenced())) { + if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { this.getRefElement(this); } if (StringUtils.isNotEmpty(dataSourceId)) { @@ -110,15 +111,9 @@ public class MsJDBCSampler extends MsTestElement { private JDBCSampler jdbcSampler(ParameterConfig config) { JDBCSampler sampler = new JDBCSampler(); sampler.setName(this.getName()); - String name = this.getParentName(this.getParent()); + String name = this.getParentName(this.getParent(), config); if (StringUtils.isNotEmpty(name)) { sampler.setName(this.getName() + "<->" + name); - } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { - if ("SCENARIO".equals(config.getStepType())) { - sampler.setName(this.getName() + "<->" + config.getStep()); - } else { - sampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}"); - } } sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); 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 aef95b9163..50c790534b 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 @@ -7,6 +7,7 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; +import io.metersphere.commons.constants.MsTestElementConstants; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -73,7 +74,7 @@ public class MsTCPSampler extends MsTestElement { if (!this.isEnable()) { return; } - if (this.getReferenced() != null && this.getReferenced().equals("REF")) { + if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) { this.getRefElement(this); } config.setConfig(getEnvironmentConfig(useEnvironment)); @@ -102,15 +103,9 @@ public class MsTCPSampler extends MsTestElement { private TCPSampler tcpSampler(ParameterConfig config) { TCPSampler tcpSampler = new TCPSampler(); tcpSampler.setName(this.getName()); - String name = this.getParentName(this.getParent()); + String name = this.getParentName(this.getParent(), config); if (StringUtils.isNotEmpty(name)) { tcpSampler.setName(this.getName() + "<->" + name); - } else if (config != null && StringUtils.isNotEmpty(config.getStep())) { - if ("SCENARIO".equals(config.getStepType())) { - tcpSampler.setName(this.getName() + "<->" + config.getStep()); - } else { - tcpSampler.setName(this.getName() + "<->" + config.getStep() + "-" + "${LoopCounterConfigXXX}"); - } } tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName()); diff --git a/backend/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java b/backend/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java new file mode 100644 index 0000000000..e3e2dbf232 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/MsTestElementConstants.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum MsTestElementConstants { + LoopController,SCENARIO,REF +}