From c8f871dbc0beefb118b01851053b7cef3981d468 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 11 Nov 2024 09:55:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8Bxmind?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048527 --user=王旭 [功能用例]github#33991功能用例导出为xmind再导入会报错 “Index 1 out of bounds for length 1” https://www.tapd.cn/55049933/s/1607845 --- .../xmind/parser/XMindCaseParser.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/parser/XMindCaseParser.java b/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/parser/XMindCaseParser.java index af0247834e..2b21b31556 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/parser/XMindCaseParser.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/parser/XMindCaseParser.java @@ -132,7 +132,7 @@ public class XMindCaseParser { this.formatTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null); } else { if (StringUtils.equalsIgnoreCase(parent.getPath().trim(), Translator.get("functional_case.module.default.name"))) { - process.add(Translator.get("incorrect_format"), Translator.get("functional_case.module.default.name.add_error")); + process.add(Translator.get("incorrect_format"), Translator.get("functional_case.module.default.name.add_error")); return; } String nodePath = parent.getPath().trim() + "/" + item.getTitle().trim(); @@ -308,14 +308,14 @@ public class XMindCaseParser { private void formatTestCase(String title, String nodePath, List attacheds) { FunctionalCaseExcelData testCase = new FunctionalCaseExcelData(); String tc = title.replace(":", ":"); - String[] tcArrs = tc.split(":"); + String[] tcArrs = tc.split(":", 2); if (tcArrs.length <= 1) { process.add(Translator.get("test_case_name") + Translator.get("incorrect_format"), title); return; } // 用例名称 String name = title.replace(tcArrs[0] + ":", StringUtils.EMPTY).replace(tcArrs[0] + ":", StringUtils.EMPTY); - if (name.length()>=255) { + if (name.length() >= 255) { process.add(Translator.get("test_case_name") + Translator.get("length.too.large"), title); return; } @@ -365,7 +365,7 @@ public class XMindCaseParser { } } else { //自定义字段 - String[] customFiled = item.getTitle().split("(?:\\s*:|:)",2); + String[] customFiled = item.getTitle().split("(?:\\s*:|:)", 2); Map stringObjectMap = testCase.getCustomData(); if (customFiled.length > 1) { TemplateCustomFieldDTO templateCustomFieldDTO = customFieldsMap.get(customFiled[0]); @@ -407,7 +407,7 @@ public class XMindCaseParser { */ private String getSteps(List attacheds, String caseName) { List functionalCaseStepDTOS = new ArrayList<>(); - if (attacheds!=null && !attacheds.isEmpty()) { + if (attacheds != null && !attacheds.isEmpty()) { for (int i = 0; i < attacheds.size(); i++) { // 保持插入顺序,判断用例是否有相同的steps FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO(); @@ -415,8 +415,8 @@ public class XMindCaseParser { functionalCaseStepDTO.setNum(i + 1); if (isAvailable(attacheds.get(i).getTitle(), STEP)) { String stepDesc = attacheds.get(i).getTitle().replace(":", ":"); - String[] stepDescArrs = stepDesc.split(":"); - functionalCaseStepDTO.setDesc(StringUtils.isNotBlank(stepDescArrs[1]) ? stepDescArrs[1] : StringUtils.EMPTY); + String[] stepDescArrs = stepDesc.split(":", 2); + functionalCaseStepDTO.setDesc(stepDescArrs.length < 2 ? StringUtils.EMPTY : stepDescArrs[1]); } else { functionalCaseStepDTO.setDesc(StringUtils.EMPTY); } @@ -429,8 +429,8 @@ public class XMindCaseParser { String title = attacheds.get(i).getChildren().getAttached().get(0).getTitle(); if (isAvailable(title, EXPECTED_RESULT)) { String stepDesc = title.replace(":", ":"); - String[] stepDescArrs = stepDesc.split(":"); - functionalCaseStepDTO.setResult(StringUtils.isNotBlank(stepDescArrs[1]) ? stepDescArrs[1] : StringUtils.EMPTY); + String[] stepDescArrs = stepDesc.split(":", 2); + functionalCaseStepDTO.setResult(stepDescArrs.length < 2 ? StringUtils.EMPTY : stepDescArrs[1]); } else { functionalCaseStepDTO.setResult(StringUtils.EMPTY); } @@ -452,6 +452,7 @@ public class XMindCaseParser { } return JSON.toJSONString(functionalCaseStepDTOS); } + /** * 获取步骤数据 */ @@ -460,7 +461,7 @@ public class XMindCaseParser { String title = attacheds.get(0).getTitle(); if (isAvailable(title, EXPECTED_RESULT)) { String stepDesc = title.replace(":", ":"); - String[] stepDescArrs = stepDesc.split(":"); + String[] stepDescArrs = stepDesc.split(":", 2); return StringUtils.isNotBlank(stepDescArrs[1]) ? stepDescArrs[1] : StringUtils.EMPTY; } else { return StringUtils.EMPTY;