feat(测试计划): 新增测试集功能用例脑图

This commit is contained in:
guoyuqi 2024-09-19 17:21:07 +08:00 committed by Craftsman
parent b0f24ef72e
commit 3f87ec4f32
6 changed files with 189 additions and 12 deletions

View File

@ -86,4 +86,12 @@ public class FunctionalCaseMinderController {
return PageUtils.setPageInfo(page, functionalCaseMinderService.getPlanMindFunctionalCase(request, false)); return PageUtils.setPageInfo(page, functionalCaseMinderService.getPlanMindFunctionalCase(request, false));
} }
@PostMapping("/collection/list")
@Operation(summary = "测试集-功能用例-脑图用例跟根据测试集ID查询列表")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public Pager<List<FunctionalMinderTreeDTO>> getCollectionFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCaseCollectionMindRequest request) { Page<Object> page = PageHelper.startPage(request.getCurrent(), 100 );
return PageUtils.setPageInfo(page, functionalCaseMinderService.getCollectionMindFunctionalCase(request, false));
}
} }

View File

@ -96,7 +96,7 @@ public interface ExtFunctionalCaseMapper {
List<FunctionalCaseCustomField> getCaseCustomFieldList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted, @Param("fieldIds") List<String> fieldIds); List<FunctionalCaseCustomField> getCaseCustomFieldList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted, @Param("fieldIds") List<String> fieldIds);
List<FunctionalCaseCustomField> getCaseCustomFieldListByCollection(@Param("request") FunctionalCaseCollectionMindRequest request, @Param("deleted") boolean deleted, @Param("fieldIds") List<String> fieldIds);
/** /**
* 根据模块ID获取用例评审脑图展示数据 * 根据模块ID获取用例评审脑图展示数据
*/ */
@ -104,6 +104,9 @@ public interface ExtFunctionalCaseMapper {
List<FunctionalCaseMindDTO> getMinderTestPlanList(@Param("request") FunctionalCasePlanMindRequest request, @Param("deleted") boolean delete); List<FunctionalCaseMindDTO> getMinderTestPlanList(@Param("request") FunctionalCasePlanMindRequest request, @Param("deleted") boolean delete);
List<FunctionalCaseMindDTO> getMinderCollectionList(@Param("request") FunctionalCaseCollectionMindRequest request, @Param("deleted") boolean delete);
List<BaseTreeNode> selectBaseMindNodeByProjectId(@Param("projectId") String projectId); List<BaseTreeNode> selectBaseMindNodeByProjectId(@Param("projectId") String projectId);
List<FunctionalCase> selectAllFunctionalCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId); List<FunctionalCase> selectAllFunctionalCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId);

View File

@ -690,6 +690,35 @@
order by fc.pos desc order by fc.pos desc
</select> </select>
<select id="getCaseCustomFieldListByCollection" resultType="io.metersphere.functional.domain.FunctionalCaseCustomField">
SELECT
fccf.case_id, fccf.field_id, fccf.value
FROM
functional_case_custom_field fccf
LEFT JOIN functional_case fc ON fccf.case_id = fc.id
LEFT JOIN test_plan_functional_case tpfc ON tpfc.functional_case_id = fc.id
LEFT JOIN custom_field cf ON cf.id = fccf.field_id
WHERE
fc.deleted = false
AND
fc.project_Id = #{request.projectId}
AND
tpfc.test_plan_collection_id = #{request.collectionId}
AND
tpfc.test_plan_id = #{request.planId}
AND
cf.name = 'functional_priority'
AND cf.scene = 'FUNCTIONAL'
AND cf.internal= true
<if test="fieldIds != null and fieldIds.size() > 0">
and fccf.field_id in
<foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
#{fieldId}
</foreach>
</if>
order by fc.pos desc
</select>
<select id="getMinderCaseReviewList" resultType="io.metersphere.functional.dto.FunctionalCaseMindDTO"> <select id="getMinderCaseReviewList" resultType="io.metersphere.functional.dto.FunctionalCaseMindDTO">
SELECT SELECT
@ -757,6 +786,34 @@
fc.module_id = #{request.moduleId} fc.module_id = #{request.moduleId}
</select> </select>
<select id="getMinderCollectionList" resultType="io.metersphere.functional.dto.FunctionalCaseMindDTO">
SELECT
tpfc.id as id,
history.`status` as reviewStatus,
fc.module_id as moduleId,
fc.name as name,
fc.id as caseId,
fc.project_id, fc.template_id, fc.pos, fc.case_edit_type,
IFNULL(history.`steps`, fcb.steps) as steps, execute_history.`steps` as executeSteps, fcb.text_description, fcb.expected_result, fcb.prerequisite, fcb.description, history.`content`
FROM
test_plan_functional_case tpfc
LEFT JOIN functional_case fc ON tpfc.functional_case_id = fc.id
LEFT JOIN functional_case_blob fcb ON fcb.id = fc.id
LEFT JOIN (select * from (SELECT tpceh.test_plan_case_id, tpceh.`status`,tpceh.`steps`, tpceh.`content`, ROW_NUMBER() OVER (PARTITION BY tpceh.test_plan_case_id ORDER BY tpceh.create_time DESC) as rn from test_plan_case_execute_history tpceh where tpceh.test_plan_id = #{request.planId} and tpceh.deleted = false
order by tpceh.create_time desc ) as history_filter WHERE rn = 1 ) as history ON history.test_plan_case_id = tpfc.id
LEFT JOIN (select * from (SELECT tpceh.test_plan_case_id, tpceh.`status`,tpceh.`steps`, ROW_NUMBER() OVER (PARTITION BY tpceh.test_plan_case_id ORDER BY tpceh.create_time DESC) as rn from test_plan_case_execute_history tpceh where tpceh.test_plan_id = #{request.planId} and tpceh.deleted = false and tpceh.steps IS NOT NULL
order by tpceh.create_time desc ) as history_filter WHERE rn = 1 ) as execute_history ON execute_history.test_plan_case_id = tpfc.id
WHERE
tpfc.test_plan_id = #{request.planId}
AND fc.deleted = #{deleted}
AND
fc.project_Id = #{request.projectId}
AND
tpfc.test_plan_collection_id = #{request.collectionId}
</select>
<select id="selectBaseMindNodeByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode"> <select id="selectBaseMindNodeByProjectId" resultType="io.metersphere.system.dto.sdk.BaseTreeNode">
SELECT id, name, parent_id AS parentId, 'module' AS type SELECT id, name, parent_id AS parentId, 'module' AS type
FROM mind_additional_node FROM mind_additional_node

View File

@ -0,0 +1,27 @@
package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class FunctionalCaseCollectionMindRequest {
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.project_id.not_blank}")
private String projectId;
@Schema(description = "测试集ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String collectionId;
@Min(value = 1, message = "当前页码必须大于0")
@Schema(description = "当前页码")
private int current;
@Schema(description = "测试计划id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{test_plan_functional_case.test_plan_id.not_blank}")
private String planId;
}

View File

@ -135,7 +135,7 @@ public class FunctionalCaseMinderService {
return new ArrayList<>(); return new ArrayList<>();
} }
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseList(request, deleted); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseList(request, deleted);
List<String> fieldIds = getFieldIds(request); List<String> fieldIds = getFieldIds(request.getProjectId());
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds); List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
@ -146,8 +146,8 @@ public class FunctionalCaseMinderService {
} }
@NotNull @NotNull
private List<String> getFieldIds(FunctionalCaseMindRequest request) { private List<String> getFieldIds(String projectId) {
TemplateDTO defaultTemplateDTO = projectTemplateService.getDefaultTemplateDTO(request.getProjectId(), TemplateScene.FUNCTIONAL.toString()); TemplateDTO defaultTemplateDTO = projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.FUNCTIONAL.toString());
List<TemplateCustomFieldDTO> customFields = defaultTemplateDTO.getCustomFields(); List<TemplateCustomFieldDTO> customFields = defaultTemplateDTO.getCustomFields();
return customFields.stream().map(TemplateCustomFieldDTO::getFieldId).toList(); return customFields.stream().map(TemplateCustomFieldDTO::getFieldId).toList();
} }
@ -381,14 +381,16 @@ public class FunctionalCaseMinderService {
List<FunctionalCaseModule> allChildrenByCaseInDB = new ArrayList<>(); List<FunctionalCaseModule> allChildrenByCaseInDB = new ArrayList<>();
if (CollectionUtils.isNotEmpty(caseModuleIds)) { if (CollectionUtils.isNotEmpty(caseModuleIds)) {
functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample = new FunctionalCaseModuleExample();
functionalCaseModuleExample.createCriteria().andParentIdIn(caseModuleIds).andProjectIdEqualTo(request.getProjectId());; functionalCaseModuleExample.createCriteria().andParentIdIn(caseModuleIds).andProjectIdEqualTo(request.getProjectId());
;
allChildrenByCaseInDB = moduleMapper.selectByExample(functionalCaseModuleExample); allChildrenByCaseInDB = moduleMapper.selectByExample(functionalCaseModuleExample);
} }
allChildrenInDB.addAll(allChildrenByCaseInDB); allChildrenInDB.addAll(allChildrenByCaseInDB);
MindAdditionalNodeExample mindAdditionalNodeExample = new MindAdditionalNodeExample(); MindAdditionalNodeExample mindAdditionalNodeExample = new MindAdditionalNodeExample();
mindAdditionalNodeExample.createCriteria().andIdIn(targetIds).andProjectIdEqualTo(request.getProjectId());; mindAdditionalNodeExample.createCriteria().andIdIn(targetIds).andProjectIdEqualTo(request.getProjectId());
;
List<MindAdditionalNode> mindAdditionalNodes = additionalNodeMapper.selectByExample(mindAdditionalNodeExample); List<MindAdditionalNode> mindAdditionalNodes = additionalNodeMapper.selectByExample(mindAdditionalNodeExample);
Map<String, String> targetTextMap = new HashMap<>(); Map<String, String> targetTextMap = new HashMap<>();
List<String> targetTextParentIds = new ArrayList<>(); List<String> targetTextParentIds = new ArrayList<>();
@ -423,7 +425,8 @@ public class FunctionalCaseMinderService {
if (CollectionUtils.isNotEmpty(textModuleFilterCaseIds)) { if (CollectionUtils.isNotEmpty(textModuleFilterCaseIds)) {
functionalCaseExample = new FunctionalCaseExample(); functionalCaseExample = new FunctionalCaseExample();
functionalCaseExample.createCriteria().andModuleIdIn(textModuleFilterCaseIds).andProjectIdEqualTo(request.getProjectId());; functionalCaseExample.createCriteria().andModuleIdIn(textModuleFilterCaseIds).andProjectIdEqualTo(request.getProjectId());
;
List<FunctionalCase> allChildrenCaseByTextInDB = functionalCaseMapper.selectByExample(functionalCaseExample); List<FunctionalCase> allChildrenCaseByTextInDB = functionalCaseMapper.selectByExample(functionalCaseExample);
allChildrenCaseInDB.addAll(allChildrenCaseByTextInDB); allChildrenCaseInDB.addAll(allChildrenCaseByTextInDB);
} }
@ -1231,7 +1234,7 @@ public class FunctionalCaseMinderService {
List<FunctionalMinderTreeDTO> list = new ArrayList<>(); List<FunctionalMinderTreeDTO> list = new ArrayList<>();
//查出当前模块下的所有用例 //查出当前模块下的所有用例
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseReviewList(request, deleted, userId, viewStatusUserId); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseReviewList(request, deleted, userId, viewStatusUserId);
List<String> fieldIds = getFieldIds(request); List<String> fieldIds = getFieldIds(request.getProjectId());
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds); List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
//构造父子级数据 //构造父子级数据
@ -1248,7 +1251,7 @@ public class FunctionalCaseMinderService {
request.setModuleId(substring); request.setModuleId(substring);
} }
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderTestPlanList(request, deleted); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderTestPlanList(request, deleted);
List<String> fieldIds = getFieldIds(request); List<String> fieldIds = getFieldIds(request.getProjectId());
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds); List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
//构造父子级数据 //构造父子级数据
@ -1342,4 +1345,14 @@ public class FunctionalCaseMinderService {
} }
public List<FunctionalMinderTreeDTO> getCollectionMindFunctionalCase(FunctionalCaseCollectionMindRequest request, boolean deleted) {
List<FunctionalMinderTreeDTO> list = new ArrayList<>();
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCollectionList(request, deleted);
List<String> fieldIds = getFieldIds(request.getProjectId());
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldListByCollection(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
//构造父子级数据
buildList(functionalCaseMindDTOList, list, priorityMap, "TEST_PLAN");
return list;
}
} }

View File

@ -5,7 +5,11 @@ import io.metersphere.functional.dto.*;
import io.metersphere.functional.mapper.*; import io.metersphere.functional.mapper.*;
import io.metersphere.functional.request.*; import io.metersphere.functional.request.*;
import io.metersphere.plan.domain.TestPlanCaseExecuteHistory; import io.metersphere.plan.domain.TestPlanCaseExecuteHistory;
import io.metersphere.plan.domain.TestPlanCollection;
import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.mapper.TestPlanCaseExecuteHistoryMapper; import io.metersphere.plan.mapper.TestPlanCaseExecuteHistoryMapper;
import io.metersphere.plan.mapper.TestPlanCollectionMapper;
import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
@ -26,6 +30,7 @@ import org.springframework.test.web.servlet.MvcResult;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -49,6 +54,9 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
//测试计划 //测试计划
public static final String FUNCTIONAL_CASE_PLAN_LIST_URL = "/functional/mind/case/plan/list"; public static final String FUNCTIONAL_CASE_PLAN_LIST_URL = "/functional/mind/case/plan/list";
public static final String FUNCTIONAL_CASE_COLLECTION_LIST_URL = "/functional/mind/case/collection/list";
@Resource @Resource
private FunctionalCaseBlobMapper functionalCaseBlobMapper; private FunctionalCaseBlobMapper functionalCaseBlobMapper;
@ -62,6 +70,10 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
private FunctionalCaseCustomFieldMapper functionalCaseCustomFieldMapper; private FunctionalCaseCustomFieldMapper functionalCaseCustomFieldMapper;
@Resource @Resource
private TestPlanCaseExecuteHistoryMapper testPlanCaseExecuteHistoryMapper; private TestPlanCaseExecuteHistoryMapper testPlanCaseExecuteHistoryMapper;
@Resource
private TestPlanCollectionMapper testPlanCollectionMapper;
@Resource
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
@Test @Test
@Order(1) @Order(1)
@ -455,6 +467,63 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
Pager.class); Pager.class);
Assertions.assertNotNull(tableData.getList()); Assertions.assertNotNull(tableData.getList());
Assertions.assertEquals(2, tableData.getList().size()); Assertions.assertEquals(2, tableData.getList().size());
}
@Test
@Order(6)
public void testGetCaseCollectionList() throws Exception {
TestPlanCollection testPlanCollection = new TestPlanCollection();
testPlanCollection.setTestPlanId("TEST_MINDER_PLAN_ID_1");
testPlanCollection.setParentId("NONE");
testPlanCollection.setPos(500L);
testPlanCollection.setType("FUNCTIONAL");
testPlanCollection.setCreateTime(System.currentTimeMillis());
testPlanCollection.setName("功能用例");
String id = UUID.randomUUID().toString();
testPlanCollection.setId(id);
testPlanCollection.setCreateUser("admin");
testPlanCollection.setExtended(true);
testPlanCollection.setGrouped(false);
testPlanCollection.setTestResourcePoolId("100001100001");
testPlanCollection.setExecuteMethod("PARALLEL");
testPlanCollection.setEnvironmentId("NONE");
testPlanCollection.setRetryOnFail(false);
testPlanCollection.setStopOnFail(false);
testPlanCollectionMapper.insert(testPlanCollection);
testPlanCollection = new TestPlanCollection();
testPlanCollection.setTestPlanId("TEST_MINDER_PLAN_ID_1");
testPlanCollection.setParentId(id);
testPlanCollection.setPos(500L);
testPlanCollection.setType("FUNCTIONAL");
testPlanCollection.setCreateTime(System.currentTimeMillis());
testPlanCollection.setName("基本功能点");
String collectionId = UUID.randomUUID().toString();
testPlanCollection.setId(collectionId);
testPlanCollection.setCreateUser("admin");
testPlanCollection.setExtended(true);
testPlanCollection.setGrouped(false);
testPlanCollection.setTestResourcePoolId("100001100001");
testPlanCollection.setExecuteMethod("PARALLEL");
testPlanCollection.setEnvironmentId("NONE");
testPlanCollection.setRetryOnFail(false);
testPlanCollection.setStopOnFail(false);
testPlanCollectionMapper.insert(testPlanCollection);
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
testPlanFunctionalCase.setId("test_plan_functional_case_minder_id1");
testPlanFunctionalCase.setTestPlanCollectionId(collectionId);
testPlanFunctionalCaseMapper.updateByPrimaryKeySelective(testPlanFunctionalCase);
FunctionalCaseCollectionMindRequest request = new FunctionalCaseCollectionMindRequest();
request.setProjectId("project-case-minder-test");
request.setCollectionId(collectionId);
request.setPlanId("TEST_MINDER_PLAN_ID_1");
request.setCurrent(1);
MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_COLLECTION_LIST_URL, request);
Pager<List<FunctionalMinderTreeDTO>> tableData = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
Pager.class);
Assertions.assertNotNull(tableData.getList());
Assertions.assertEquals(1, tableData.getList().size());
//System.out.println(JSON.toJSONString(tableData.getList())); //System.out.println(JSON.toJSONString(tableData.getList()));
} }