diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index fc294e665a..99e0e415a3 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -323,6 +323,8 @@ test_case_status=Case status id_not_rightful=ID is not rightful tags_count=Tags count can not exceed 15 tag_length=Tag length cannot exceed 64 characters +step_length=Step length cannot exceed 1000 characters +result_length=Result length cannot exceed 1000 characters project_reference_multiple_plateform=Projects point to multiple third-party platforms # mock mock_warning=No matching Mock expectation was found diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index e3cea19d99..04ea31c963 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -324,6 +324,8 @@ test_case_status=用例状态 id_not_rightful=ID 不合法 tags_count=标签数量不能超过15个 tag_length=标签长度不能超过64个字符 +step_length=用例步骤不能超过1000个字符 +result_length=预期结果不能超过1000个字符 project_reference_multiple_plateform=项目指向多个第三方平台 # mock mock_warning=未找到匹配的Mock期望 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 82a61d27ab..0f97e2c5e5 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -323,6 +323,8 @@ test_case_status=用例狀態 id_not_rightful=ID 不合法 tags_count=標簽數量不能超過15個 tag_length=標簽長度不能超過64個字符 +step_length=用例步驟長度不能超過1000個字符 +result_length=預期結果長度不能超過1000個字符 project_reference_multiple_plateform=項目指向多個第三方平臺 # mock mock_warning=未找到匹配的Mock期望 diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseCheckEventListener.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseCheckEventListener.java index 7f812b50c9..dc08261d52 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseCheckEventListener.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseCheckEventListener.java @@ -3,6 +3,7 @@ package io.metersphere.functional.excel.listener; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; +import io.metersphere.functional.constants.FunctionalCaseTypeConstants; import io.metersphere.functional.excel.annotation.NotRequired; import io.metersphere.functional.excel.domain.ExcelMergeInfo; import io.metersphere.functional.excel.domain.FunctionalCaseExcelData; @@ -14,11 +15,13 @@ import io.metersphere.functional.request.FunctionalCaseImportRequest; import io.metersphere.functional.service.FunctionalCaseService; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.CommonBeanFactory; +import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.excel.ExcelValidateHelper; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import io.metersphere.system.excel.domain.ExcelErrData; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; @@ -59,7 +62,8 @@ public class FunctionalCaseCheckEventListener extends AnalysisEventListener customFieldValidatorMap; protected static final int TAGS_COUNT = 15; - protected static final int TAG_LENGTH = 15; + protected static final int TAG_LENGTH = 64; + protected static final int STEP_LENGTH = 1000; private FunctionalCaseService functionalCaseService; public FunctionalCaseCheckEventListener(FunctionalCaseImportRequest request, Class clazz, List customFields, Set mergeInfoSet) { @@ -209,8 +213,95 @@ public class FunctionalCaseCheckEventListener extends AnalysisEventListener> steps = new ArrayList<>(); + + if (CollectionUtils.isNotEmpty(data.getMergeTextDescription()) || CollectionUtils.isNotEmpty(data.getMergeExpectedResult())) { + // 如果是合并单元格,则组合多条单元格的数据 + for (int i = 0; i < data.getMergeTextDescription().size(); i++) { + List> rowSteps = getSingleRowSteps(data.getMergeTextDescription().get(i), data.getMergeExpectedResult().get(i), steps.size(),errMsg); + steps.addAll(rowSteps); + } + } else { + // 如果不是合并单元格,则直接解析单元格数据 + steps.addAll(getSingleRowSteps(data.getTextDescription(), data.getExpectedResult(), steps.size(),errMsg)); + } + return JSON.toJSONString(steps); + } + + + private List> getSingleRowSteps(String cellDesc, String cellResult, Integer startStepIndex,StringBuilder errMsg) { + List> steps = new ArrayList<>(); + + List stepDescList = parseStepCell(cellDesc); + List stepResList = parseStepCell(cellResult); + + int index = Math.max(stepDescList.size(), stepResList.size()); + for (int i = 0; i < index; i++) { + // 保持插入顺序,判断用例是否有相同的steps + Map step = new LinkedHashMap<>(); + step.put("num", startStepIndex + i + 1); + if (i < stepDescList.size()) { + step.put("desc", stepDescList.get(i)); + if (stepDescList.get(i).length() > STEP_LENGTH) { + errMsg.append(Translator.get("step_length")) + .append(ERROR_MSG_SEPARATOR); + return steps; + } + } else { + step.put("desc", StringUtils.EMPTY); + } + + if (i < stepResList.size()) { + step.put("result", stepResList.get(i)); + if (stepResList.get(i).length() > STEP_LENGTH) { + errMsg.append(Translator.get("result_length")) + .append(ERROR_MSG_SEPARATOR); + return steps; + } + } else { + step.put("result", StringUtils.EMPTY); + } + + steps.add(step); + } + return steps; + } + + private List parseStepCell(String cellContent) { + List cellStepContentList = new ArrayList<>(); + if (StringUtils.isNotEmpty(cellContent)) { + // 根据[1], [2]...分割步骤描述, 开头空字符去掉, 末尾保留 + String[] cellContentArr = cellContent.split("\\[\\d+]", -1); + if (StringUtils.isEmpty(cellContentArr[0])) { + cellContentArr = Arrays.copyOfRange(cellContentArr, 1, cellContentArr.length); + } + for (String stepContent : cellContentArr) { + cellStepContentList.add(stepContent.replaceAll("(?m)^\\s*|\\s*$", StringUtils.EMPTY)); + } + } else { + cellStepContentList.add(StringUtils.EMPTY); + } + return cellStepContentList; + } + + /** * 校验标签长度 个数 * diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseImportEventListener.java b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseImportEventListener.java index 2d0d68c19b..edc8e83389 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseImportEventListener.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/excel/listener/FunctionalCaseImportEventListener.java @@ -82,7 +82,7 @@ public class FunctionalCaseImportEventListener extends AnalysisEventListener pathMap = new HashMap<>(); protected static final int TAGS_COUNT = 15; - protected static final int TAG_LENGTH = 15; + protected static final int TAG_LENGTH = 64; public FunctionalCaseImportEventListener(FunctionalCaseImportRequest request, Class clazz, List customFields, Set mergeInfoSet, SessionUser user) { this.mergeInfoSet = mergeInfoSet;