refactor(测试计划): 修改功能用例排序逻辑

This commit is contained in:
Jianguo-Genius 2024-06-06 14:19:49 +08:00 committed by 建国
parent f2a0cdde75
commit 051b3acbdd
8 changed files with 23 additions and 67 deletions

View File

@ -5,6 +5,9 @@ import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data @Data
public class BaseScheduleConfigRequest { public class BaseScheduleConfigRequest {
@NotBlank(message = "{api_scenario.id.not_blank}") @NotBlank(message = "{api_scenario.id.not_blank}")
@ -18,4 +21,7 @@ public class BaseScheduleConfigRequest {
@Schema(description = "Cron表达式") @Schema(description = "Cron表达式")
@NotBlank @NotBlank
private String cron; private String cron;
@Schema(description = "运行配置")
private Map<String, String> runConfig = new HashMap<>();
} }

View File

@ -53,7 +53,7 @@ public class TestPlanFunctionalCaseController {
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE)
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public TestPlanOperationResponse sortNode(@Validated @RequestBody ResourceSortRequest request) { public TestPlanOperationResponse sortNode(@Validated @RequestBody ResourceSortRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); 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())); return testPlanFunctionalCaseService.sortNode(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/sort", HttpMethodConstants.POST.name()));
} }

View File

@ -7,8 +7,8 @@ import lombok.Data;
@Data @Data
public class ResourceSortRequest extends PosRequest { public class ResourceSortRequest extends PosRequest {
@Schema(description = "测试计划ID") @Schema(description = "测试ID")
@NotBlank(message = "{test_plan.id.not_blank}") @NotBlank(message = "{test_plan.id.not_blank}")
private String testPlanId; private String testCollectionId;
} }

View File

@ -2,13 +2,16 @@ package io.metersphere.plan.job;
import io.metersphere.plan.dto.request.TestPlanExecuteRequest; import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
import io.metersphere.plan.service.TestPlanExecuteService; import io.metersphere.plan.service.TestPlanExecuteService;
import io.metersphere.sdk.constants.ApiBatchRunMode;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.schedule.BaseScheduleJob; import io.metersphere.system.schedule.BaseScheduleJob;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
public class TestPlanScheduleJob extends BaseScheduleJob { public class TestPlanScheduleJob extends BaseScheduleJob {
@ -16,8 +19,11 @@ public class TestPlanScheduleJob extends BaseScheduleJob {
protected void businessExecute(JobExecutionContext context) { protected void businessExecute(JobExecutionContext context) {
TestPlanExecuteService testPlanExecuteService = CommonBeanFactory.getBean(TestPlanExecuteService.class); TestPlanExecuteService testPlanExecuteService = CommonBeanFactory.getBean(TestPlanExecuteService.class);
assert testPlanExecuteService != null; assert testPlanExecuteService != null;
Map<String, String> runConfig = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), Map.class);
String runMode = runConfig.containsKey("runMode") ? runConfig.get("runMode") : ApiBatchRunMode.SERIAL.name();
testPlanExecuteService.execute(new TestPlanExecuteRequest() {{ testPlanExecuteService.execute(new TestPlanExecuteRequest() {{
this.setExecuteIds(Collections.singletonList(resourceId)); this.setExecuteIds(Collections.singletonList(resourceId));
this.setExecuteMode(runMode);
}}, userId); }}, userId);
} }

View File

@ -189,13 +189,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public TestPlanOperationResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) { public TestPlanOperationResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) {
TestPlanFunctionalCase dragNode = testPlanFunctionalCaseMapper.selectByPrimaryKey(request.getMoveId()); TestPlanFunctionalCase dragNode = testPlanFunctionalCaseMapper.selectByPrimaryKey(request.getMoveId());
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId()); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestCollectionId());
if (dragNode == null) { if (dragNode == null) {
throw new MSException(Translator.get("test_plan.drag.node.error")); throw new MSException(Translator.get("test_plan.drag.node.error"));
} }
TestPlanOperationResponse response = new TestPlanOperationResponse(); TestPlanOperationResponse response = new TestPlanOperationResponse();
MoveNodeSortDTO sortDTO = super.getNodeSortDTO( MoveNodeSortDTO sortDTO = super.getNodeSortDTO(
request.getTestPlanId(), request.getTestCollectionId(),
super.getNodeMoveRequest(request, true), super.getNodeMoveRequest(request, true),
extTestPlanFunctionalCaseMapper::selectDragInfoById, extTestPlanFunctionalCaseMapper::selectDragInfoById,
extTestPlanFunctionalCaseMapper::selectNodeByPosOperator extTestPlanFunctionalCaseMapper::selectNodeByPosOperator

View File

@ -13,10 +13,7 @@ import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.*;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.domain.ScheduleExample;
import io.metersphere.system.domain.TestPlanModuleExample; import io.metersphere.system.domain.TestPlanModuleExample;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
@ -753,6 +750,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
.enable(request.isEnable()) .enable(request.isEnable())
.cron(request.getCron()) .cron(request.getCron())
.resourceType(ScheduleResourceType.TEST_PLAN.name()) .resourceType(ScheduleResourceType.TEST_PLAN.name())
.config(JSON.toJSONString(request.getRunConfig()))
.build(); .build();
if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {

View File

@ -20,58 +20,4 @@ public abstract class TestPlanSortService extends MoveNodeService {
private static final String MOVE_POS_OPERATOR_MORE = "moreThan"; private static final String MOVE_POS_OPERATOR_MORE = "moreThan";
private static final String DRAG_NODE_NOT_EXIST = "drag_node.not.exist"; private static final String DRAG_NODE_NOT_EXIST = "drag_node.not.exist";
/**
* 构建节点排序的参数
*
* @param request 拖拽的前端请求参数
* @param selectIdNodeFunc 通过id查询节点的函数
* @param selectPosNodeFunc 通过parentId和pos运算符查询节点的函数
* @return
*/
// public MoveNodeSortDTO getNodeSortDTO(NodeMoveRequest request, String testPlanId, Function<String, DropNode> selectIdNodeFunc, Function<NodeSortQueryParam, DropNode> selectPosNodeFunc) {
//
//
// if (StringUtils.equals(request.getDragNodeId(), request.getDropNodeId())) {
// //两种节点不能一样
// throw new MSException(Translator.get("invalid_parameter") + ": drag node and drop node");
// }
//
// DropNode dragNode = selectIdNodeFunc.apply(request.getDragNodeId());
// if (dragNode == null) {
// throw new MSException(Translator.get(DRAG_NODE_NOT_EXIST) + ":" + request.getDragNodeId());
// }
//
// DropNode dropNode = selectIdNodeFunc.apply(request.getDropNodeId());
// if (dropNode == null) {
// throw new MSException(Translator.get(DRAG_NODE_NOT_EXIST) + ":" + request.getDropNodeId());
// }
//
// DropNode previousNode;
// DropNode nextNode;
//
// if (request.getDropPosition() == 1) {
// //dropPosition=1: 放到dropNode节点后原dropNode后面的节点之前
// previousNode = dropNode;
//
// NodeSortQueryParam sortParam = new NodeSortQueryParam();
// sortParam.setParentId(testPlanId);
// sortParam.setPos(previousNode.getPos());
// sortParam.setOperator(MOVE_POS_OPERATOR_MORE);
// nextNode = selectPosNodeFunc.apply(sortParam);
// } else if (request.getDropPosition() == -1) {
// //dropPosition=-1: 放到dropNode节点前原dropNode前面的节点之后
// nextNode = dropNode;
// NodeSortQueryParam sortParam = new NodeSortQueryParam();
// sortParam.setPos(nextNode.getPos());
// sortParam.setParentId(testPlanId);
// sortParam.setOperator(MOVE_POS_OPERATOR_LESS);
// previousNode = selectPosNodeFunc.apply(sortParam);
// } else {
// throw new MSException(Translator.get("invalid_parameter") + ": dropPosition");
// }
// return new MoveNodeSortDTO(testPlanId, dragNode, previousNode, nextNode);
// }
} }

View File

@ -1268,7 +1268,7 @@ public class TestPlanTests extends BaseTest {
List<TestPlanFunctionalCase> funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId()); List<TestPlanFunctionalCase> funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId());
//将第30个移动到第一位之前 //将第30个移动到第一位之前
ResourceSortRequest request = new ResourceSortRequest(); ResourceSortRequest request = new ResourceSortRequest();
request.setTestPlanId(repeatCaseTestPlan.getId()); request.setTestCollectionId(repeatCaseTestPlan.getId());
request.setProjectId(DEFAULT_PROJECT_ID); request.setProjectId(DEFAULT_PROJECT_ID);
request.setMoveId(funcList.get(29).getId()); request.setMoveId(funcList.get(29).getId());
request.setTargetId(funcList.get(0).getId()); request.setTargetId(funcList.get(0).getId());
@ -1325,13 +1325,13 @@ public class TestPlanTests extends BaseTest {
); );
//反例测试计划为空 //反例测试计划为空
request.setTestPlanId(null); request.setTestCollectionId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest()); this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest());
//反例 测试计划不存在 //反例 测试计划不存在
request.setTestPlanId(IDGenerator.nextStr()); request.setTestCollectionId(IDGenerator.nextStr());
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError()); this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
//反例拖拽的节点不存在 //反例拖拽的节点不存在
request.setTestPlanId(repeatCaseTestPlan.getId()); request.setTestCollectionId(repeatCaseTestPlan.getId());
request.setMoveId(null); request.setMoveId(null);
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest()); this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest());
//反例目标节点不存在 //反例目标节点不存在