mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-30 19:18:59 +08:00
refactor(测试计划): 修改功能用例排序逻辑
This commit is contained in:
parent
f2a0cdde75
commit
051b3acbdd
@ -5,6 +5,9 @@ import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class BaseScheduleConfigRequest {
|
||||
@NotBlank(message = "{api_scenario.id.not_blank}")
|
||||
@ -18,4 +21,7 @@ public class BaseScheduleConfigRequest {
|
||||
@Schema(description = "Cron表达式")
|
||||
@NotBlank
|
||||
private String cron;
|
||||
|
||||
@Schema(description = "运行配置")
|
||||
private Map<String, String> runConfig = new HashMap<>();
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ 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.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()));
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ResourceSortRequest extends PosRequest {
|
||||
@Schema(description = "测试计划ID")
|
||||
@Schema(description = "测试集ID")
|
||||
@NotBlank(message = "{test_plan.id.not_blank}")
|
||||
private String testPlanId;
|
||||
private String testCollectionId;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,16 @@ package io.metersphere.plan.job;
|
||||
|
||||
import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
|
||||
import io.metersphere.plan.service.TestPlanExecuteService;
|
||||
import io.metersphere.sdk.constants.ApiBatchRunMode;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.schedule.BaseScheduleJob;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.TriggerKey;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class TestPlanScheduleJob extends BaseScheduleJob {
|
||||
|
||||
@ -16,8 +19,11 @@ public class TestPlanScheduleJob extends BaseScheduleJob {
|
||||
protected void businessExecute(JobExecutionContext context) {
|
||||
TestPlanExecuteService testPlanExecuteService = CommonBeanFactory.getBean(TestPlanExecuteService.class);
|
||||
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() {{
|
||||
this.setExecuteIds(Collections.singletonList(resourceId));
|
||||
this.setExecuteMode(runMode);
|
||||
}}, userId);
|
||||
}
|
||||
|
||||
|
@ -189,13 +189,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
||||
|
||||
public TestPlanOperationResponse sortNode(ResourceSortRequest request, LogInsertModule logInsertModule) {
|
||||
TestPlanFunctionalCase dragNode = testPlanFunctionalCaseMapper.selectByPrimaryKey(request.getMoveId());
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestPlanId());
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getTestCollectionId());
|
||||
if (dragNode == null) {
|
||||
throw new MSException(Translator.get("test_plan.drag.node.error"));
|
||||
}
|
||||
TestPlanOperationResponse response = new TestPlanOperationResponse();
|
||||
MoveNodeSortDTO sortDTO = super.getNodeSortDTO(
|
||||
request.getTestPlanId(),
|
||||
request.getTestCollectionId(),
|
||||
super.getNodeMoveRequest(request, true),
|
||||
extTestPlanFunctionalCaseMapper::selectDragInfoById,
|
||||
extTestPlanFunctionalCaseMapper::selectNodeByPosOperator
|
||||
|
@ -13,10 +13,7 @@ import io.metersphere.project.request.ProjectApplicationRequest;
|
||||
import io.metersphere.project.service.ProjectApplicationService;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.sdk.util.*;
|
||||
import io.metersphere.system.domain.ScheduleExample;
|
||||
import io.metersphere.system.domain.TestPlanModuleExample;
|
||||
import io.metersphere.system.domain.User;
|
||||
@ -753,6 +750,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
||||
.enable(request.isEnable())
|
||||
.cron(request.getCron())
|
||||
.resourceType(ScheduleResourceType.TEST_PLAN.name())
|
||||
.config(JSON.toJSONString(request.getRunConfig()))
|
||||
.build();
|
||||
|
||||
if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
|
||||
|
@ -20,58 +20,4 @@ public abstract class TestPlanSortService extends MoveNodeService {
|
||||
private static final String MOVE_POS_OPERATOR_MORE = "moreThan";
|
||||
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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -1268,7 +1268,7 @@ public class TestPlanTests extends BaseTest {
|
||||
List<TestPlanFunctionalCase> funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId());
|
||||
//将第30个移动到第一位之前
|
||||
ResourceSortRequest request = new ResourceSortRequest();
|
||||
request.setTestPlanId(repeatCaseTestPlan.getId());
|
||||
request.setTestCollectionId(repeatCaseTestPlan.getId());
|
||||
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||
request.setMoveId(funcList.get(29).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());
|
||||
//反例: 测试计划不存在
|
||||
request.setTestPlanId(IDGenerator.nextStr());
|
||||
request.setTestCollectionId(IDGenerator.nextStr());
|
||||
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().is5xxServerError());
|
||||
//反例:拖拽的节点不存在
|
||||
request.setTestPlanId(repeatCaseTestPlan.getId());
|
||||
request.setTestCollectionId(repeatCaseTestPlan.getId());
|
||||
request.setMoveId(null);
|
||||
this.requestPost(URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT, request).andExpect(status().isBadRequest());
|
||||
//反例:目标节点不存在
|
||||
|
Loading…
Reference in New Issue
Block a user