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";
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
if (!this.isEnable()) {
return;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,13 +40,17 @@ public class Body {
if (StringUtils.equals(type, FORM_DATA) || StringUtils.equals(type, WWW_FROM)
|| StringUtils.equals(type, BINARY)) {
return true;
} else return false;
} else {
return false;
}
}
public boolean isOldKV() {
if (StringUtils.equals(type, KV)) {
return true;
} else return false;
} else {
return false;
}
}
public List<KeyValue> getBodyParams(HTTPSamplerProxy sampler, String requestId) {
@ -63,7 +67,7 @@ public class Body {
if (!this.isJson()) {
sampler.setPostBodyRaw(true);
} 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()));
}
}

View File

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

View File

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

View File

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

View File

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