From dfc7f1755e33ab67aee90cf35165abada858dd6c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 17 Sep 2020 13:51:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E5=AF=BC=E5=85=A5=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xmind/XmindToTestCaseParser.java | 22 ++++++++++++++++--- .../resources/i18n/messages_en_US.properties | 2 ++ .../resources/i18n/messages_zh_CN.properties | 2 ++ .../resources/i18n/messages_zh_TW.properties | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/xmind/XmindToTestCaseParser.java b/backend/src/main/java/io/metersphere/xmind/XmindToTestCaseParser.java index c6987dd289..ffa07bd3da 100644 --- a/backend/src/main/java/io/metersphere/xmind/XmindToTestCaseParser.java +++ b/backend/src/main/java/io/metersphere/xmind/XmindToTestCaseParser.java @@ -1,5 +1,6 @@ package io.metersphere.xmind; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.TestCaseWithBLOBs; @@ -23,6 +24,8 @@ import java.util.*; /** * 数据转换 + * 1 解析Xmind文件 XmindParser.parseJson + * 2 解析后的JSON 转成测试用例 */ public class XmindToTestCaseParser { @@ -218,14 +221,25 @@ public class XmindToTestCaseParser { return true; } + // 导入思维导图处理 public String importXmind(MultipartFile multipartFile) { StringBuffer processBuffer = new StringBuffer(); + File file = null; try { - File file = multipartFileToFile(multipartFile); + file = multipartFileToFile(multipartFile); if (file == null || !file.exists()) return Translator.get("incorrect_format"); - JsonRootBean root = XmindParser.parseObject(file); - file.delete(); + + // 获取思维导图内容 + String content = XmindParser.parseJson(file); + if (StringUtils.isEmpty(content) || content.split("(?:tc:|tc:)").length == 1) { + return Translator.get("import_xmind_not_found"); + } + if (!StringUtils.isEmpty(content) && content.split("(?:tc:|tc:)").length > 500) { + return Translator.get("import_xmind_count_error"); + } + JsonRootBean root = JSON.parseObject(content, JsonRootBean.class); + if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) { // 判断是模块还是用例 root.getRootTopic().getChildren().getAttached().forEach(item -> { @@ -246,6 +260,8 @@ public class XmindToTestCaseParser { LogUtil.error(ex.getMessage()); ex.printStackTrace(); } finally { + if (file != null) + file.delete(); testCaseWithBLOBs.clear(); } return process.toString(); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 6cbce8b777..a9be69b2aa 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -153,3 +153,5 @@ quota_duration_excess_workspace=The stress test duration exceeds the work space quota_duration_excess_organization=The stress test duration exceeds the organization quota email_subject=Metersphere timing task result notification +import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500 +import_xmind_not_found=Test case not found \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index dba0ab0432..87ed767fb7 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -152,6 +152,8 @@ quota_max_threads_excess_organization=最大并发数超过组织限额 quota_duration_excess_workspace=压测时长超过工作空间限额 quota_duration_excess_organization=压测时长超过组织限额 email_subject=MeterSphere定时任务结果通知 +import_xmind_count_error=思维导图导入用例数量不能超过 500 条 +import_xmind_not_found=未找到测试用例 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 1ba3befebc..d2fdb48ea6 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -156,3 +156,5 @@ license_valid_license_code=授權碼已經存在 email_subject=MeterSphere定時任務結果通知 +import_xmind_count_error=思維導圖導入用例數量不能超過 500 條 +import_xmind_not_found=未找到测试用例 \ No newline at end of file From 10d42f432dc092a8645fcfa41e8cae494fd8a789 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 17 Sep 2020 14:55:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AAresponse=5Fti?= =?UTF-8?q?meout=EF=BC=8C=E9=81=BF=E5=85=8D=E7=9B=AE=E6=A0=87=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E4=B8=8D=E5=8F=8D=E5=9B=9E=E7=BB=93=E6=9E=9C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=B5=8B=E8=AF=95=E4=B8=8D=E8=83=BD=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parse/xml/reader/jmx/JmeterDocumentParser.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index 5cdd5b3a54..fa090c5af1 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -439,6 +439,12 @@ public class JmeterDocumentParser implements DocumentParser { item.appendChild(ele.getOwnerDocument().createTextNode(context.getProperty("timeout").toString())); } } + // 增加一个response_timeout,避免目标网站不反回结果导致测试不能结束 + if (item instanceof Element && nodeNameEquals(item, STRING_PROP) + && StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.response_timeout")) { + removeChildren(item); + item.appendChild(ele.getOwnerDocument().createTextNode("")); + } } }