refactor(接口定义): 代码统一规范

This commit is contained in:
fit2-zhao 2021-01-18 14:53:49 +08:00
parent 7766db552c
commit aeaf6f8018
23 changed files with 45 additions and 23 deletions

View File

@ -54,6 +54,7 @@ public class MsScenario extends MsTestElement {
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -18,6 +18,7 @@ import java.util.List;
public class MsTestPlan extends MsTestElement { public class MsTestPlan extends MsTestElement {
private String type = "TestPlan"; private String type = "TestPlan";
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
final HashTree testPlanTree = tree.add(getPlan()); final HashTree testPlanTree = tree.add(getPlan());
if (CollectionUtils.isNotEmpty(hashTree)) { if (CollectionUtils.isNotEmpty(hashTree)) {

View File

@ -20,6 +20,7 @@ public class MsThreadGroup extends MsTestElement {
private String type = "ThreadGroup"; private String type = "ThreadGroup";
private boolean enableCookieShare; private boolean enableCookieShare;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
final HashTree groupTree = tree.add(getThreadGroup()); final HashTree groupTree = tree.add(getThreadGroup());
if ((config != null && config.isEnableCookieShare()) || enableCookieShare) { if ((config != null && config.isEnableCookieShare()) || enableCookieShare) {

View File

@ -24,6 +24,7 @@ public class MsAssertions extends MsTestElement {
private MsAssertionDuration duration; private MsAssertionDuration duration;
private String type = "Assertions"; private String type = "Assertions";
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (this.isEnable()) { if (this.isEnable()) {
addAssertions(tree); addAssertions(tree);
@ -79,6 +80,8 @@ public class MsAssertions extends MsTestElement {
case "Response Data": case "Response Data":
assertion.setTestFieldResponseData(); assertion.setTestFieldResponseData();
break; break;
default:
break;
} }
return assertion; return assertion;
} }

View File

@ -51,6 +51,7 @@ public class MsAuthManager extends MsTestElement {
@JSONField(ordinal = 28) @JSONField(ordinal = 28)
private String environment; private String environment;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -25,6 +25,7 @@ public class MsHeaderManager extends MsTestElement {
@JSONField(ordinal = 20) @JSONField(ordinal = 20)
private List<KeyValue> headers; private List<KeyValue> headers;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -24,6 +24,7 @@ public class MsIfController extends MsTestElement {
private String operator; private String operator;
private String value; private String value;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
@ -39,7 +40,7 @@ public class MsIfController extends MsTestElement {
private IfController ifController() { private IfController ifController() {
IfController ifController = new IfController(); IfController ifController = new IfController();
ifController.setEnabled(true); ifController.setEnabled(true);
ifController.setName(this.getLabel()); ifController.setName(this.getLabelName());
ifController.setCondition(this.getCondition()); ifController.setCondition(this.getCondition());
ifController.setProperty(TestElement.TEST_CLASS, IfController.class.getName()); ifController.setProperty(TestElement.TEST_CLASS, IfController.class.getName());
ifController.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("IfControllerPanel")); ifController.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("IfControllerPanel"));
@ -55,7 +56,7 @@ public class MsIfController extends MsTestElement {
return StringUtils.isNotBlank(variable) && StringUtils.isNotBlank(operator) && StringUtils.isNotBlank(value); return StringUtils.isNotBlank(variable) && StringUtils.isNotBlank(operator) && StringUtils.isNotBlank(value);
} }
public String getLabel() { public String getLabelName() {
if (isValid()) { if (isValid()) {
String label = variable + " " + operator; String label = variable + " " + operator;
if (StringUtils.isNotBlank(value)) { if (StringUtils.isNotBlank(value)) {

View File

@ -38,14 +38,15 @@ public class MsLoopController extends MsTestElement {
@JSONField(ordinal = 23) @JSONField(ordinal = 23)
private MsWhileController whileController; private MsWhileController whileController;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
} }
GenericController controller = controller(); GenericController controller = controller();
if (controller == null) if (controller == null) {
return; return;
}
final HashTree groupTree = tree.add(controller); final HashTree groupTree = tree.add(controller);
if (CollectionUtils.isNotEmpty(hashTree)) { if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> { hashTree.forEach(el -> {

View File

@ -24,6 +24,7 @@ import java.util.List;
@JSONType(typeName = "DNSCacheManager") @JSONType(typeName = "DNSCacheManager")
public class MsDNSCacheManager extends MsTestElement { public class MsDNSCacheManager extends MsTestElement {
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -27,6 +27,7 @@ public class MsExtract extends MsTestElement {
private List<MsExtractXPath> xpath; private List<MsExtractXPath> xpath;
private String type = "Extract"; private String type = "Extract";
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -27,6 +27,7 @@ public class MsJSR223Processor extends MsTestElement {
@JSONField(ordinal = 21) @JSONField(ordinal = 21)
private String scriptLanguage; private String scriptLanguage;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -27,7 +27,7 @@ public class MsJSR223PostProcessor extends MsTestElement {
@JSONField(ordinal = 21) @JSONField(ordinal = 21)
private String scriptLanguage; private String scriptLanguage;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -27,6 +27,7 @@ public class MsJSR223PreProcessor extends MsTestElement {
@JSONField(ordinal = 21) @JSONField(ordinal = 21)
private String scriptLanguage; private String scriptLanguage;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -54,14 +54,15 @@ public class MsDubboSampler extends MsTestElement {
@JSONField(ordinal = 60) @JSONField(ordinal = 60)
private Object requestResult; private Object requestResult;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
} }
if (this.getReferenced() != null && this.getReferenced().equals("Deleted")) { if (this.getReferenced() != null && "Deleted".equals(this.getReferenced())) {
return; return;
} }
if (this.getReferenced() != null && this.getReferenced().equals("REF")) { if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
this.getRefElement(this); this.getRefElement(this);
} }

View File

@ -31,7 +31,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@JSONType(typeName = "HTTPSamplerProxy") @JSONType(typeName = "HTTPSamplerProxy")
@ -86,11 +85,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
@JSONField(ordinal = 35) @JSONField(ordinal = 35)
private Object requestResult; private Object requestResult;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
} }
if (this.getReferenced() != null && this.getReferenced().equals("REF")) { if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
this.getRefElement(this); this.getRefElement(this);
} }
HTTPSamplerProxy sampler = new HTTPSamplerProxy(); HTTPSamplerProxy sampler = new HTTPSamplerProxy();
@ -109,9 +109,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setFollowRedirects(this.isFollowRedirects()); sampler.setFollowRedirects(this.isFollowRedirects());
sampler.setUseKeepAlive(true); sampler.setUseKeepAlive(true);
sampler.setDoMultipart(this.isDoMultipartPost()); sampler.setDoMultipart(this.isDoMultipartPost());
if(config != null && config.getConfig() != null){ if (config != null && config.getConfig() != null) {
config.setConfig(config.getConfig()); config.setConfig(config.getConfig());
}else{ } else {
config.setConfig(getEnvironmentConfig(useEnvironment)); config.setConfig(getEnvironmentConfig(useEnvironment));
} }
@ -183,7 +183,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (!StringUtils.equals(this.getMethod(), "GET")) { if (!StringUtils.equals(this.getMethod(), "GET")) {
if (this.body != null) { if (this.body != null) {
List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId()); List<KeyValue> bodyParams = this.body.getBodyParams(sampler, this.getId());
if (StringUtils.isNotEmpty(this.body.getType()) && this.body.getType().equals("Form Data")) { if (StringUtils.isNotEmpty(this.body.getType()) && "Form Data".equals(this.body.getType())) {
sampler.setDoMultipart(true); sampler.setDoMultipart(true);
} }
if (CollectionUtils.isNotEmpty(bodyParams)) { if (CollectionUtils.isNotEmpty(bodyParams)) {

View File

@ -51,11 +51,12 @@ public class MsJDBCSampler extends MsTestElement {
@JSONField(ordinal = 28) @JSONField(ordinal = 28)
private String dataSourceId; private String dataSourceId;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;
} }
if (this.getReferenced() != null && this.getReferenced().equals("REF")) { if (this.getReferenced() != null && "REF".equals(this.getReferenced())) {
this.getRefElement(this); this.getRefElement(this);
} }
if (StringUtils.isNotEmpty(dataSourceId)) { if (StringUtils.isNotEmpty(dataSourceId)) {

View File

@ -59,6 +59,7 @@ public class MsTCPSampler extends MsTestElement {
@JSONField(ordinal = 36) @JSONField(ordinal = 36)
private String useEnvironment; private String useEnvironment;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -24,6 +24,7 @@ public class MsConstantTimer extends MsTestElement {
@JSONField(ordinal = 21) @JSONField(ordinal = 21)
private String delay; private String delay;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) { if (!this.isEnable()) {
return; return;

View File

@ -40,13 +40,17 @@ public class Body {
if (StringUtils.equals(type, FORM_DATA) || StringUtils.equals(type, WWW_FROM) if (StringUtils.equals(type, FORM_DATA) || StringUtils.equals(type, WWW_FROM)
|| StringUtils.equals(type, BINARY)) { || StringUtils.equals(type, BINARY)) {
return true; return true;
} else return false; } else {
return false;
}
} }
public boolean isOldKV() { public boolean isOldKV() {
if (StringUtils.equals(type, KV)) { if (StringUtils.equals(type, KV)) {
return true; return true;
} else return false; } else {
return false;
}
} }
public List<KeyValue> getBodyParams(HTTPSamplerProxy sampler, String requestId) { public List<KeyValue> getBodyParams(HTTPSamplerProxy sampler, String requestId) {
@ -63,7 +67,7 @@ public class Body {
if (!this.isJson()) { if (!this.isJson()) {
sampler.setPostBodyRaw(true); sampler.setPostBodyRaw(true);
} else { } else {
if (StringUtils.isNotEmpty(this.format) && this.format.equals("JSON-SCHEMA") && this.getJsonSchema() != null) { if (StringUtils.isNotEmpty(this.format) && "JSON-SCHEMA".equals(this.format) && this.getJsonSchema() != null) {
this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema())); this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
} }
} }

View File

@ -40,16 +40,16 @@ public class TestResult {
this.passAssertions += count; this.passAssertions += count;
} }
private static final String separator = "<->"; private static final String SEPARATOR = "<->";
public void addScenario(ScenarioResult result) { public void addScenario(ScenarioResult result) {
Map<String, List<RequestResult>> requestResultMap = new LinkedHashMap<>(); Map<String, List<RequestResult>> requestResultMap = new LinkedHashMap<>();
if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) { if (result != null && CollectionUtils.isNotEmpty(result.getRequestResults())) {
result.getRequestResults().forEach(item -> { result.getRequestResults().forEach(item -> {
if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(separator) != -1) { if (StringUtils.isNotEmpty(item.getName()) && item.getName().indexOf(SEPARATOR) != -1) {
String array[] = item.getName().split(separator); String array[] = item.getName().split(SEPARATOR);
String scenarioName = array[array.length - 1]; String scenarioName = array[array.length - 1];
item.setName(item.getName().replace(separator + scenarioName, "")); item.setName(item.getName().replace(SEPARATOR + scenarioName, ""));
if (requestResultMap.containsKey(scenarioName)) { if (requestResultMap.containsKey(scenarioName)) {
requestResultMap.get(scenarioName).add(item); requestResultMap.get(scenarioName).add(item);
} else { } else {

View File

@ -157,7 +157,7 @@ public class JmeterDocumentParser {
u += k + "=" + ScriptEngineUtils.calculate(v); u += k + "=" + ScriptEngineUtils.calculate(v);
return u; return u;
}); });
ele.setTextContent(url + ((params != null && !params.equals("?")) ? params : "")); ele.setTextContent(url + ((params != null && !"?".equals(params)) ? params : ""));
break; break;
case "Argument.value": case "Argument.value":
String textContent = ele.getTextContent(); String textContent = ele.getTextContent();

View File

@ -295,7 +295,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
if (level > 8) { if (level > 8) {
MSException.throwException(Translator.get("node_deep_limit")); MSException.throwException(Translator.get("node_deep_limit"));
} }
if (rootNode.getId().equals("root")) { if ("root".equals(rootNode.getId())) {
rootPath = ""; rootPath = "";
} }
ApiModule apiDefinitionNode = new ApiModule(); ApiModule apiDefinitionNode = new ApiModule();

View File

@ -253,7 +253,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
if (level > 8) { if (level > 8) {
MSException.throwException(Translator.get("node_deep_limit")); MSException.throwException(Translator.get("node_deep_limit"));
} }
if (rootNode.getId().equals("root")) { if ("root".equals(rootNode.getId())) {
rootPath = ""; rootPath = "";
} }
ApiScenarioModule apiScenarioModule = new ApiScenarioModule(); ApiScenarioModule apiScenarioModule = new ApiScenarioModule();