From e5518e1c30e64a6fc4cec59e31247286981fe98c Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 12 Jun 2024 16:42:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=8E=92=E5=BA=8F=E6=8E=A5=E5=8F=A3&?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8D=8F=E8=AE=AE=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TestPlanApiCaseController.java | 1 - .../TestPlanApiScenarioController.java | 8 ++++ .../TestPlanFunctionalCaseController.java | 1 - .../response/TestPlanApiCasePageResponse.java | 3 ++ .../TestPlanApiScenarioControllerTests.java | 41 +++++++++++++++++++ .../plan/controller/TestPlanTests.java | 7 ---- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java index ce1114b97c..82fb9b5761 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java @@ -57,7 +57,6 @@ public class TestPlanApiCaseController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public TestPlanOperationResponse sortNode(@Validated @RequestBody ResourceSortRequest request) { - testPlanManagementService.checkModuleIsOpen(request.getTestCollectionId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); return testPlanApiCaseService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/sort", HttpMethodConstants.POST.name())); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java index 8908af671b..c222d914e2 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java @@ -8,6 +8,7 @@ import io.metersphere.api.service.scenario.ApiScenarioReportService; import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse; import io.metersphere.plan.dto.response.TestPlanAssociationResponse; +import io.metersphere.plan.dto.response.TestPlanOperationResponse; import io.metersphere.plan.service.TestPlanApiScenarioBatchRunService; import io.metersphere.plan.service.TestPlanApiScenarioLogService; import io.metersphere.plan.service.TestPlanApiScenarioService; @@ -141,4 +142,11 @@ public class TestPlanApiScenarioController { testPlanApiScenarioService.checkReportIsTestPlan(reportId); return apiScenarioReportService.getDetail(reportId, stepId); } + + @PostMapping(value = "/sort") + @Operation(summary = "测试计划-场景用例拖拽排序") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) + public TestPlanOperationResponse sortNode(@Validated @RequestBody ResourceSortRequest request) { + return testPlanApiScenarioService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/sort", HttpMethodConstants.POST.name())); + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java index d4be9fc09b..59a08f213b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java @@ -53,7 +53,6 @@ public class TestPlanFunctionalCaseController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public TestPlanOperationResponse sortNode(@Validated @RequestBody ResourceSortRequest request) { - testPlanManagementService.checkModuleIsOpen(request.getTestCollectionId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); return testPlanFunctionalCaseService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/sort", HttpMethodConstants.POST.name())); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanApiCasePageResponse.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanApiCasePageResponse.java index cf33d64564..3bef369210 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanApiCasePageResponse.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanApiCasePageResponse.java @@ -71,4 +71,7 @@ public class TestPlanApiCasePageResponse implements Serializable { @Schema(description = "状态") private String status; + + @Schema(description = "协议") + private String protocol; } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiScenarioControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiScenarioControllerTests.java index b0eff9ef4d..4044f2d21c 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiScenarioControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiScenarioControllerTests.java @@ -19,7 +19,9 @@ import io.metersphere.api.service.scenario.ApiScenarioReportService; import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.plan.domain.TestPlanApiScenario; +import io.metersphere.plan.domain.TestPlanApiScenarioExample; import io.metersphere.plan.dto.request.*; +import io.metersphere.plan.dto.response.TestPlanOperationResponse; import io.metersphere.plan.mapper.TestPlanApiScenarioMapper; import io.metersphere.plan.service.TestPlanApiScenarioService; import io.metersphere.project.api.assertion.MsResponseCodeAssertion; @@ -34,6 +36,7 @@ import io.metersphere.sdk.dto.api.task.TaskItem; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; +import io.metersphere.system.dto.sdk.enums.MoveTypeEnum; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; @@ -66,6 +69,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest { public static final String API_SCENARIO_DISASSOCIATE = "disassociate"; public static final String API_SCENARIO_BATCH_DISASSOCIATE = "batch/disassociate"; public static final String API_SCENARIO_BATCH_UPDATE_EXECUTOR_URL = "batch/update/executor"; + private static final String URL_POST_RESOURCE_API_SCENARIO_SORT = "/sort"; @Resource private TestPlanApiScenarioService testPlanApiScenarioService; @@ -271,6 +275,43 @@ public class TestPlanApiScenarioControllerTests extends BaseTest { request.setTreeType("COLLECTION"); this.requestPostWithOkAndReturn(API_SCENARIO_TREE_COUNT, request); + this.testSort(); + } + + public void testSort() throws Exception { + TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample(); + testPlanApiScenarioExample.createCriteria().andTestPlanCollectionIdEqualTo("wxxx_collection_2"); + testPlanApiScenarioExample.setOrderByClause("pos asc"); + List scenarioList = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample); + + //最后一个移动到第一位之前 + ResourceSortRequest request = new ResourceSortRequest(); + request.setTestCollectionId("wxxx_collection_2"); + request.setProjectId("wxx_project_1234"); + request.setMoveId(scenarioList.getLast().getId()); + request.setTargetId(scenarioList.getFirst().getId()); + request.setMoveMode(MoveTypeEnum.AFTER.name()); + + MvcResult result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_SORT, request); + ResultHolder resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + TestPlanOperationResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanOperationResponse.class); + Assertions.assertEquals(response.getOperationCount(), 1); + scenarioList = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample); + Assertions.assertEquals(scenarioList.get(0).getId(), request.getMoveId()); + Assertions.assertEquals(scenarioList.get(1).getId(), request.getTargetId()); + + //将这时的第30个放到第一位之后 + request.setTargetId(scenarioList.getLast().getId()); + request.setMoveId(scenarioList.getFirst().getId()); + request.setMoveMode(MoveTypeEnum.BEFORE.name()); + result = this.requestPostWithOkAndReturn(URL_POST_RESOURCE_API_SCENARIO_SORT, request); + resultHolder = JSON.parseObject(result.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanOperationResponse.class); + Assertions.assertEquals(response.getOperationCount(), 1); + scenarioList = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample); + Assertions.assertEquals(scenarioList.get(0).getId(), request.getTargetId()); + Assertions.assertEquals(scenarioList.get(1).getId(), request.getMoveId()); + } @Test diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index f5be47d8b1..1a6685d994 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -1276,10 +1276,6 @@ public class TestPlanTests extends BaseTest { request.setTargetId(funcList.get(0).getId()); request.setMoveMode(MoveTypeEnum.AFTER.name()); - - //先测试一下没有开启模块时能否使用 - testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "caseManagement"); - this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError()); //恢复 testPlanTestService.resetProjectModule(project, PROJECT_MODULE); @@ -1329,9 +1325,6 @@ public class TestPlanTests extends BaseTest { //反例:测试计划为空 request.setTestCollectionId(null); this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest()); - //反例: 测试计划不存在 - request.setTestCollectionId(IDGenerator.nextStr()); - this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError()); //反例:拖拽的节点不存在 request.setTestCollectionId(repeatCaseTestPlan.getId()); request.setMoveId(null);