refactor(测试计划): 创建计划并关联用例

This commit is contained in:
WangXu10 2024-05-07 11:09:04 +08:00 committed by Craftsman
parent 0c3e9bcd36
commit 6421d1ebf0
6 changed files with 111 additions and 24 deletions

View File

@ -111,23 +111,4 @@ public class TestPlanController {
} }
//todo 关注测试计划接口
//todo 取消关注测试计划接口
/*
todo 归档测试计划
·归档时要确定测试计划是完成状态
·归档时所有数据要备份一套新的包括各种用例的基本信息
·关于环境但是在查看归档内容的时候所属环境展示什么只展示名字吗
·关于用例那么是要在测试计划里能查看到用例的具体信息吗 不归档的测试计划能查看吗
·功能用例里涉及到评审相关的也要备份吗
·功能用例里关联的其他自动化用例信息也要备份吗
·缺陷的整个流转过程也是要备份吗
·关于报告
·备份到什么程度还需要在报告列表中展示这些报告吗
·每个用例调试出来的报告要备份吗全部都备份
·执行记录呢也要完全备份吗
·归档的测试计划从哪里看在测试计划列表中混合着展示吗还是提供一个单独的按钮/页面/模块单独展示这些归档了的东西
*/
} }

View File

@ -0,0 +1,43 @@
package io.metersphere.plan.dto.request;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author wx
*/
@Data
public class BaseAssociateCaseRequest extends TableBatchProcessDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "模块id")
private List<String> moduleIds;
/*@Schema(description = "类型:项目/测试计划/用例评审", allowableValues = {"PROJECT", "TEST_PLAN", "CASE_REVIEW"})
private String associateType;
@Schema(description = "类型id: 项目id/测试计划id/用例评审id")
private String associateTypeId;
@Schema(description = "用例类型: 功能用例/接口用例/接口场景用例", allowableValues = {"FUNCTIONAL", "API", "API_SCENARIO"})
private List<String> associateCaseType;*/
@Schema(description = "功能用例选中的ids")
private List<String> functionalSelectIds;
@Schema(description = "接口API用例选中的ids")
private List<String> apiSelectIds;
@Schema(description = "接口CASE选中的ids")
private List<String> apiCaseSelectIds;
@Schema(description = "接口场景用例选中的ids")
private List<String> apiScenarioSelectIds;
}

View File

@ -74,4 +74,7 @@ public class TestPlanCreateRequest {
public boolean isGroupOption() { public boolean isGroupOption() {
return StringUtils.equals(this.type, TestPlanConstants.TEST_PLAN_TYPE_GROUP) || !StringUtils.equals(this.groupId, TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID); return StringUtils.equals(this.type, TestPlanConstants.TEST_PLAN_TYPE_GROUP) || !StringUtils.equals(this.groupId, TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID);
} }
@Schema(description = "查询用例的条件")
private BaseAssociateCaseRequest baseAssociateCaseRequest;
} }

View File

@ -20,6 +20,7 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.uid.NumGenerator;
import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -59,7 +60,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
if (maxPos == null) { if (maxPos == null) {
return 0; return 0;
} else { } else {
return maxPos + DEFAULT_NODE_INTERVAL_POS; return maxPos + ServiceUtils.POS_STEP;
} }
} }
@ -89,7 +90,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
this::saveTestPlanResource); this::saveTestPlanResource);
} }
private void saveTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) { public void saveTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) {
long pox = this.getNextOrder(associationParam.getTestPlanId()); long pox = this.getNextOrder(associationParam.getTestPlanId());
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
List<TestPlanFunctionalCase> testPlanFunctionalCaseList = new ArrayList<>(); List<TestPlanFunctionalCase> testPlanFunctionalCaseList = new ArrayList<>();
@ -100,11 +101,12 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
testPlanFunctionalCase.setNum(NumGenerator.nextNum(associationParam.getTestPlanNum() + "_" + associationParam.getProjectId(), ApplicationNumScope.TEST_PLAN_FUNCTION_CASE)); testPlanFunctionalCase.setNum(NumGenerator.nextNum(associationParam.getTestPlanNum() + "_" + associationParam.getProjectId(), ApplicationNumScope.TEST_PLAN_FUNCTION_CASE));
testPlanFunctionalCase.setTestPlanId(associationParam.getTestPlanId()); testPlanFunctionalCase.setTestPlanId(associationParam.getTestPlanId());
testPlanFunctionalCase.setFunctionalCaseId(associationIdList.get(i)); testPlanFunctionalCase.setFunctionalCaseId(associationIdList.get(i));
testPlanFunctionalCase.setPos(pox + (i + 1) * DEFAULT_NODE_INTERVAL_POS); testPlanFunctionalCase.setPos(pox);
testPlanFunctionalCase.setCreateTime(now); testPlanFunctionalCase.setCreateTime(now);
testPlanFunctionalCase.setCreateUser(associationParam.getOperator()); testPlanFunctionalCase.setCreateUser(associationParam.getOperator());
testPlanFunctionalCase.setExecuteUser(associationParam.getOperator()); testPlanFunctionalCase.setExecuteUser(associationParam.getOperator());
testPlanFunctionalCaseList.add(testPlanFunctionalCase); testPlanFunctionalCaseList.add(testPlanFunctionalCase);
pox += ServiceUtils.POS_STEP;
} }
testPlanFunctionalCaseMapper.batchInsert(testPlanFunctionalCaseList); testPlanFunctionalCaseMapper.batchInsert(testPlanFunctionalCaseList);
} }

View File

@ -1,6 +1,7 @@
package io.metersphere.plan.service; package io.metersphere.plan.service;
import io.metersphere.plan.domain.*; import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.TestPlanBatchProcessRequest; import io.metersphere.plan.dto.request.TestPlanBatchProcessRequest;
import io.metersphere.plan.dto.request.TestPlanCreateRequest; import io.metersphere.plan.dto.request.TestPlanCreateRequest;
import io.metersphere.plan.dto.request.TestPlanUpdateRequest; import io.metersphere.plan.dto.request.TestPlanUpdateRequest;
@ -108,12 +109,39 @@ public class TestPlanService {
testPlanXPackFactory.getTestPlanGroupService().validateGroup(createTestPlan, testPlanConfig); testPlanXPackFactory.getTestPlanGroupService().validateGroup(createTestPlan, testPlanConfig);
} }
handleAssociateCase(testPlanCreateRequest, createTestPlan);
testPlanMapper.insert(createTestPlan); testPlanMapper.insert(createTestPlan);
testPlanConfigMapper.insert(testPlanConfig); testPlanConfigMapper.insert(testPlanConfig);
testPlanLogService.saveAddLog(createTestPlan, operator, requestUrl, requestMethod); testPlanLogService.saveAddLog(createTestPlan, operator, requestUrl, requestMethod);
return createTestPlan.getId(); return createTestPlan.getId();
} }
/**
* 处理关联的用例
*
* @param request
* @return
*/
private void handleAssociateCase(TestPlanCreateRequest request, TestPlan testPlan) {
//关联的功能用例
handleFunctionalCase(request.getBaseAssociateCaseRequest().getFunctionalSelectIds(), testPlan);
//TODO 关联接口用例/接口场景用例
}
/**
* 关联的功能用例
*
* @param functionalSelectIds
*/
private void handleFunctionalCase(List<String> functionalSelectIds, TestPlan testPlan) {
if (CollectionUtils.isNotEmpty(functionalSelectIds)) {
TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(functionalSelectIds, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), testPlan.getCreateUser());
testPlanFunctionCaseService.saveTestPlanResource(associationParam);
}
}
private void validateTestPlan(TestPlan testPlan) { private void validateTestPlan(TestPlan testPlan) {
TestPlanExample example = new TestPlanExample(); TestPlanExample example = new TestPlanExample();
if (StringUtils.isBlank(testPlan.getId())) { if (StringUtils.isBlank(testPlan.getId())) {

View File

@ -513,6 +513,8 @@ public class TestPlanTests extends BaseTest {
request.setProjectId(project.getId()); request.setProjectId(project.getId());
request.setTestPlanning(false); request.setTestPlanning(false);
BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest();
request.setBaseAssociateCaseRequest(associateCaseRequest);
for (int i = 0; i < 999; i++) { for (int i = 0; i < 999; i++) {
String moduleId; String moduleId;
if (i < 50) { if (i < 50) {
@ -602,6 +604,7 @@ public class TestPlanTests extends BaseTest {
itemRequest.setModuleId(a1Node.getId()); itemRequest.setModuleId(a1Node.getId());
itemRequest.setGroupId(groupTestPlanId7); itemRequest.setGroupId(groupTestPlanId7);
itemRequest.setName("testPlan_group7_" + i); itemRequest.setName("testPlan_group7_" + i);
itemRequest.setBaseAssociateCaseRequest(associateCaseRequest);
if (i == 0) { if (i == 0) {
//测试项目没有开启测试计划模块时能否使用 //测试项目没有开启测试计划模块时能否使用
testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan"); testPlanTestService.removeProjectModule(project, PROJECT_MODULE, "testPlan");
@ -1078,8 +1081,8 @@ public class TestPlanTests extends BaseTest {
TestPlanResourceSortResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class); TestPlanResourceSortResponse response = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), TestPlanResourceSortResponse.class);
Assertions.assertEquals(response.getSortNodeNum(), 1); Assertions.assertEquals(response.getSortNodeNum(), 1);
funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId()); funcList = testPlanTestService.selectTestPlanFunctionalCaseByTestPlanId(repeatCaseTestPlan.getId());
Assertions.assertEquals(funcList.get(0).getId(), request.getDragNodeId()); Assertions.assertEquals(funcList.get(0).getId(), request.getDropNodeId());
Assertions.assertEquals(funcList.get(1).getId(), request.getDropNodeId()); Assertions.assertEquals(funcList.get(1).getId(), request.getDragNodeId());
LOG_CHECK_LIST.add( LOG_CHECK_LIST.add(
new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT) new CheckLogModel(request.getDragNodeId(), OperationLogType.UPDATE, URL_POST_RESOURCE_FUNCTIONAL_CASE_SORT)
); );
@ -2051,4 +2054,31 @@ public class TestPlanTests extends BaseTest {
ResultHolder editResultHolder = JSON.parseObject(editReturnData, ResultHolder.class); ResultHolder editResultHolder = JSON.parseObject(editReturnData, ResultHolder.class);
Assertions.assertNotNull(editResultHolder); Assertions.assertNotNull(editResultHolder);
} }
@Test
@Order(301)
public void testAdd() throws Exception {
TestPlanCreateRequest request = new TestPlanCreateRequest();
request.setProjectId(project.getId());
request.setTestPlanning(false);
BaseAssociateCaseRequest associateCaseRequest = new BaseAssociateCaseRequest();
associateCaseRequest.setFunctionalSelectIds(Arrays.asList("wx_fc_1", "wx_fc_2"));
request.setBaseAssociateCaseRequest(associateCaseRequest);
request.setName("测试一下关联");
request.setPlannedEndTime(null);
request.setPlannedStartTime(null);
request.setRepeatCase(false);
request.setAutomaticStatusUpdate(false);
request.setPassThreshold(100);
request.setDescription(null);
request.setType(TestPlanConstants.TEST_PLAN_TYPE_PLAN);
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_POST_TEST_PLAN_ADD, request);
String returnStr = mvcResult.getResponse().getContentAsString();
ResultHolder holder = JSON.parseObject(returnStr, ResultHolder.class);
String returnId = holder.getData().toString();
Assertions.assertNotNull(returnId);
}
} }