From df335e5f89aa731e26be6adf17b3d3578fc0985e Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 19 Jun 2024 11:00:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E8=84=91=E5=9B=BE=E4=BF=9D=E5=AD=98=E6=A0=B9=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FunctionalCaseMinderService.java | 16 ++--- .../FunctionalCaseMinderControllerTest.java | 15 ++-- .../TestPlanCollectionMinderService.java | 51 ++++++++----- ...stPlanCollectionMinderControllerTests.java | 71 +++++++++++++++++-- 4 files changed, 116 insertions(+), 37 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 487ee5b6e8..05db29d23c 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 @@ -621,16 +621,16 @@ public class FunctionalCaseMinderService { FunctionalCase functionalCase = addCase(request, userId, functionalCaseChangeRequest, caseMapper, sourceIdAndInsertModuleIdMap); String caseId = functionalCase.getId(); sourceIdAndInsertCaseIdMap.put(functionalCaseChangeRequest.getId(), caseId); - //保存用例等级 - FunctionalCaseCustomField customField = new FunctionalCaseCustomField(); - customField.setCaseId(caseId); - customField.setFieldId(defaultCustomFieldValueMap.get("priorityFieldId").toString()); - customField.setValue("P"+functionalCaseChangeRequest.getPriority()); - caseCustomFieldMapper.insertSelective(customField); //附属表 FunctionalCaseBlob functionalCaseBlob = addCaseBlob(functionalCaseChangeRequest, caseId, caseBlobMapper); //保存自定义字段 List functionalCaseCustomFields = addCustomFields(functionalCaseChangeRequest, caseId, caseCustomFieldMapper, defaultCustomFieldValueMap); + //保存用例等级 + FunctionalCaseCustomField customField = new FunctionalCaseCustomField(); + customField.setCaseId(caseId); + customField.setFieldId(defaultCustomFieldValueMap.get("priorityFieldId").toString()); + customField.setValue("P"+(functionalCaseChangeRequest.getPriority()-1)); + caseCustomFieldMapper.insertSelective(customField); //日志 FunctionalCaseHistoryLogDTO historyLogDTO = new FunctionalCaseHistoryLogDTO(functionalCase, functionalCaseBlob, functionalCaseCustomFields, new ArrayList<>(), new ArrayList<>()); LogDTO logDTO = addLog(request, userId, caseId, historyLogDTO, null); @@ -668,7 +668,7 @@ public class FunctionalCaseMinderService { FunctionalCaseCustomField customField = new FunctionalCaseCustomField(); customField.setCaseId(caseId); customField.setFieldId(defaultCustomFieldValueMap.get("priorityFieldId").toString()); - customField.setValue("P"+functionalCaseChangeRequest.getPriority()); + customField.setValue("P"+(functionalCaseChangeRequest.getPriority()-1)); caseCustomFieldMapper.updateByPrimaryKeySelective(customField); //日志 FunctionalCaseHistoryLogDTO historyLogDTO = new FunctionalCaseHistoryLogDTO(functionalCase, functionalCaseBlob, oldCaseCustomFieldMap.get(caseId), new ArrayList<>(), new ArrayList<>()); @@ -1060,7 +1060,7 @@ public class FunctionalCaseMinderService { List list = customFields.stream().map(CaseCustomFieldDTO::getFieldId).toList(); List customFieldDTOs = new ArrayList<>(); defaultValueMap.forEach((k, v) -> { - if (!list.contains(k)) { + if (!list.contains(k) && !StringUtils.equalsIgnoreCase(k,"priorityFieldId")) { CaseCustomFieldDTO customFieldDTO = new CaseCustomFieldDTO(); customFieldDTO.setFieldId(k); customFieldDTO.setValue(v.toString()); 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 4b46d04274..a97ceaa3b5 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 @@ -5,10 +5,7 @@ import io.metersphere.functional.dto.CaseCustomFieldDTO; import io.metersphere.functional.dto.FunctionalCaseStepDTO; import io.metersphere.functional.dto.FunctionalMinderTreeDTO; import io.metersphere.functional.dto.MinderOptionDTO; -import io.metersphere.functional.mapper.FunctionalCaseBlobMapper; -import io.metersphere.functional.mapper.FunctionalCaseMapper; -import io.metersphere.functional.mapper.FunctionalCaseModuleMapper; -import io.metersphere.functional.mapper.MindAdditionalNodeMapper; +import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.*; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; @@ -58,6 +55,8 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { private FunctionalCaseModuleMapper functionalCaseModuleMapper; @Resource private MindAdditionalNodeMapper mindAdditionalNodeMapper; + @Resource + private FunctionalCaseCustomFieldMapper functionalCaseCustomFieldMapper; @Test @Order(1) @@ -165,7 +164,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { caseChangeRequest.setName("新增用例"); caseChangeRequest.setModuleId("TEST_MINDER_MODULE_ID_GYQ2"); caseChangeRequest.setMoveMode("AFTER"); - caseChangeRequest.setPriority(2); + caseChangeRequest.setPriority(3); caseChangeRequest.setTargetId("TEST_FUNCTIONAL_MINDER_CASE_ID_3"); caseChangeRequest.setTemplateId("100001"); caseChangeRequest.setType("ADD"); @@ -183,7 +182,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { caseChangeRequest.setName("TEST_MINDER_MODULE_ID_GYQ_更新"); caseChangeRequest.setModuleId("TEST_MINDER_MODULE_ID_GYQ"); caseChangeRequest.setTemplateId("100001"); - caseChangeRequest.setPriority(2); + caseChangeRequest.setPriority(3); caseChangeRequest.setMoveMode("BEFORE"); caseChangeRequest.setTargetId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); caseChangeRequest.setType("UPDATE"); @@ -251,6 +250,10 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalCases)); Assertions.assertTrue(functionalCases.get(0).getPos() > 0L); + FunctionalCaseCustomFieldExample customFieldExample = new FunctionalCaseCustomFieldExample(); + customFieldExample.createCriteria().andCaseIdEqualTo(functionalCases.get(0).getId()).andFieldIdEqualTo("custom_field_minder_gyq_id_3"); + List functionalCaseCustomFields = functionalCaseCustomFieldMapper.selectByExample(customFieldExample); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(functionalCaseCustomFields.get(0).getValue(),"P2")); FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andNameEqualTo("新增9"); List functionalCaseModules = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java index d3dc3d7ce4..ef978a912b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java @@ -284,13 +284,14 @@ public class TestPlanCollectionMinderService { } private Map> dealUpdateList(TestPlanCollectionMinderEditRequest request, String userId, Map> associateMap, Map> parentMap, TestPlanCollectionMapper collectionMapper) { - List updateList = request.getEditList().stream().filter(t -> StringUtils.isNotBlank(t.getId()) && t.getLevel() == 2).toList(); + List updateList = request.getEditList().stream().filter(t -> StringUtils.isNotBlank(t.getId())).toList(); Map> typeNamesMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(updateList)) { //处理删除 deleteCollection(updateList, request.getPlanId()); //处理更新 - for (TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO : updateList) { + List collect = updateList.stream().filter(t -> t.getLevel() == 2).toList(); + for (TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO : collect) { TestPlanCollection testPlanCollection = updateCollection(request, userId, testPlanCollectionMinderEditDTO, parentMap, collectionMapper); checkChangeDataRepeat(typeNamesMap, testPlanCollection); setAssociateMap(testPlanCollectionMinderEditDTO, associateMap, testPlanCollection); @@ -340,26 +341,35 @@ public class TestPlanCollectionMinderService { @NotNull private Map> getParentMap(TestPlanCollectionMinderEditRequest request) { - TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample(); - testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andParentIdEqualTo(ModuleConstants.ROOT_NODE_PARENT_ID); - List testPlanCollections = testPlanCollectionMapper.selectByExample(testPlanCollectionExample); - return testPlanCollections.stream().collect(Collectors.groupingBy(TestPlanCollection::getType)); + List list = request.getEditList().stream().filter(t -> StringUtils.isNotBlank(t.getId()) && t.getLevel() == 1).toList(); + ListparentList = new ArrayList<>(); + for (TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO : list) { + TestPlanCollection testPlanCollection = new TestPlanCollection(); + BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO); + parentList.add(testPlanCollection); + } + return parentList.stream().collect(Collectors.groupingBy(TestPlanCollection::getType)); } @NotNull private static TestPlanCollection updateCollection(TestPlanCollectionMinderEditRequest request, String userId, TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO, Map> parentMap, TestPlanCollectionMapper collectionMapper) { TestPlanCollection testPlanCollection = new TestPlanCollection(); - BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO); - testPlanCollection.setId(testPlanCollectionMinderEditDTO.getId()); - testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText()); - testPlanCollection.setTestPlanId(request.getPlanId()); - testPlanCollection.setType(testPlanCollectionMinderEditDTO.getType()); + TestPlanCollection parent = parentMap.get(testPlanCollectionMinderEditDTO.getType()).get(0); if (StringUtils.equalsIgnoreCase(parent.getId(), testPlanCollectionMinderEditDTO.getId())) { testPlanCollection.setParentId(parent.getParentId()); } else { testPlanCollection.setParentId(parent.getId()); } + if (testPlanCollectionMinderEditDTO.getExtended()) { + BeanUtils.copyBean(testPlanCollection, parent); + } else { + BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO); + } + testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText()); + testPlanCollection.setTestPlanId(request.getPlanId()); + testPlanCollection.setType(testPlanCollectionMinderEditDTO.getType()); + testPlanCollection.setId(testPlanCollectionMinderEditDTO.getId()); testPlanCollection.setCreateUser(userId); testPlanCollection.setCreateTime(null); testPlanCollection.setPos(testPlanCollectionMinderEditDTO.getNum()); @@ -369,19 +379,24 @@ public class TestPlanCollectionMinderService { @NotNull private static TestPlanCollection addCollection(TestPlanCollectionMinderEditRequest request, String userId, TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO, Map> parentMap, TestPlanCollectionMapper collectionMapper) { - TestPlanCollection testPlanCollection = new TestPlanCollection(); - BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO); - testPlanCollection.setId(IDGenerator.nextStr()); - testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText()); - testPlanCollection.setTestPlanId(request.getPlanId()); - testPlanCollection.setType(testPlanCollectionMinderEditDTO.getType()); List testPlanCollections = parentMap.get(testPlanCollectionMinderEditDTO.getType()); + TestPlanCollection parent = null; + TestPlanCollection testPlanCollection = new TestPlanCollection(); + testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText()); if (CollectionUtils.isNotEmpty(testPlanCollections)) { - TestPlanCollection parent = testPlanCollections.get(0); + parent = testPlanCollections.get(0); testPlanCollection.setParentId(parent.getId()); } else { testPlanCollection.setParentId(CommonConstants.DEFAULT_NULL_VALUE); } + if (testPlanCollectionMinderEditDTO.getExtended() && parent!=null) { + BeanUtils.copyBean(testPlanCollection, parent); + } else { + BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO); + } + testPlanCollection.setId(IDGenerator.nextStr()); + testPlanCollection.setTestPlanId(request.getPlanId()); + testPlanCollection.setType(testPlanCollectionMinderEditDTO.getType()); testPlanCollection.setCreateUser(userId); testPlanCollection.setCreateTime(System.currentTimeMillis()); testPlanCollection.setPos(testPlanCollectionMinderEditDTO.getNum()); diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java index 3848394489..77c9776055 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java @@ -59,6 +59,60 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { void editMind() throws Exception { TestPlanCollectionMinderEditRequest request = new TestPlanCollectionMinderEditRequest(); request.setPlanId("gyq_plan_1"); + List parentList = new ArrayList<>(); + TestPlanCollectionMinderEditDTO funcParent = new TestPlanCollectionMinderEditDTO(); + funcParent.setId("gyq_wxxx_2"); + funcParent.setText("功能用例"); + funcParent.setNum(2L); + funcParent.setExecuteMethod("PARALLEL"); + funcParent.setType("FUNCTIONAL"); + funcParent.setExtended(false); + funcParent.setGrouped(false); + funcParent.setLevel(1); + funcParent.setEnvironmentId("gyq_123"); + funcParent.setTestResourcePoolId("gyq_123_pool"); + funcParent.setRetryOnFail(true); + funcParent.setRetryType("SCENARIO"); + funcParent.setRetryTimes(5); + funcParent.setRetryInterval(1000); + funcParent.setStopOnFail(true); + parentList.add(funcParent); + TestPlanCollectionMinderEditDTO apiParent = new TestPlanCollectionMinderEditDTO(); + apiParent.setId("gyq_wxxx_1"); + apiParent.setText("接口用例"); + apiParent.setNum(1L); + apiParent.setExecuteMethod("PARALLEL"); + apiParent.setType("API"); + apiParent.setExtended(false); + apiParent.setGrouped(false); + apiParent.setLevel(1); + apiParent.setEnvironmentId("NONE"); + apiParent.setTestResourcePoolId("gyq_123_pool"); + apiParent.setRetryOnFail(true); + apiParent.setRetryType("SCENARIO"); + apiParent.setRetryTimes(5); + apiParent.setRetryInterval(1000); + apiParent.setStopOnFail(true); + parentList.add(apiParent); + + TestPlanCollectionMinderEditDTO scenarioParent = new TestPlanCollectionMinderEditDTO(); + scenarioParent.setId("gyq_wxxx_3"); + scenarioParent.setText("场景用例"); + scenarioParent.setNum(3L); + scenarioParent.setExecuteMethod("PARALLEL"); + scenarioParent.setType("SCENARIO"); + scenarioParent.setExtended(false); + scenarioParent.setGrouped(false); + scenarioParent.setLevel(1); + scenarioParent.setEnvironmentId("NONE"); + scenarioParent.setTestResourcePoolId("gyq_123_pool"); + scenarioParent.setRetryOnFail(true); + scenarioParent.setRetryType("SCENARIO"); + scenarioParent.setRetryTimes(6); + scenarioParent.setRetryInterval(1000); + scenarioParent.setStopOnFail(true); + parentList.add(scenarioParent); + List editList = new ArrayList<>(); TestPlanCollectionMinderEditDTO deleteDTO = new TestPlanCollectionMinderEditDTO(); TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO = new TestPlanCollectionMinderEditDTO(); @@ -67,7 +121,7 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { testPlanCollectionMinderEditDTO.setNum(500L); testPlanCollectionMinderEditDTO.setExecuteMethod("PARALLEL"); testPlanCollectionMinderEditDTO.setType("API"); - testPlanCollectionMinderEditDTO.setExtended(false); + testPlanCollectionMinderEditDTO.setExtended(true); testPlanCollectionMinderEditDTO.setGrouped(false); testPlanCollectionMinderEditDTO.setLevel(2); testPlanCollectionMinderEditDTO.setEnvironmentId("gyq_123"); @@ -85,12 +139,19 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { testPlanCollectionMinderEditDTO.setAssociateDTOS(associateDTOS); deleteDTO = testPlanCollectionMinderEditDTO; editList.add(testPlanCollectionMinderEditDTO); + editList.addAll(parentList); request.setEditList(editList); this.requestPostWithOkAndReturn(EDIT_MIND, request); - + TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample(); + testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo("gyq_plan_1"); + List testPlanCollections1 = testPlanCollectionMapper.selectByExample(testPlanCollectionExample); + Assertions.assertEquals(4, testPlanCollections1.size()); TestPlanCollection testPlanCollection = testPlanCollectionMapper.selectByPrimaryKey("gyq_wxxx_4"); Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getName(),"更新名称")); + + Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getEnvironmentId(),"NONE")); editList = new ArrayList<>(); + editList.addAll(parentList); testPlanCollectionMinderEditDTO = new TestPlanCollectionMinderEditDTO(); testPlanCollectionMinderEditDTO.setId(null); testPlanCollectionMinderEditDTO.setText("新建名称"); @@ -116,11 +177,11 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { editList.add(testPlanCollectionMinderEditDTO); request.setEditList(editList); this.requestPostWithOkAndReturn(EDIT_MIND, request); - TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample(); + testPlanCollectionExample = new TestPlanCollectionExample(); testPlanCollectionExample.createCriteria().andNameEqualTo("新建名称"); List testPlanCollections = testPlanCollectionMapper.selectByExample(testPlanCollectionExample); Assertions.assertTrue(CollectionUtils.isNotEmpty(testPlanCollections)); - editList = new ArrayList<>(); + editList = new ArrayList<>(parentList); editList.add(deleteDTO); editList.add(deleteDTO); request.setEditList(editList); @@ -145,7 +206,7 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { testPlanCollectionMinderEditDTO.setRetryTimes(5); testPlanCollectionMinderEditDTO.setRetryInterval(1000); testPlanCollectionMinderEditDTO.setStopOnFail(true); - editList = new ArrayList<>(); + editList = new ArrayList<>(parentList); editList.add(testPlanCollectionMinderEditDTO); request.setEditList(editList); this.requestPostWithOkAndReturn(EDIT_MIND, request);