From 66f4226f1843d33d382d357508b753631da224e6 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 20 May 2024 09:42:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E8=84=91=E5=9B=BE=E8=AF=BB=E5=8F=96=E6=97=B6=E7=A9=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FunctionalCaseMinderService.java | 34 +++++++++++++------ .../FunctionalCaseMinderControllerTest.java | 30 ++++++++++------ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index f2b1c2ccea..083446a298 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -154,22 +154,27 @@ public class FunctionalCaseMinderService { List children = new ArrayList<>(); if (functionalCaseMindDTO.getPrerequisite() != null) { String prerequisiteText = new String(functionalCaseMindDTO.getPrerequisite(), StandardCharsets.UTF_8); - FunctionalMinderTreeDTO prerequisiteFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(prerequisiteText, Translator.get("minder_extra_node.prerequisite"), 0L); - children.add(prerequisiteFunctionalMinderTreeDTO); + if (StringUtils.isNotBlank(prerequisiteText)) { + FunctionalMinderTreeDTO prerequisiteFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(prerequisiteText, Translator.get("minder_extra_node.prerequisite"), 0L); + children.add(prerequisiteFunctionalMinderTreeDTO); + } } if (StringUtils.equalsIgnoreCase(functionalCaseMindDTO.getCaseEditType(), FunctionalCaseTypeConstants.CaseEditType.TEXT.name()) && functionalCaseMindDTO.getTextDescription() != null) { String textDescription = new String(functionalCaseMindDTO.getTextDescription(), StandardCharsets.UTF_8); FunctionalMinderTreeDTO stepFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(textDescription, Translator.get("minder_extra_node.text_description"), 1L); + String expectedResultText = ""; if (functionalCaseMindDTO.getExpectedResult() != null) { - String expectedResultText = new String(functionalCaseMindDTO.getExpectedResult(), StandardCharsets.UTF_8); + expectedResultText = new String(functionalCaseMindDTO.getExpectedResult(), StandardCharsets.UTF_8); FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(expectedResultText, Translator.get("minder_extra_node.text_expected_result"), 1L); stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO); } else { - FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO("", Translator.get("minder_extra_node.text_expected_result"), 1L); + FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(expectedResultText, Translator.get("minder_extra_node.text_expected_result"), 1L); stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO); } - children.add(stepFunctionalMinderTreeDTO); + if (StringUtils.isNotBlank(textDescription) || StringUtils.isNotBlank(expectedResultText)) { + children.add(stepFunctionalMinderTreeDTO); + } } int i = 1; @@ -179,24 +184,31 @@ public class FunctionalCaseMinderService { List functionalCaseStepDTOS = JSON.parseArray(stepText, FunctionalCaseStepDTO.class); for (FunctionalCaseStepDTO functionalCaseStepDTO : functionalCaseStepDTOS) { i = i + 1; - FunctionalMinderTreeDTO stepFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(functionalCaseStepDTO.getDesc(), Translator.get("minder_extra_node.steps"), Long.valueOf(functionalCaseStepDTO.getNum())); + String desc = functionalCaseStepDTO.getDesc(); + FunctionalMinderTreeDTO stepFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(desc, Translator.get("minder_extra_node.steps"), Long.valueOf(functionalCaseStepDTO.getNum())); stepFunctionalMinderTreeDTO.getData().setId(functionalCaseStepDTO.getId()); FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO; + String result = ""; if (functionalCaseMindDTO.getExpectedResult() != null) { - expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(functionalCaseStepDTO.getResult(), Translator.get("minder_extra_node.steps_expected_result"), Long.valueOf(functionalCaseStepDTO.getNum())); + result = functionalCaseStepDTO.getResult(); + expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(result, Translator.get("minder_extra_node.steps_expected_result"), Long.valueOf(functionalCaseStepDTO.getNum())); } else { - expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO("", Translator.get("minder_extra_node.steps_expected_result"), Long.valueOf(functionalCaseStepDTO.getNum())); + expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(result, Translator.get("minder_extra_node.steps_expected_result"), Long.valueOf(functionalCaseStepDTO.getNum())); } stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO); - children.add(stepFunctionalMinderTreeDTO); + if (StringUtils.isNotBlank(desc) || StringUtils.isNotBlank(result)) { + children.add(stepFunctionalMinderTreeDTO); + } } } } if (functionalCaseMindDTO.getDescription() != null) { String descriptionText = new String(functionalCaseMindDTO.getDescription(), StandardCharsets.UTF_8); - FunctionalMinderTreeDTO descriptionFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(descriptionText, Translator.get("minder_extra_node.description"), (long) (i + 1)); - children.add(descriptionFunctionalMinderTreeDTO); + if (StringUtils.isNotBlank(descriptionText)) { + FunctionalMinderTreeDTO descriptionFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(descriptionText, Translator.get("minder_extra_node.description"), (long) (i + 1)); + children.add(descriptionFunctionalMinderTreeDTO); + } } return children; } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java index 2f843800fe..41751f0110 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java @@ -15,6 +15,7 @@ import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -59,6 +60,22 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); Assertions.assertNotNull(resultHolder); + FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob(); + functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); + functionalCaseBlob.setSteps(JSON.toJSONString(new ArrayList<>()).getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob.setTextDescription(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob.setExpectedResult(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob.setPrerequisite(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob.setDescription(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlobMapper.insert(functionalCaseBlob); + FunctionalCaseBlob functionalCaseBlob6 = new FunctionalCaseBlob(); + functionalCaseBlob6.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_1"); + functionalCaseBlob6.setSteps(JSON.toJSONString(new ArrayList<>()).getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob6.setTextDescription(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob6.setExpectedResult(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob6.setPrerequisite(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlob6.setDescription(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8)); + functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob6); List list = new ArrayList<>(); FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO(); functionalCaseStepDTO.setId("12455"); @@ -77,15 +94,15 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { String prerequisite = "前置条件"; String description = "备注"; - FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob(); + functionalCaseBlob = new FunctionalCaseBlob(); functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); functionalCaseBlob.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setTextDescription(textDescription.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setExpectedResult(expectedResult.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setPrerequisite(prerequisite.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setDescription(description.getBytes(StandardCharsets.UTF_8)); - functionalCaseBlobMapper.insert(functionalCaseBlob); - FunctionalCaseBlob functionalCaseBlob6 = new FunctionalCaseBlob(); + functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob); + functionalCaseBlob6 = new FunctionalCaseBlob(); functionalCaseBlob6.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_1"); functionalCaseBlob6.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8)); functionalCaseBlob6.setTextDescription(textDescription.getBytes(StandardCharsets.UTF_8)); @@ -99,8 +116,6 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Assertions.assertNotNull(baseTreeNodes); - String jsonString = JSON.toJSONString(baseTreeNodes); - System.out.println(jsonString); Assertions.assertEquals(2, baseTreeNodes.size()); } @@ -207,8 +222,6 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Assertions.assertNotNull(baseTreeNodes); - String jsonString = JSON.toJSONString(baseTreeNodes); - System.out.println(jsonString); Assertions.assertEquals(1, baseTreeNodes.size()); request = new FunctionalCaseReviewMindRequest(); request.setProjectId("project-case-minder-test"); @@ -221,10 +234,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Assertions.assertNotNull(baseTreeNodes); - jsonString = JSON.toJSONString(baseTreeNodes); - System.out.println(jsonString); Assertions.assertEquals(1, baseTreeNodes.size()); - } }