refactor(用例管理): 脑图读取时空字符串不显示

This commit is contained in:
guoyuqi 2024-05-20 09:42:51 +08:00 committed by 刘瑞斌
parent 9077c44c45
commit 66f4226f18
2 changed files with 43 additions and 21 deletions

View File

@ -154,23 +154,28 @@ public class FunctionalCaseMinderService {
List<FunctionalMinderTreeDTO> children = new ArrayList<>(); List<FunctionalMinderTreeDTO> children = new ArrayList<>();
if (functionalCaseMindDTO.getPrerequisite() != null) { if (functionalCaseMindDTO.getPrerequisite() != null) {
String prerequisiteText = new String(functionalCaseMindDTO.getPrerequisite(), StandardCharsets.UTF_8); String prerequisiteText = new String(functionalCaseMindDTO.getPrerequisite(), StandardCharsets.UTF_8);
if (StringUtils.isNotBlank(prerequisiteText)) {
FunctionalMinderTreeDTO prerequisiteFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(prerequisiteText, Translator.get("minder_extra_node.prerequisite"), 0L); FunctionalMinderTreeDTO prerequisiteFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(prerequisiteText, Translator.get("minder_extra_node.prerequisite"), 0L);
children.add(prerequisiteFunctionalMinderTreeDTO); children.add(prerequisiteFunctionalMinderTreeDTO);
} }
}
if (StringUtils.equalsIgnoreCase(functionalCaseMindDTO.getCaseEditType(), FunctionalCaseTypeConstants.CaseEditType.TEXT.name()) && functionalCaseMindDTO.getTextDescription() != null) { if (StringUtils.equalsIgnoreCase(functionalCaseMindDTO.getCaseEditType(), FunctionalCaseTypeConstants.CaseEditType.TEXT.name()) && functionalCaseMindDTO.getTextDescription() != null) {
String textDescription = new String(functionalCaseMindDTO.getTextDescription(), StandardCharsets.UTF_8); String textDescription = new String(functionalCaseMindDTO.getTextDescription(), StandardCharsets.UTF_8);
FunctionalMinderTreeDTO stepFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(textDescription, Translator.get("minder_extra_node.text_description"), 1L); FunctionalMinderTreeDTO stepFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(textDescription, Translator.get("minder_extra_node.text_description"), 1L);
String expectedResultText = "";
if (functionalCaseMindDTO.getExpectedResult() != null) { 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); FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(expectedResultText, Translator.get("minder_extra_node.text_expected_result"), 1L);
stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO); stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO);
} else { } 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); stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO);
} }
if (StringUtils.isNotBlank(textDescription) || StringUtils.isNotBlank(expectedResultText)) {
children.add(stepFunctionalMinderTreeDTO); children.add(stepFunctionalMinderTreeDTO);
} }
}
int i = 1; int i = 1;
if (StringUtils.equalsIgnoreCase(functionalCaseMindDTO.getCaseEditType(), FunctionalCaseTypeConstants.CaseEditType.STEP.name()) && functionalCaseMindDTO.getSteps() != null) { if (StringUtils.equalsIgnoreCase(functionalCaseMindDTO.getCaseEditType(), FunctionalCaseTypeConstants.CaseEditType.STEP.name()) && functionalCaseMindDTO.getSteps() != null) {
@ -179,25 +184,32 @@ public class FunctionalCaseMinderService {
List<FunctionalCaseStepDTO> functionalCaseStepDTOS = JSON.parseArray(stepText, FunctionalCaseStepDTO.class); List<FunctionalCaseStepDTO> functionalCaseStepDTOS = JSON.parseArray(stepText, FunctionalCaseStepDTO.class);
for (FunctionalCaseStepDTO functionalCaseStepDTO : functionalCaseStepDTOS) { for (FunctionalCaseStepDTO functionalCaseStepDTO : functionalCaseStepDTOS) {
i = i + 1; 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()); stepFunctionalMinderTreeDTO.getData().setId(functionalCaseStepDTO.getId());
FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO; FunctionalMinderTreeDTO expectedResultFunctionalMinderTreeDTO;
String result = "";
if (functionalCaseMindDTO.getExpectedResult() != null) { 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 { } 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); stepFunctionalMinderTreeDTO.getChildren().add(expectedResultFunctionalMinderTreeDTO);
if (StringUtils.isNotBlank(desc) || StringUtils.isNotBlank(result)) {
children.add(stepFunctionalMinderTreeDTO); children.add(stepFunctionalMinderTreeDTO);
} }
} }
} }
}
if (functionalCaseMindDTO.getDescription() != null) { if (functionalCaseMindDTO.getDescription() != null) {
String descriptionText = new String(functionalCaseMindDTO.getDescription(), StandardCharsets.UTF_8); String descriptionText = new String(functionalCaseMindDTO.getDescription(), StandardCharsets.UTF_8);
if (StringUtils.isNotBlank(descriptionText)) {
FunctionalMinderTreeDTO descriptionFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(descriptionText, Translator.get("minder_extra_node.description"), (long) (i + 1)); FunctionalMinderTreeDTO descriptionFunctionalMinderTreeDTO = getFunctionalMinderTreeDTO(descriptionText, Translator.get("minder_extra_node.description"), (long) (i + 1));
children.add(descriptionFunctionalMinderTreeDTO); children.add(descriptionFunctionalMinderTreeDTO);
} }
}
return children; return children;
} }

View File

@ -15,6 +15,7 @@ import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -59,6 +60,22 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
Assertions.assertNotNull(resultHolder); 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<FunctionalCaseStepDTO> list = new ArrayList<>(); List<FunctionalCaseStepDTO> list = new ArrayList<>();
FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO(); FunctionalCaseStepDTO functionalCaseStepDTO = new FunctionalCaseStepDTO();
functionalCaseStepDTO.setId("12455"); functionalCaseStepDTO.setId("12455");
@ -77,15 +94,15 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
String prerequisite = "前置条件"; String prerequisite = "前置条件";
String description = "备注"; String description = "备注";
FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob(); functionalCaseBlob = new FunctionalCaseBlob();
functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); functionalCaseBlob.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_2");
functionalCaseBlob.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setTextDescription(textDescription.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setTextDescription(textDescription.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setExpectedResult(expectedResult.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setExpectedResult(expectedResult.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setPrerequisite(prerequisite.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setPrerequisite(prerequisite.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setDescription(description.getBytes(StandardCharsets.UTF_8)); functionalCaseBlob.setDescription(description.getBytes(StandardCharsets.UTF_8));
functionalCaseBlobMapper.insert(functionalCaseBlob); functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob);
FunctionalCaseBlob functionalCaseBlob6 = new FunctionalCaseBlob(); functionalCaseBlob6 = new FunctionalCaseBlob();
functionalCaseBlob6.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_1"); functionalCaseBlob6.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_1");
functionalCaseBlob6.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8)); functionalCaseBlob6.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8));
functionalCaseBlob6.setTextDescription(textDescription.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); resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class);
Assertions.assertNotNull(baseTreeNodes); Assertions.assertNotNull(baseTreeNodes);
String jsonString = JSON.toJSONString(baseTreeNodes);
System.out.println(jsonString);
Assertions.assertEquals(2, baseTreeNodes.size()); Assertions.assertEquals(2, baseTreeNodes.size());
} }
@ -207,8 +222,6 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class);
Assertions.assertNotNull(baseTreeNodes); Assertions.assertNotNull(baseTreeNodes);
String jsonString = JSON.toJSONString(baseTreeNodes);
System.out.println(jsonString);
Assertions.assertEquals(1, baseTreeNodes.size()); Assertions.assertEquals(1, baseTreeNodes.size());
request = new FunctionalCaseReviewMindRequest(); request = new FunctionalCaseReviewMindRequest();
request.setProjectId("project-case-minder-test"); request.setProjectId("project-case-minder-test");
@ -221,10 +234,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class);
Assertions.assertNotNull(baseTreeNodes); Assertions.assertNotNull(baseTreeNodes);
jsonString = JSON.toJSONString(baseTreeNodes);
System.out.println(jsonString);
Assertions.assertEquals(1, baseTreeNodes.size()); Assertions.assertEquals(1, baseTreeNodes.size());
} }
} }