From 12f28344d04e2e8db1612853f9d8820935b5462d Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 27 Apr 2021 19:34:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E4=BE=8B=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=94=AF=E6=8C=81=E6=AD=A5=E9=AA=A4=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/constants/TestCaseConstants.java | 4 ++ .../excel/domain/TestCaseExcelData.java | 4 +- .../excel/domain/TestCaseExcelDataCn.java | 6 +++ .../excel/domain/TestCaseExcelDataTw.java | 6 +++ .../excel/domain/TestCaseExcelDataUs.java | 6 +++ .../excel/listener/TestCaseDataListener.java | 11 ++-- .../track/service/TestCaseService.java | 53 +++++++++++-------- .../resources/i18n/messages_en_US.properties | 3 +- .../resources/i18n/messages_zh_CN.properties | 3 +- .../resources/i18n/messages_zh_TW.properties | 3 +- 10 files changed, 71 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestCaseConstants.java b/backend/src/main/java/io/metersphere/commons/constants/TestCaseConstants.java index 79172d7cc6..98dabc202b 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/TestCaseConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/TestCaseConstants.java @@ -45,4 +45,8 @@ public class TestCaseConstants { return types.stream().map(Method::getValue).collect(Collectors.toList()); } } + + public enum StepModel { + TEXT, STEP + } } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java index 099c9b462f..64b878a2f0 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelData.java @@ -32,4 +32,6 @@ public class TestCaseExcelData { private String stepDesc; @ExcelIgnore private String stepResult; -} \ No newline at end of file + @ExcelIgnore + private String stepModel; +} diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java index 32638e93d3..9a0ea3c53d 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataCn.java @@ -69,4 +69,10 @@ public class TestCaseExcelDataCn extends TestCaseExcelData { @ColumnWidth(50) @ExcelProperty("预期结果") private String stepResult; + + @ColumnWidth(50) + @ExcelProperty("编辑模式") + @NotRequired + @Pattern(regexp = "(^TEXT$)|(^STEP$)", message = "{test_case_step_model_validate}") + private String stepModel; } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java index 7060931a30..f60e6d1812 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataTw.java @@ -69,4 +69,10 @@ public class TestCaseExcelDataTw extends TestCaseExcelData { @ColumnWidth(50) @ExcelProperty("預期結果") private String stepResult; + + @ColumnWidth(50) + @ExcelProperty("編輯模式") + @NotRequired + @Pattern(regexp = "(^TEXT$)|(^STEP$)", message = "{test_case_step_model_validate}") + private String stepModel; } diff --git a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java index da1e74ad96..845020b1b4 100644 --- a/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java +++ b/backend/src/main/java/io/metersphere/excel/domain/TestCaseExcelDataUs.java @@ -70,4 +70,10 @@ public class TestCaseExcelDataUs extends TestCaseExcelData { @ColumnWidth(50) @ExcelProperty("Step result") private String stepResult; + + @ColumnWidth(50) + @ExcelProperty("Edit Model") + @NotRequired + @Pattern(regexp = "(^TEXT$)|(^STEP$)", message = "{test_case_step_model_validate}") + private String stepModel; } diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index 12d78b9625..e9b8447885 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -198,9 +198,14 @@ public class TestCaseDataListener extends EasyExcelListener { String modifiedTags = modifyTagPattern(data); testCase.setTags(modifiedTags); - String steps = getSteps(data); - testCase.setSteps(steps); - + if (StringUtils.isNotBlank(data.getStepModel()) + && StringUtils.equals(data.getStepModel(), TestCaseConstants.StepModel.TEXT.name())) { + testCase.setStepDescription(data.getStepDesc()); + testCase.setExpectedResult(data.getStepResult()); + } else { + String steps = getSteps(data); + testCase.setSteps(steps); + } return testCase; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index bf5e583a3b..b799a8be29 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -667,38 +667,49 @@ public class TestCaseService { data.setNodePath(t.getNodePath()); data.setPriority(t.getPriority()); data.setType(t.getType()); + if (StringUtils.isBlank(t.getStepModel())) { + data.setStepModel(TestCaseConstants.StepModel.STEP.name()); + } else { + data.setStepModel(t.getStepModel()); + } // data.setMethod(t.getMethod()); data.setPrerequisite(t.getPrerequisite()); data.setTags(t.getTags()); if (StringUtils.equals(t.getMethod(), "manual") || StringUtils.isBlank(t.getMethod())) { - String steps = t.getSteps(); - String setp = ""; - setp = steps; - JSONArray jsonArray = null; - //解决旧版本保存用例导出报错 - try { - jsonArray = JSON.parseArray(setp); - } catch (Exception e) { - if (steps.contains("null") && !steps.contains("\"null\"")) { - setp = steps.replace("null", "\"\""); + if (StringUtils.equals(data.getStepModel(), TestCaseConstants.StepModel.TEXT.name())) { + data.setStepDesc(t.getStepDescription()); + data.setStepResult(t.getExpectedResult()); + } else { + String steps = t.getSteps(); + String setp = ""; + setp = steps; + JSONArray jsonArray = null; + + //解决旧版本保存用例导出报错 + try { jsonArray = JSON.parseArray(setp); + } catch (Exception e) { + if (steps.contains("null") && !steps.contains("\"null\"")) { + setp = steps.replace("null", "\"\""); + jsonArray = JSON.parseArray(setp); + } } - } - if (CollectionUtils.isNotEmpty(jsonArray)) { - for (int j = 0; j < jsonArray.size(); j++) { - int num = j + 1; - step.append(num + "." + jsonArray.getJSONObject(j).getString("desc") + "\r\n"); - result.append(num + "." + jsonArray.getJSONObject(j).getString("result") + "\r\n"); + if (CollectionUtils.isNotEmpty(jsonArray)) { + for (int j = 0; j < jsonArray.size(); j++) { + int num = j + 1; + step.append(num + "." + jsonArray.getJSONObject(j).getString("desc") + "\r\n"); + result.append(num + "." + jsonArray.getJSONObject(j).getString("result") + "\r\n"); + } } - } - data.setStepDesc(step.toString()); - data.setStepResult(result.toString()); - step.setLength(0); - result.setLength(0); + data.setStepDesc(step.toString()); + data.setStepResult(result.toString()); + step.setLength(0); + result.setLength(0); + } data.setRemark(t.getRemark()); } else if ("auto".equals(t.getMethod()) && "api".equals(t.getType())) { diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 74ce602a5d..9b5fee7017 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -99,6 +99,7 @@ node_deep_limit=The node depth does not exceed 8 layers! before_delete_plan=There is an associated test case under this plan, please unlink it first! incorrect_format=\tincorrect format test_case_type_validate=\tmust be functional, performance, api +test_case_step_model_validate=\tmust be TEXT, STEP test_case_priority_validate=\tmust be P0, P1, P2, P3 test_case_method_validate=\tmust be manual, auto test_case_name=Name @@ -218,4 +219,4 @@ authsource_configuration_is_null=Authentication source configuration cannot be e mobile_phone_number_cannot_be_empty=When the receiving mode is pin and enterprise wechat: the user's mobile phone number cannot be empty custom_field_already=A feild already exists under this workspace: template_already=A template already exists under this workspace: -expect_name_exists=Expect name is exists \ No newline at end of file +expect_name_exists=Expect name is exists diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 483e89fe17..bd455eb94e 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -99,6 +99,7 @@ node_deep_limit=节点深度不超过8层! before_delete_plan=该计划下存在关联测试用例,请先取消关联! incorrect_format=格式错误 test_case_type_validate=必须为functional、performance、api +test_case_step_model_validate=必须为TEXT、STEP test_case_priority_validate=必须为P0、P1、P2、P3 test_case_method_validate=必须为manual、auto test_case_name=用例名称 @@ -218,4 +219,4 @@ authsource_name_is_null=认证源名称不能为空 authsource_configuration_is_null=认证源配置不能为空 custom_field_already=工作空间下已存在该字段: template_already=工作空间下已存在该模板: -expect_name_exists=预期名称已存在 \ No newline at end of file +expect_name_exists=预期名称已存在 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 683414f060..9fc873a7f4 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -99,6 +99,7 @@ node_deep_limit=節點深度不超過8層! before_delete_plan=該計劃下存在關聯測試用例,請先取消關聯! incorrect_format=格式錯誤 test_case_type_validate=必須為functional、performance、api +test_case_step_model_validate=必須為TEXT、STEP test_case_priority_validate=必須為P0、P1、P2、P3 test_case_method_validate=必須為manual、auto test_case_name=用例名稱 @@ -219,4 +220,4 @@ authsource_name_is_null=認證源名稱不能為空 authsource_configuration_is_null=認證源配置不能為空 custom_field_already=工作空間下已存在該字段: template_already=工作空間下已存在該模板: -expect_name_exists=預期名稱已存在 \ No newline at end of file +expect_name_exists=預期名稱已存在