feat(用例管理): 增加单元测试覆盖率

This commit is contained in:
guoyuqi 2024-05-09 09:54:54 +08:00 committed by 刘瑞斌
parent 76c466a6a8
commit 26ac5c4636
2 changed files with 25 additions and 23 deletions

View File

@ -288,20 +288,10 @@ public class FunctionalCaseMinderService {
MinderTargetDTO moduleMinderTargetDTO = request.getModuleMinderTargetDTO();
List<MinderOptionDTO> caseOptionDTOS = resourceMap.get(MinderLabel.CASE.toString());
List<String> caseIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(caseOptionDTOS)) {
caseIds = caseOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
if (!extCheckOwnerMapper.checkoutOwner(FUNCTIONAL_CASE, userId, caseIds)) {
throw new MSException(Translator.get(CHECK_OWNER_CASE));
}
}
caseIds = checkPermission(caseOptionDTOS, caseIds, FUNCTIONAL_CASE, userId);
List<String> moduleIds = new ArrayList<>();
List<MinderOptionDTO> moduleOptionDTOS = resourceMap.get(MinderLabel.MODULE.toString());
if (CollectionUtils.isNotEmpty(moduleOptionDTOS)) {
moduleIds = moduleOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
if (!extCheckOwnerMapper.checkoutOwner(FUNCTIONAL_CASE_MODULE, userId, moduleIds)) {
throw new MSException(Translator.get(CHECK_OWNER_CASE));
}
}
moduleIds = checkPermission(moduleOptionDTOS, moduleIds, FUNCTIONAL_CASE_MODULE, userId);
if (StringUtils.isNotBlank(request.getParentTargetId()) ) {
//移动到某节点下
if (!extCheckOwnerMapper.checkoutOwner(FUNCTIONAL_CASE_MODULE, userId, List.of(request.getParentTargetId()))) {
@ -333,6 +323,16 @@ public class FunctionalCaseMinderService {
}
private List<String> checkPermission(List<MinderOptionDTO> caseOptionDTOS, List<String> caseIds, String functionalCase, String userId) {
if (CollectionUtils.isNotEmpty(caseOptionDTOS)) {
caseIds = caseOptionDTOS.stream().map(MinderOptionDTO::getId).toList();
if (!extCheckOwnerMapper.checkoutOwner(functionalCase, userId, caseIds)) {
throw new MSException(Translator.get(CHECK_OWNER_CASE));
}
}
return caseIds;
}
private void moveSortModule(String projectId, String userId, MinderTargetDTO moduleMinderTargetDTO, List<String> moduleIds) {
if (moduleMinderTargetDTO != null && StringUtils.isNotBlank(moduleMinderTargetDTO.getTargetId())) {
//排序
@ -403,14 +403,14 @@ public class FunctionalCaseMinderService {
finalIds.addAll(beforeIds);
finalIds.addAll(paramIds);
finalIds.addAll(afterIds);
return finalIds;
return finalIds.stream().distinct().toList();
}
private void updateSteps(FunctionalCaseMinderRemoveRequest request, List<MinderOptionDTO> resourceList) {
if (StringUtils.isNotBlank(request.getSteps())) {
List<FunctionalCaseStepDTO> functionalCaseStepDTOS = JSON.parseArray(request.getSteps(), FunctionalCaseStepDTO.class);
for (int i = 0; i < functionalCaseStepDTOS.size(); i++) {
functionalCaseStepDTOS.get(i).setNum(i + 1);
functionalCaseStepDTOS.get(i).setNum(i);
}
byte[] bytes = StringUtils.defaultIfBlank(JSON.toJSONString(functionalCaseStepDTOS), StringUtils.EMPTY).getBytes(StandardCharsets.UTF_8);
extFunctionalCaseBlobMapper.batchUpdateColumn("steps", List.of(resourceList.get(0).getId()), bytes);

View File

@ -86,12 +86,12 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
functionalCaseBlobMapper.insert(functionalCaseBlob);
FunctionalCaseBlob functionalCaseBlob6 = new FunctionalCaseBlob();
functionalCaseBlob6.setId("TEST_FUNCTIONAL_MINDER_CASE_ID_1");
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.updateByPrimaryKeyWithBLOBs(functionalCaseBlob);
functionalCaseBlob6.setSteps(JSON.toJSONString(list).getBytes(StandardCharsets.UTF_8));
functionalCaseBlob6.setTextDescription(textDescription.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob6.setExpectedResult(expectedResult.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob6.setPrerequisite(prerequisite.getBytes(StandardCharsets.UTF_8));
functionalCaseBlob6.setDescription(description.getBytes(StandardCharsets.UTF_8));
functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob6);
FunctionalCaseMindRequest request = new FunctionalCaseMindRequest();
request.setProjectId("project-case-minder-test");
@ -269,9 +269,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
functionalCaseMinderRemoveRequest.setParentTargetId(null);
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_MOVE, functionalCaseMinderRemoveRequest);
functionalCaseModule = functionalCaseModuleMapper.selectByPrimaryKey("TEST_MINDER_MODULE_ID_GYQ5");
functionalCaseMinderRemoveRequest.setSteps("[{\"id\":\"aa159262-baf9-4a11-91b9-0ab50a9f199e\",\"num\":0,\"desc\":\"点点滴滴\",\"result\":\"点点滴滴的\"},{\"id\":\"2bf16247-96a2-44c4-92c8-f620f85eb351\",\"num\":1,\"desc\":\"d d d\",\"result\":\" 得到的\"}]");
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_MOVE, functionalCaseMinderRemoveRequest);
Assertions.assertTrue(functionalCaseModule.getPos() !=0);
caseMinderTargetDTO = new MinderTargetDTO();
caseMinderTargetDTO.setTargetId("TEST_FUNCTIONAL_MINDER_CASE_ID_2");
caseMinderTargetDTO.setTargetId("TEST_FUNCTIONAL_MINDER_CASE_ID_8");
caseMinderTargetDTO.setMoveMode(MoveTypeEnum.BEFORE.name());
functionalCaseMinderRemoveRequest.setCaseMinderTargetDTO(caseMinderTargetDTO);
moduleMinderTargetDTO = new MinderTargetDTO();
@ -280,12 +282,12 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
functionalCaseMinderRemoveRequest.setModuleMinderTargetDTO(moduleMinderTargetDTO);
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_MOVE, functionalCaseMinderRemoveRequest);
functionalCaseModule = functionalCaseModuleMapper.selectByPrimaryKey("TEST_MINDER_MODULE_ID_GYQ5");
Assertions.assertTrue(functionalCaseModule.getPos()==20000);
Assertions.assertTrue(functionalCaseModule.getPos()==5000);
functionalCaseMinderRemoveRequest.setCaseMinderTargetDTO(null);
functionalCaseMinderRemoveRequest.setModuleMinderTargetDTO(null);
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_MOVE, functionalCaseMinderRemoveRequest);
functionalCaseModule = functionalCaseModuleMapper.selectByPrimaryKey("TEST_MINDER_MODULE_ID_GYQ5");
Assertions.assertTrue(functionalCaseModule.getPos()==20000);
Assertions.assertTrue(functionalCaseModule.getPos()==5000);
functionalCaseMinderRemoveRequest.setParentTargetId("TEST_MINDER_MODULE_ID_GYQ6");
this.requestPost(FUNCTIONAL_CASE_BATCH_MOVE, functionalCaseMinderRemoveRequest).andExpect(status().is5xxServerError());
resourceList = new ArrayList<>();