refactor(接口自动化): 部分代码优化
This commit is contained in:
parent
8c8f2850c2
commit
98f3391c75
|
@ -30,6 +30,7 @@ import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
import io.metersphere.commons.constants.LoopConstants;
|
import io.metersphere.commons.constants.LoopConstants;
|
||||||
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -249,17 +250,17 @@ public abstract class MsTestElement {
|
||||||
if (element.getParent() == null) {
|
if (element.getParent() == null) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
if ("LoopController".equals(element.getType())) {
|
if (MsTestElementConstants.LoopController.name().equals(element.getType())) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
return getRootParent(element.getParent());
|
return getRootParent(element.getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getParentName(MsTestElement element) {
|
protected String getParentName(MsTestElement element, ParameterConfig config) {
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
MsTestElement parent = this.getRootParent(element);
|
MsTestElement parent = this.getRootParent(element);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
if ("LoopController".equals(parent.getType())) {
|
if (MsTestElementConstants.LoopController.name().equals(parent.getType())) {
|
||||||
MsLoopController loopController = (MsLoopController) parent;
|
MsLoopController loopController = (MsLoopController) parent;
|
||||||
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.WHILE.name()) && loopController.getWhileController() != null) {
|
if (StringUtils.equals(loopController.getLoopType(), LoopConstants.WHILE.name()) && loopController.getWhileController() != null) {
|
||||||
return "While 循环-" + "${LoopCounterConfigXXX}";
|
return "While 循环-" + "${LoopCounterConfigXXX}";
|
||||||
|
@ -274,6 +275,12 @@ public abstract class MsTestElement {
|
||||||
return parent.getName();
|
return parent.getName();
|
||||||
}
|
}
|
||||||
return element.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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,9 @@ public class MsJSR223Processor extends MsTestElement {
|
||||||
} else {
|
} else {
|
||||||
processor.setName("JSR223Processor");
|
processor.setName("JSR223Processor");
|
||||||
}
|
}
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent(), config);
|
||||||
if (StringUtils.isNotEmpty(name)) {
|
if (StringUtils.isNotEmpty(name)) {
|
||||||
processor.setName(this.getName() + "<->" + 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.TEST_CLASS, JSR223Sampler.class.getName());
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
|
|
|
@ -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.MsConsumerAndService;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
|
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -62,7 +63,7 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) {
|
if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
|
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||||
this.getRefElement(this);
|
this.getRefElement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,15 +78,9 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
private DubboSample dubboSample(ParameterConfig config) {
|
private DubboSample dubboSample(ParameterConfig config) {
|
||||||
DubboSample sampler = new DubboSample();
|
DubboSample sampler = new DubboSample();
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent(), config);
|
||||||
if (StringUtils.isNotEmpty(name)) {
|
if (StringUtils.isNotEmpty(name)) {
|
||||||
sampler.setName(this.getName() + "<->" + 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.TEST_CLASS, DubboSample.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
||||||
|
|
|
@ -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.definition.request.dns.MsDNSCacheManager;
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.commons.utils.ScriptEngineUtils;
|
import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -91,23 +92,16 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
if (!this.isEnable()) {
|
if (!this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
|
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||||
this.getRefElement(this);
|
this.getRefElement(this);
|
||||||
}
|
}
|
||||||
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
|
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
|
||||||
sampler.setEnabled(true);
|
sampler.setEnabled(true);
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent(), config);
|
||||||
if (StringUtils.isNotEmpty(name)) {
|
if (StringUtils.isNotEmpty(name)) {
|
||||||
sampler.setName(this.getName() + "<->" + 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.TEST_CLASS, HTTPSamplerProxy.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
||||||
sampler.setMethod(this.getMethod());
|
sampler.setMethod(this.getMethod());
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -57,7 +58,7 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
if (!this.isEnable()) {
|
if (!this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
|
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||||
this.getRefElement(this);
|
this.getRefElement(this);
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(dataSourceId)) {
|
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||||
|
@ -110,15 +111,9 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
private JDBCSampler jdbcSampler(ParameterConfig config) {
|
private JDBCSampler jdbcSampler(ParameterConfig config) {
|
||||||
JDBCSampler sampler = new JDBCSampler();
|
JDBCSampler sampler = new JDBCSampler();
|
||||||
sampler.setName(this.getName());
|
sampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent(), config);
|
||||||
if (StringUtils.isNotEmpty(name)) {
|
if (StringUtils.isNotEmpty(name)) {
|
||||||
sampler.setName(this.getName() + "<->" + 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.TEST_CLASS, JDBCSampler.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
|
|
|
@ -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.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -73,7 +74,7 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
if (!this.isEnable()) {
|
if (!this.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.getReferenced() != null && this.getReferenced().equals("REF")) {
|
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||||
this.getRefElement(this);
|
this.getRefElement(this);
|
||||||
}
|
}
|
||||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||||
|
@ -102,15 +103,9 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
private TCPSampler tcpSampler(ParameterConfig config) {
|
private TCPSampler tcpSampler(ParameterConfig config) {
|
||||||
TCPSampler tcpSampler = new TCPSampler();
|
TCPSampler tcpSampler = new TCPSampler();
|
||||||
tcpSampler.setName(this.getName());
|
tcpSampler.setName(this.getName());
|
||||||
String name = this.getParentName(this.getParent());
|
String name = this.getParentName(this.getParent(), config);
|
||||||
if (StringUtils.isNotEmpty(name)) {
|
if (StringUtils.isNotEmpty(name)) {
|
||||||
tcpSampler.setName(this.getName() + "<->" + 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());
|
tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName());
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package io.metersphere.commons.constants;
|
||||||
|
|
||||||
|
public enum MsTestElementConstants {
|
||||||
|
LoopController,SCENARIO,REF
|
||||||
|
}
|
Loading…
Reference in New Issue