fix(测试用例): 修复导出再导入格式问题

--bug=1045075 --user=王旭 【测试用例】导出用例为xmind后再次导入-导入失败-提示ID不合法 https://www.tapd.cn/55049933/s/1562248
This commit is contained in:
WangXu10 2024-08-14 13:50:23 +08:00 committed by 刘瑞斌
parent f1358a55de
commit ba1a23b8f6
2 changed files with 25 additions and 18 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.functional.xmind.parser; package io.metersphere.functional.xmind.parser;
import io.metersphere.functional.constants.FunctionalCaseTypeConstants;
import io.metersphere.functional.dto.FunctionalCaseStepDTO; import io.metersphere.functional.dto.FunctionalCaseStepDTO;
import io.metersphere.functional.excel.domain.FunctionalCaseExcelData; import io.metersphere.functional.excel.domain.FunctionalCaseExcelData;
import io.metersphere.functional.excel.exception.CustomFieldValidateException; import io.metersphere.functional.excel.exception.CustomFieldValidateException;
@ -83,7 +84,7 @@ public class XMindCaseParser {
private static final String CASE = "(?:CASE-|case-)"; private static final String CASE = "(?:CASE-|case-)";
private static final String PREREQUISITE = "(?:" + Translator.get("xmind_prerequisite") + ":|" + Translator.get("xmind_prerequisite") + ")"; private static final String PREREQUISITE = "(?:" + Translator.get("xmind_prerequisite") + ":|" + Translator.get("xmind_prerequisite") + ")";
private static final String STEP = "(?:" + Translator.get("xmind_step") + ":|" + Translator.get("xmind_step") + ")"; private static final String STEP = "(?:" + Translator.get("xmind_step") + ":|" + Translator.get("xmind_step") + ")";
private static final String STEP_DESCRIPTION = "(?:" + Translator.get("xmind_stepDescription") + ":|" + Translator.get("xmind_stepDescription") + ")"; private static final String STEP_DESCRIPTION = Translator.get("xmind_stepDescription");
private static final String TEXT_DESCRIPTION = "(?:" + Translator.get("xmind_textDescription") + ":|" + Translator.get("xmind_textDescription") + ")"; private static final String TEXT_DESCRIPTION = "(?:" + Translator.get("xmind_textDescription") + ":|" + Translator.get("xmind_textDescription") + ")";
private static final String EXPECTED_RESULT = "(?:" + Translator.get("xmind_expectedResult") + ":|" + Translator.get("xmind_expectedResult") + ")"; private static final String EXPECTED_RESULT = "(?:" + Translator.get("xmind_expectedResult") + ":|" + Translator.get("xmind_expectedResult") + ")";
private static final String DESCRIPTION = "(?:" + Translator.get("xmind_description") + ":|" + Translator.get("xmind_description") + ")"; private static final String DESCRIPTION = "(?:" + Translator.get("xmind_description") + ":|" + Translator.get("xmind_description") + ")";
@ -169,6 +170,10 @@ public class XMindCaseParser {
*/ */
private boolean validateTags(FunctionalCaseExcelData data) { private boolean validateTags(FunctionalCaseExcelData data) {
AtomicBoolean validate = new AtomicBoolean(true); AtomicBoolean validate = new AtomicBoolean(true);
if (StringUtils.isBlank(data.getTags())) {
data.setTags("");
return validate.get();
}
List<String> tags = functionalCaseService.handleImportTags(data.getTags()); List<String> tags = functionalCaseService.handleImportTags(data.getTags());
if (tags.size() > TAGS_COUNT) { if (tags.size() > TAGS_COUNT) {
process.add(data.getName(), Translator.get("tags_count")); process.add(data.getName(), Translator.get("tags_count"));
@ -340,6 +345,7 @@ public class XMindCaseParser {
testCase.setPrerequisite(replace(item.getTitle(), PREREQUISITE)); testCase.setPrerequisite(replace(item.getTitle(), PREREQUISITE));
} else if (isAvailable(item.getTitle(), TEXT_DESCRIPTION)) { } else if (isAvailable(item.getTitle(), TEXT_DESCRIPTION)) {
testCase.setTextDescription(replace(item.getTitle(), TEXT_DESCRIPTION)); testCase.setTextDescription(replace(item.getTitle(), TEXT_DESCRIPTION));
testCase.setCaseEditType(FunctionalCaseTypeConstants.CaseEditType.TEXT.name());
} else if (isAvailable(item.getTitle(), DESCRIPTION)) { } else if (isAvailable(item.getTitle(), DESCRIPTION)) {
testCase.setTextDescription(replace(item.getTitle(), DESCRIPTION)); testCase.setTextDescription(replace(item.getTitle(), DESCRIPTION));
} else if (isAvailable(item.getTitle(), TAGS)) { } else if (isAvailable(item.getTitle(), TAGS)) {
@ -356,6 +362,7 @@ public class XMindCaseParser {
} else if (isAvailable(item.getTitle(), STEP_DESCRIPTION)) { } else if (isAvailable(item.getTitle(), STEP_DESCRIPTION)) {
if (item.getChildren() != null) { if (item.getChildren() != null) {
testCase.setSteps(this.getSteps(item.getChildren().getAttached(), title)); testCase.setSteps(this.getSteps(item.getChildren().getAttached(), title));
testCase.setCaseEditType(FunctionalCaseTypeConstants.CaseEditType.STEP.name());
} }
} else { } else {
//自定义字段 //自定义字段

View File

@ -136,12 +136,12 @@ public class XmindExportUtil {
TemplateCustomFieldDTO priorityDto = dto.getTemplateCustomFieldDTOList().stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get(); TemplateCustomFieldDTO priorityDto = dto.getTemplateCustomFieldDTOList().stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get();
String priority = Translator.get("custom_field.functional_priority").concat("").concat(Translator.get("required")).concat(", ").concat(Translator.get("options")).concat(JSON.toJSONString(customFieldOptionsMap.get(priorityDto.getFieldName()))); String priority = Translator.get("custom_field.functional_priority").concat("").concat(Translator.get("required")).concat(", ").concat(Translator.get("options")).concat(JSON.toJSONString(customFieldOptionsMap.get(priorityDto.getFieldName())));
String name = Translator.get("case.export.system.columns.name").concat(", ").concat(Translator.get("required")); String name = Translator.get("case.export.system.columns.name").concat(", ").concat(Translator.get("required"));
itemTopic.setTitleText("case-P0: ".concat(dto.getName()).concat(" ").concat(priority).concat(name)); itemTopic.setTitleText("case-P0".concat(dto.getName()).concat(" ").concat(priority).concat(name));
//前置条件 //前置条件
if (StringUtils.isNotBlank(dto.getPrerequisite())) { if (StringUtils.isNotBlank(dto.getPrerequisite())) {
ITopic preTopic = workbook.createTopic(); ITopic preTopic = workbook.createTopic();
preTopic.setTitleText(Translator.get("xmind_prerequisite").concat(": ").concat(dto.getPrerequisite())); preTopic.setTitleText(Translator.get("xmind_prerequisite").concat("").concat(dto.getPrerequisite()));
if (style != null) { if (style != null) {
preTopic.setStyleId(style.getId()); preTopic.setStyleId(style.getId());
} }
@ -151,7 +151,7 @@ public class XmindExportUtil {
//备注 //备注
if (StringUtils.isNotBlank(dto.getDescription())) { if (StringUtils.isNotBlank(dto.getDescription())) {
ITopic deTopic = workbook.createTopic(); ITopic deTopic = workbook.createTopic();
deTopic.setTitleText(Translator.get("xmind_description").concat(": ").concat(dto.getDescription())); deTopic.setTitleText(Translator.get("xmind_description").concat("").concat(dto.getDescription()));
if (style != null) { if (style != null) {
deTopic.setStyleId(style.getId()); deTopic.setStyleId(style.getId());
} }
@ -162,7 +162,7 @@ public class XmindExportUtil {
if (StringUtils.isNotBlank(dto.getTags())) { if (StringUtils.isNotBlank(dto.getTags())) {
try { try {
ITopic tagTopic = workbook.createTopic(); ITopic tagTopic = workbook.createTopic();
tagTopic.setTitleText(Translator.get("xmind_tags").concat(": ").concat(dto.getTags())); tagTopic.setTitleText(Translator.get("xmind_tags").concat("").concat(dto.getTags()));
if (style != null) { if (style != null) {
tagTopic.setStyleId(style.getId()); tagTopic.setStyleId(style.getId());
} }
@ -175,14 +175,14 @@ public class XmindExportUtil {
//文本描述 //文本描述
ITopic textDesTopic = workbook.createTopic(); ITopic textDesTopic = workbook.createTopic();
String desc = dto.getTextDescription(); String desc = dto.getTextDescription();
textDesTopic.setTitleText(desc == null ? Translator.get("xmind_textDescription").concat(": ") : Translator.get("xmind_textDescription").concat(": ").concat(desc)); textDesTopic.setTitleText(desc == null ? Translator.get("xmind_textDescription").concat("") : Translator.get("xmind_textDescription").concat("").concat(desc));
if (style != null) { if (style != null) {
textDesTopic.setStyleId(style.getId()); textDesTopic.setStyleId(style.getId());
} }
String result = dto.getExpectedResult(); String result = dto.getExpectedResult();
ITopic resultTopic = workbook.createTopic(); ITopic resultTopic = workbook.createTopic();
resultTopic.setTitleText(result == null ? Translator.get("xmind_expectedResult").concat(": ") : Translator.get("xmind_expectedResult").concat(": ").concat(result)); resultTopic.setTitleText(result == null ? Translator.get("xmind_expectedResult").concat("") : Translator.get("xmind_expectedResult").concat("").concat(result));
if (style != null) { if (style != null) {
resultTopic.setStyleId(style.getId()); resultTopic.setStyleId(style.getId());
} }
@ -205,7 +205,7 @@ public class XmindExportUtil {
if (obj.containsKey("desc")) { if (obj.containsKey("desc")) {
ITopic stepTopic = workbook.createTopic(); ITopic stepTopic = workbook.createTopic();
String desc = obj.get("desc"); String desc = obj.get("desc");
stepTopic.setTitleText(Translator.get("xmind_step").concat(": ").concat(desc)); stepTopic.setTitleText(Translator.get("xmind_step").concat("").concat(desc));
if (style != null) { if (style != null) {
stepTopic.setStyleId(style.getId()); stepTopic.setStyleId(style.getId());
} }
@ -216,7 +216,7 @@ public class XmindExportUtil {
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
hasResult = true; hasResult = true;
ITopic resultTopic = workbook.createTopic(); ITopic resultTopic = workbook.createTopic();
resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat(": ").concat(result)); resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat("").concat(result));
if (style != null) { if (style != null) {
resultTopic.setStyleId(style.getId()); resultTopic.setStyleId(style.getId());
} }
@ -240,7 +240,7 @@ public class XmindExportUtil {
if (!StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))) { if (!StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))) {
ITopic customTopic = workbook.createTopic(); ITopic customTopic = workbook.createTopic();
String fieldComment = getComment(item, customFieldOptionsMap); String fieldComment = getComment(item, customFieldOptionsMap);
customTopic.setTitleText(item.getFieldName().concat(": ").concat(fieldComment)); customTopic.setTitleText(item.getFieldName().concat("").concat(fieldComment));
if (style != null) { if (style != null) {
customTopic.setStyleId(style.getId()); customTopic.setStyleId(style.getId());
} }
@ -424,7 +424,7 @@ public class XmindExportUtil {
//用例名称 //用例名称
TemplateCustomFieldDTO priority = templateCustomFields.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get(); TemplateCustomFieldDTO priority = templateCustomFields.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get();
String casePriority = customFieldMap.get(priority.getFieldId()); String casePriority = customFieldMap.get(priority.getFieldId());
itemTopic.setTitleText("case-".concat(StringUtils.defaultIfBlank(casePriority, StringUtils.EMPTY)).concat(": ").concat(dto.getName())); itemTopic.setTitleText("case-".concat(StringUtils.defaultIfBlank(casePriority, StringUtils.EMPTY)).concat("").concat(dto.getName()));
//系统字段 //系统字段
systemColumns.forEach(item -> { systemColumns.forEach(item -> {
if (columns.getSystemColumns().containsKey(item) && !StringUtils.equalsIgnoreCase(item, "name") if (columns.getSystemColumns().containsKey(item) && !StringUtils.equalsIgnoreCase(item, "name")
@ -432,13 +432,13 @@ public class XmindExportUtil {
ITopic preTopic = workbook.createTopic(); ITopic preTopic = workbook.createTopic();
switch (item) { switch (item) {
case "num": case "num":
preTopic.setTitleText(columns.getSystemColumns().get(item).concat(": ").concat(dto.getNum())); preTopic.setTitleText(columns.getSystemColumns().get(item).concat("").concat(dto.getNum()));
break; break;
case "prerequisite": case "prerequisite":
preTopic.setTitleText(columns.getSystemColumns().get(item).concat(": ").concat(dto.getPrerequisite())); preTopic.setTitleText(columns.getSystemColumns().get(item).concat("").concat(dto.getPrerequisite()));
break; break;
case "module": case "module":
preTopic.setTitleText(columns.getSystemColumns().get(item).concat(": ").concat(moduleName)); preTopic.setTitleText(columns.getSystemColumns().get(item).concat("").concat(moduleName));
break; break;
default: default:
break; break;
@ -454,14 +454,14 @@ public class XmindExportUtil {
//文本描述 //文本描述
ITopic textDesTopic = workbook.createTopic(); ITopic textDesTopic = workbook.createTopic();
String desc = dto.getTextDescription(); String desc = dto.getTextDescription();
textDesTopic.setTitleText(Translator.get("xmind_textDescription").concat(": ").concat(dto.getTextDescription())); textDesTopic.setTitleText(Translator.get("xmind_textDescription").concat("").concat(dto.getTextDescription()));
if (style != null) { if (style != null) {
textDesTopic.setStyleId(style.getId()); textDesTopic.setStyleId(style.getId());
} }
String result = dto.getExpectedResult(); String result = dto.getExpectedResult();
ITopic resultTopic = workbook.createTopic(); ITopic resultTopic = workbook.createTopic();
resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat(": ").concat(dto.getExpectedResult())); resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat("").concat(dto.getExpectedResult()));
if (style != null) { if (style != null) {
resultTopic.setStyleId(style.getId()); resultTopic.setStyleId(style.getId());
} }
@ -484,7 +484,7 @@ public class XmindExportUtil {
if (obj.containsKey("desc")) { if (obj.containsKey("desc")) {
ITopic stepTopic = workbook.createTopic(); ITopic stepTopic = workbook.createTopic();
String desc = obj.get("desc"); String desc = obj.get("desc");
stepTopic.setTitleText(Translator.get("xmind_step").concat(": ").concat(desc)); stepTopic.setTitleText(Translator.get("xmind_step").concat("").concat(desc));
if (style != null) { if (style != null) {
stepTopic.setStyleId(style.getId()); stepTopic.setStyleId(style.getId());
} }
@ -495,7 +495,7 @@ public class XmindExportUtil {
if (StringUtils.isNotEmpty(result)) { if (StringUtils.isNotEmpty(result)) {
hasResult = true; hasResult = true;
ITopic resultTopic = workbook.createTopic(); ITopic resultTopic = workbook.createTopic();
resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat(": ").concat(result)); resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat("").concat(result));
if (style != null) { if (style != null) {
resultTopic.setStyleId(style.getId()); resultTopic.setStyleId(style.getId());
} }