From 671f60986647efcf37fe2a77e04f5a9dc8e17254 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Mon, 17 Oct 2022 17:29:36 +0800 Subject: [PATCH] refactor: "" -> StringUtils.EMPTY --- .../api/dto/ErrorReportLibraryParseDTO.java | 2 +- .../io/metersphere/api/dto/JmxInfoDTO.java | 4 ++-- .../io/metersphere/api/jmeter/TestResult.java | 2 +- .../api/parse/ApiImportAbstractParser.java | 12 ++++++------ .../api/parse/HarScenarioAbstractParser.java | 6 +++--- .../api/parse/JmeterDocumentParser.java | 4 ++-- .../api/parse/PostmanAbstractParserParser.java | 6 +++--- .../java/io/metersphere/api/tcp/TCPPool.java | 3 ++- .../utils/ApiTestDefinitionDiffUtilImpl.java | 2 +- .../commons/utils/FixedCapacityUtil.java | 4 +++- .../commons/utils/HashTreeUtil.java | 4 ++-- .../utils/JSONSchemaToDocumentUtil.java | 10 +++++----- .../commons/utils/JSONToDocumentUtil.java | 10 +++++----- .../commons/utils/JmeterDocumentParser.java | 18 +++++++++--------- .../commons/utils/ResultConversionUtil.java | 4 ++-- .../commons/utils/WebSocketUtil.java | 5 +++-- .../io/metersphere/commons/utils/XMLUtil.java | 2 +- .../service/ext/ExtApiScheduleService.java | 2 +- .../ext/ExtProjectApplicationService.java | 2 +- .../service/PerformanceTestService.java | 2 +- .../metersphere/service/TestCaseService.java | 6 +++--- .../io/metersphere/xmind/XmindCaseParser.java | 16 ++++++++-------- 22 files changed, 65 insertions(+), 61 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java index e880e561dd..b3ea038fd0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java @@ -25,7 +25,7 @@ public class ErrorReportLibraryParseDTO { String errorCodeStr = StringUtils.join(this.errorCodeList,";"); return errorCodeStr; }else { - return ""; + return StringUtils.EMPTY; } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/JmxInfoDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/JmxInfoDTO.java index 07b58aaefc..e68f6e86ab 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/JmxInfoDTO.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/JmxInfoDTO.java @@ -26,13 +26,13 @@ public class JmxInfoDTO { private List fileMetadataList; public JmxInfoDTO(String name, String xml, Map attachFiles) { - this.name = StringUtils.replace(name, "/", ""); + this.name = StringUtils.replace(name, "/", StringUtils.EMPTY); this.xml = xml; this.attachFiles = attachFiles; } public void setName(String name) { - this.name = StringUtils.replace(name, "/", ""); + this.name = StringUtils.replace(name, "/", StringUtils.EMPTY); } public void addFileMetadataLists(List list) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java index df4897c3d9..878074434f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java @@ -131,7 +131,7 @@ public class TestResult { result.setRequestResults(formatedResult); result.getRequestResults().forEach(item -> { - String itemAndScenarioName = ""; + String itemAndScenarioName = StringUtils.EMPTY; if (StringUtils.isNotEmpty(item.getScenario())) { //第1个:当前场景, 第all_id_names个:最后一层场景 List all_id_names = JSON.parseObject(item.getScenario(), List.class); diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java index e3ba82d0ee..a3d1dfa170 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/ApiImportAbstractParser.java @@ -57,7 +57,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { } protected String getBodyType(String contentType) { - String bodyType = ""; + String bodyType = StringUtils.EMPTY; if (StringUtils.isBlank(contentType)) { return bodyType; } @@ -85,7 +85,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { } protected void addBodyHeader(MsHTTPSamplerProxy request) { - String contentType = ""; + String contentType = StringUtils.EMPTY; if (request.getBody() != null && StringUtils.isNotBlank(request.getBody().getType())) { switch (request.getBody().getType()) { case Body.WWW_FROM: @@ -176,7 +176,7 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { } protected void addCookie(List headers, String key, String value) { - addCookie(headers, key, value, "", true); + addCookie(headers, key, value, StringUtils.EMPTY, true); } protected void addCookie(List headers, String key, String value, String description, boolean required) { @@ -184,17 +184,17 @@ public abstract class ApiImportAbstractParser implements ApiImportParser { for (KeyValue header : headers) { if (StringUtils.equalsIgnoreCase("Cookie", header.getName())) { hasCookie = true; - String cookies = Optional.ofNullable(header.getValue()).orElse(""); + String cookies = Optional.ofNullable(header.getValue()).orElse(StringUtils.EMPTY); header.setValue(cookies + key + "=" + value + ";"); } } if (!hasCookie) { - addHeader(headers, "Cookie", key + "=" + value + ";", description, "", required); + addHeader(headers, "Cookie", key + "=" + value + ";", description, StringUtils.EMPTY, required); } } protected void addHeader(List headers, String key, String value) { - addHeader(headers, key, value, "", "", true); + addHeader(headers, key, value, "", StringUtils.EMPTY, true); } protected void addHeader(List headers, String key, String value, String description, String contentType, boolean required) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java index 795ae505ab..5d191b4631 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java @@ -147,7 +147,7 @@ public abstract class HarScenarioAbstractParser extends ApiImportAbstractPars } private void parseHeaderParameters(HarHeader harHeader, List headers) { - addHeader(headers, harHeader.name, harHeader.value, harHeader.comment, "", false); + addHeader(headers, harHeader.name, harHeader.value, harHeader.comment, StringUtils.EMPTY, false); } private void addPreScript(MsHTTPSamplerProxy request, List event) { @@ -227,7 +227,7 @@ public abstract class HarScenarioAbstractParser extends ApiImportAbstractPars if (options != null) { JsonNode raw = options.get(PostmanRequestBodyMode.RAW.value()); if (raw != null) { - String bodyType = ""; + String bodyType = StringUtils.EMPTY; switch (raw.get("language").textValue()) { case "json": bodyType = Body.JSON_STR; @@ -244,7 +244,7 @@ public abstract class HarScenarioAbstractParser extends ApiImportAbstractPars } private String getDefaultStringValue(String val) { - return StringUtils.isBlank(val) ? "" : val; + return StringUtils.isBlank(val) ? StringUtils.EMPTY : val; } private String getBoundaryFromContentType(String contentType) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/JmeterDocumentParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/JmeterDocumentParser.java index 7e0efbc356..93872f1ba8 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/JmeterDocumentParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/JmeterDocumentParser.java @@ -159,7 +159,7 @@ public class JmeterDocumentParser { u += k + "=" + ScriptEngineUtils.buildFunctionCallString(v); return u; }); - ele.setTextContent(url + ((params != null && !"?".equals(params)) ? params : "")); + ele.setTextContent(url + ((params != null && !"?".equals(params)) ? params : StringUtils.EMPTY)); break; case "Argument.value": String textContent = ele.getTextContent(); @@ -214,7 +214,7 @@ public class JmeterDocumentParser { if (p.contains("=")) { String[] param = p.split("="); if (param.length == 1) { - strUrlParas.put(param[0], ""); + strUrlParas.put(param[0], StringUtils.EMPTY); } else { String key = param[0]; diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java index a8f08df623..0db1f87ee0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/PostmanAbstractParserParser.java @@ -32,8 +32,8 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa } requestDesc.getAuth(); // todo 认证方式等待优化 PostmanUrl url = requestDesc.getUrl(); - MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), url == null ? "" : url.getRaw(), requestDesc.getMethod(), - requestDesc.getBody().get("jsonSchema") == null ? "" : requestDesc.getBody().get("jsonSchema").textValue()); + MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), url == null ? StringUtils.EMPTY : url.getRaw(), requestDesc.getMethod(), + requestDesc.getBody().get("jsonSchema") == null ? StringUtils.EMPTY : requestDesc.getBody().get("jsonSchema").textValue()); request.setRest(parseKeyValue(requestDesc.getUrl().getVariable())); if (StringUtils.isNotBlank(request.getPath())) { String path = request.getPath().split("\\?")[0]; @@ -168,7 +168,7 @@ public abstract class PostmanAbstractParserParser extends ApiImportAbstractPa if (options != null) { JsonNode raw = options.get(PostmanRequestBodyMode.RAW.value()); if (raw != null) { - String bodyType = ""; + String bodyType = StringUtils.EMPTY; switch (raw.get("language").textValue()) { case "json": bodyType = Body.JSON_STR; diff --git a/api-test/backend/src/main/java/io/metersphere/api/tcp/TCPPool.java b/api-test/backend/src/main/java/io/metersphere/api/tcp/TCPPool.java index feeaa4f4ef..ce80a1ca9e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/tcp/TCPPool.java +++ b/api-test/backend/src/main/java/io/metersphere/api/tcp/TCPPool.java @@ -3,6 +3,7 @@ package io.metersphere.api.tcp; import io.metersphere.api.tcp.server.TCPServer; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; +import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; @@ -18,7 +19,7 @@ public class TCPPool { private TCPPool(){} public static String createTcp(int port){ - String returnString = ""; + String returnString = StringUtils.EMPTY; if(port > 0){ TCPServer tcpServer = null; if(serverSockedMap.containsKey(port)){ diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java index f7cf415a33..d7ccf1b344 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ApiTestDefinitionDiffUtilImpl.java @@ -207,7 +207,7 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil { authColumns.forEach(item -> { Object value = item.getOriginalValue(); item.setNewValue(value); - item.setOriginalValue(""); + item.setOriginalValue(StringUtils.EMPTY); }); diffMap.put("body_auth", JSON.toJSONString(authColumns)); } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/FixedCapacityUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/FixedCapacityUtil.java index 53f2a4bde1..470cbc2e27 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/FixedCapacityUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/FixedCapacityUtil.java @@ -1,5 +1,7 @@ package io.metersphere.commons.utils; +import org.apache.commons.lang3.StringUtils; + import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -50,7 +52,7 @@ public class FixedCapacityUtil { return logMessage; } catch (Exception e) { - return ""; + return StringUtils.EMPTY; } finally { if (isClear && FixedCapacityUtil.jmeterLogTask.containsKey(reportId)) { FixedCapacityUtil.jmeterLogTask.remove(reportId); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java index bd6c3e7528..d65656335b 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/HashTreeUtil.java @@ -69,7 +69,7 @@ public class HashTreeUtil { for (String param : params) { String value = envHeadMap.get(param); if (value == null) { - value = ""; + value = StringUtils.EMPTY; } if (returnMap.containsKey(envId)) { returnMap.get(envId).put(param, value); @@ -94,7 +94,7 @@ public class HashTreeUtil { for (Object hashTreeKey : hashTree.keySet()) { HashTree itemTree = hashTree.get(hashTreeKey); - String scriptValue = ""; + String scriptValue = StringUtils.EMPTY; try { if (hashTreeKey instanceof JSR223PostProcessor) { JSR223PostProcessor postProcessor = (JSR223PostProcessor) hashTreeKey; diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONSchemaToDocumentUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONSchemaToDocumentUtil.java index 71a1a99fd7..58c0aaf023 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONSchemaToDocumentUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONSchemaToDocumentUtil.java @@ -78,7 +78,7 @@ public class JSONSchemaToDocumentUtil { Object value = null; boolean required = requiredList.contains(propertyName); if (object.has(PropertyConstant.DEFAULT)) { - value = object.get(PropertyConstant.DEFAULT) != null ? object.get(PropertyConstant.DEFAULT).getAsString() : ""; + value = object.get(PropertyConstant.DEFAULT) != null ? object.get(PropertyConstant.DEFAULT).getAsString() : StringUtils.EMPTY; concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null)); } else if (object.has(PropertyConstant.ENUM)) { try { @@ -102,7 +102,7 @@ public class JSONSchemaToDocumentUtil { } else if (propertyObjType.equals(PropertyConstant.STRING)) { // 先设置空值 if (object.has(PropertyConstant.DEFAULT)) { - value = object.get(PropertyConstant.DEFAULT) != null ? object.get(PropertyConstant.DEFAULT).getAsString() : ""; + value = object.get(PropertyConstant.DEFAULT) != null ? object.get(PropertyConstant.DEFAULT).getAsString() : StringUtils.EMPTY; } if (object.has(PropertyConstant.MOCK) && object.get(PropertyConstant.MOCK).getAsJsonObject() != null && StringUtils.isNotEmpty(object.get(PropertyConstant.MOCK).getAsJsonObject().get(PropertyConstant.MOCK).getAsString())) { @@ -149,12 +149,12 @@ public class JSONSchemaToDocumentUtil { concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null)); } else if (propertyObjType.equals(PropertyConstant.ARRAY)) { List elements = new LinkedList<>(); - concept.add(new DocumentElement(propertyName, propertyObjType, "", requiredList.contains(propertyName), true, elements)); + concept.add(new DocumentElement(propertyName, propertyObjType, StringUtils.EMPTY, requiredList.contains(propertyName), true, elements)); JsonArray jsonArray = object.get(PropertyConstant.ITEMS).getAsJsonArray(); analyzeArray(propertyName, jsonArray, elements, requiredList); } else if (propertyObjType.equals(PropertyConstant.OBJECT)) { List list = new LinkedList<>(); - concept.add(new DocumentElement(propertyName, propertyObjType, "", list)); + concept.add(new DocumentElement(propertyName, propertyObjType, StringUtils.EMPTY, list)); analyzeObject(object, list); } } @@ -166,7 +166,7 @@ public class JSONSchemaToDocumentUtil { if (obj.isJsonArray()) { JsonArray itemsObject = obj.getAsJsonArray(); List elements = new LinkedList<>(); - array.add(new DocumentElement(propertyName, "", "", requiredList.contains("" + i + ""), elements)); + array.add(new DocumentElement(propertyName, StringUtils.EMPTY, StringUtils.EMPTY, requiredList.contains("" + i + ""), elements)); analyzeArray("", itemsObject, elements, requiredList); } else if (obj.isJsonObject()) { List requiredItems = new ArrayList<>(); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java index 0ccbce6004..f4479a0ccd 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java @@ -20,11 +20,11 @@ public class JSONToDocumentUtil { Object value = array.get(i); if (value instanceof JSONObject) { List childrenElements = new LinkedList<>(); - children.add(new DocumentElement("", PropertyConstant.OBJECT, "", childrenElements)); + children.add(new DocumentElement(StringUtils.EMPTY, PropertyConstant.OBJECT, StringUtils.EMPTY, childrenElements)); jsonDataFormatting((JSONObject) value, childrenElements); } else if (value instanceof JSONArray) { List childrenElements = new LinkedList<>(); - DocumentElement documentElement = new DocumentElement("", PropertyConstant.ARRAY, "", childrenElements); + DocumentElement documentElement = new DocumentElement(StringUtils.EMPTY, PropertyConstant.ARRAY, StringUtils.EMPTY, childrenElements); documentElement.setArrayVerification(true); children.add(documentElement); jsonDataFormatting((JSONArray) value, childrenElements); @@ -33,7 +33,7 @@ public class JSONToDocumentUtil { if (value != null) { type = DocumentUtils.getType(value); } - children.add(new DocumentElement("", type, value, null)); + children.add(new DocumentElement(StringUtils.EMPTY, type, value, null)); } } } @@ -43,11 +43,11 @@ public class JSONToDocumentUtil { Object value = object.get(key); if (value instanceof JSONObject) { List childrenElements = new LinkedList<>(); - children.add(new DocumentElement(key, PropertyConstant.OBJECT, "", childrenElements)); + children.add(new DocumentElement(key, PropertyConstant.OBJECT, StringUtils.EMPTY, childrenElements)); jsonDataFormatting((JSONObject) value, childrenElements); } else if (value instanceof JSONArray) { List childrenElements = new LinkedList<>(); - DocumentElement documentElement = new DocumentElement(key, PropertyConstant.ARRAY, "", childrenElements); + DocumentElement documentElement = new DocumentElement(key, PropertyConstant.ARRAY, StringUtils.EMPTY, childrenElements); documentElement.setArrayVerification(true); children.add(documentElement); jsonDataFormatting((JSONArray) value, childrenElements); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java index d84e6c4d8f..59e0487ff0 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java @@ -339,7 +339,7 @@ public class JmeterDocumentParser implements EngineSourceParser { collectionProp.addAttribute("name", "Asserion.test_strings"); // - appendStringProp(item, "Assertion.custom_message", ""); + appendStringProp(item, "Assertion.custom_message", StringUtils.EMPTY); appendStringProp(item, "Assertion.test_field", "Assertion.response_code"); appendBoolProp(item, "Assertion.assume_success", true); appendIntProp(item, "Assertion.test_type", 40); @@ -368,7 +368,7 @@ public class JmeterDocumentParser implements EngineSourceParser { Element collectionProp = responseAssertion.addElement(COLLECTION_PROP); collectionProp.addAttribute("name", "Asserion.test_strings"); // - appendStringProp(responseAssertion, "Assertion.custom_message", ""); + appendStringProp(responseAssertion, "Assertion.custom_message", StringUtils.EMPTY); appendStringProp(responseAssertion, "Assertion.test_field", "Assertion.response_code"); appendBoolProp(responseAssertion, "Assertion.assume_success", true); appendIntProp(responseAssertion, "Assertion.test_type", 40); @@ -462,14 +462,14 @@ public class JmeterDocumentParser implements EngineSourceParser { collectionProp.addAttribute("name", "Arguments.arguments"); - appendStringProp(element, "HTTPSampler.domain", ""); - appendStringProp(element, "HTTPSampler.port", ""); - appendStringProp(element, "HTTPSampler.protocol", ""); - appendStringProp(element, "HTTPSampler.contentEncoding", ""); - appendStringProp(element, "HTTPSampler.path", ""); + appendStringProp(element, "HTTPSampler.domain", StringUtils.EMPTY); + appendStringProp(element, "HTTPSampler.port", StringUtils.EMPTY); + appendStringProp(element, "HTTPSampler.protocol", StringUtils.EMPTY); + appendStringProp(element, "HTTPSampler.contentEncoding", StringUtils.EMPTY); + appendStringProp(element, "HTTPSampler.path", StringUtils.EMPTY); appendStringProp(element, "HTTPSampler.concurrentPool", "6"); appendStringProp(element, "HTTPSampler.connect_timeout", "60000"); - appendStringProp(element, "HTTPSampler.response_timeout", ""); + appendStringProp(element, "HTTPSampler.response_timeout", StringUtils.EMPTY); // 空的 hashTree hashTree.addElement(HASH_TREE_ELEMENT); @@ -878,7 +878,7 @@ public class JmeterDocumentParser implements EngineSourceParser { appendStringProp(threadGroup, "RampUp", rampUp); appendStringProp(threadGroup, "Steps", step); appendStringProp(threadGroup, "Hold", hold); - appendStringProp(threadGroup, "LogFilename", ""); + appendStringProp(threadGroup, "LogFilename", StringUtils.EMPTY); // bzm - Concurrency Thread Group "Thread Iterations Limit:" 设置为空 // threadGroup.appendChild(createStringProp(document, "Iterations", "1")); appendStringProp(threadGroup, "Unit", "S"); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/ResultConversionUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/ResultConversionUtil.java index 5f4666bc81..e7c033f7ea 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/ResultConversionUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/ResultConversionUtil.java @@ -37,8 +37,8 @@ public class ResultConversionUtil { String resourceId = result.getResourceId(); ApiScenarioReportResultWithBLOBs report = newScenarioReportResult(reportId, resourceId); - report.setTotalAssertions(Long.parseLong(result.getTotalAssertions() + "")); - report.setPassAssertions(Long.parseLong(result.getPassAssertions() + "")); + report.setTotalAssertions(Long.parseLong(result.getTotalAssertions() + StringUtils.EMPTY)); + report.setPassAssertions(Long.parseLong(result.getPassAssertions() + StringUtils.EMPTY)); String status = result.getError() == 0 ? ApiReportStatus.SUCCESS.name() : ApiReportStatus.ERROR.name(); if (CollectionUtils.isNotEmpty(errorCodeDTO.getErrorCodeList())) { report.setErrorCode(errorCodeDTO.getErrorCodeStr()); diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/WebSocketUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/WebSocketUtil.java index 0c0142c481..1b0f8a49c9 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/WebSocketUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/WebSocketUtil.java @@ -2,6 +2,7 @@ package io.metersphere.commons.utils; import io.metersphere.api.dto.MsgDTO; import io.metersphere.utils.LoggerUtil; +import org.apache.commons.lang3.StringUtils; import javax.websocket.RemoteEndpoint; import javax.websocket.Session; @@ -28,8 +29,8 @@ public class WebSocketUtil { // 单用户推送 public static void sendMessageSingle(MsgDTO dto) { - sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getReportId()).orElse("")), dto.getContent()); - sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getToReport()).orElse("")), dto.getContent()); + sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getReportId()).orElse(StringUtils.EMPTY)), dto.getContent()); + sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getToReport()).orElse(StringUtils.EMPTY)), dto.getContent()); } // 全用户推送 diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/XMLUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/XMLUtil.java index babd98419c..7fbee97ade 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/XMLUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/XMLUtil.java @@ -67,7 +67,7 @@ public class XMLUtil { StringBuffer buffer = new StringBuffer(); buffer.append("\n"); try { - jsonToXmlStr(jObj, buffer, new StringBuffer("")); + jsonToXmlStr(jObj, buffer, new StringBuffer(StringUtils.EMPTY)); } catch (Exception e) { LogUtil.error(e.getMessage(), e); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiScheduleService.java b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiScheduleService.java index b2dd702d99..e95d73cbd8 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiScheduleService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtApiScheduleService.java @@ -339,7 +339,7 @@ public class ExtApiScheduleService { if (list.size() > 0) { return list.get(0).getKey(); } else { - return ""; + return StringUtils.EMPTY; } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java index fa362d8955..41f4dea435 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ext/ExtProjectApplicationService.java @@ -128,7 +128,7 @@ public class ExtProjectApplicationService { public void checkProjectTcpPort(AddProjectRequest project) { //判断端口是否重复 if (project.getMockTcpPort() != null && project.getMockTcpPort().intValue() != 0) { - String projectId = StringUtils.isEmpty(project.getId()) ? "" : project.getId(); + String projectId = StringUtils.isEmpty(project.getId()) ? StringUtils.EMPTY : project.getId(); ProjectApplicationExample example = new ProjectApplicationExample(); example.createCriteria().andTypeEqualTo(ProjectApplicationType.MOCK_TCP_PORT.name()).andTypeValueEqualTo(String.valueOf(project.getMockTcpPort())).andProjectIdNotEqualTo(projectId); if (projectApplicationMapper.countByExample(example) > 0) { diff --git a/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java b/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java index 14045a6c59..9bf0b00a21 100644 --- a/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java +++ b/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java @@ -1001,7 +1001,7 @@ public class PerformanceTestService { LoadTestFileExample example1 = new LoadTestFileExample(); example1.createCriteria().andFileIdEqualTo(fileId); List loadTestFiles = loadTestFileMapper.selectByExample(example1); - String errorMessage = ""; + String errorMessage = StringUtils.EMPTY; if (loadTestFiles.size() > 0) { List testIds = loadTestFiles.stream().map(LoadTestFile::getTestId).distinct().collect(Collectors.toList()); LoadTestExample example = new LoadTestExample(); diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 2f2d27488e..048ecaafcd 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -2688,7 +2688,7 @@ public class TestCaseService { fileContentExample.createCriteria().andFileIdIn(fileIds); List allCaseFileContents = fileContentMapper.selectByExample(fileContentExample); entry.getValue().stream().forEach(relation -> { - String filename = ""; + String filename = StringUtils.EMPTY; List fileMetadatas = allCaseFileMetadatas.stream().filter(fileMetadata -> fileMetadata.getId().equals(relation.getAttachmentId())) .collect(Collectors.toList()); List fileContents = allCaseFileContents.stream().filter(fileContent -> fileContent.getFileId().equals(relation.getAttachmentId())) @@ -2699,7 +2699,7 @@ public class TestCaseService { FileAttachmentMetadata fileAttachmentMetadata = new FileAttachmentMetadata(); BeanUtils.copyBean(fileAttachmentMetadata, fileMetadata); fileAttachmentMetadata.setId(UUID.randomUUID().toString()); - fileAttachmentMetadata.setCreator(""); + fileAttachmentMetadata.setCreator(StringUtils.EMPTY); fileAttachmentMetadata.setFilePath(uploadPath); fileAttachmentMetadataMapper.insert(fileAttachmentMetadata); AttachmentModuleRelation record = new AttachmentModuleRelation(); @@ -3066,7 +3066,7 @@ public class TestCaseService { return; } if (!StringUtils.equals(demandId, "other")) { - demandName = ""; + demandName = StringUtils.EMPTY; } SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class); diff --git a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index 090eb29180..1df10cf1e2 100644 --- a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -119,9 +119,9 @@ public class XmindCaseParser { process.add(Translator.get("test_case_node_level_tip") + TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"), nodePath); } - String path = ""; + String path = StringUtils.EMPTY; for (int i = 0; i < nodes.length; i++) { - if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) { + if (i != 0 && StringUtils.equals(nodes[i].trim(), StringUtils.EMPTY)) { process.add(Translator.get("module_not_null"), path); } else if (nodes[i].trim().length() > 100) { process.add(Translator.get("module") + Translator.get("test_track.length_less_than") + "100", path + nodes[i].trim()); @@ -150,7 +150,7 @@ public class XmindCaseParser { //用例名称判断 if (StringUtils.isEmpty(data.getName())) { validatePass = false; - process.add("name" + Translator.get("cannot_be_null"), nodePath + ""); + process.add("name" + Translator.get("cannot_be_null"), nodePath + StringUtils.EMPTY); } else { if (data.getName().length() > 200) { validatePass = false; @@ -170,7 +170,7 @@ public class XmindCaseParser { } } for (int i = 0; i < nodes.length; i++) { - if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) { + if (i != 0 && StringUtils.equals(nodes[i].trim(), StringUtils.EMPTY)) { validatePass = false; process.add(Translator.get("test_case") + Translator.get("module_not_null"), nodePath + data.getName()); if (!errorPath.contains(nodePath)) { @@ -315,7 +315,7 @@ public class XmindCaseParser { } Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher result = pattern.matcher(str); - str = result.replaceAll(""); + str = result.replaceAll(StringUtils.EMPTY); return str; } @@ -339,8 +339,8 @@ public class XmindCaseParser { // 保持插入顺序,判断用例是否有相同的steps Map step = new LinkedHashMap(); step.put("num", 1); - step.put("desc", ""); - step.put("result", ""); + step.put("desc", StringUtils.EMPTY); + step.put("result", StringUtils.EMPTY); jsonArray.add(step); } return JSON.toJSONString(jsonArray); @@ -364,7 +364,7 @@ public class XmindCaseParser { return; } // 用例名称 - String name = title.replace(tcArrs[0] + ":", "").replace(tcArrs[0] + ":", ""); + String name = title.replace(tcArrs[0] + ":", StringUtils.EMPTY).replace(tcArrs[0] + ":", StringUtils.EMPTY); testCase.setName(name); testCase.setNodePath(nodePath.trim());