feat(测试计划): 同步添加功能用例的关联用例
This commit is contained in:
parent
6dee6010eb
commit
5e647b2070
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.functional.mapper;
|
||||
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.functional.dto.FunctionalCaseTestDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseTestPlanDTO;
|
||||
import io.metersphere.functional.dto.TestPlanCaseExecuteHistoryDTO;
|
||||
|
@ -20,6 +22,9 @@ public interface ExtFunctionalCaseTestMapper {
|
|||
|
||||
List<FunctionalCaseTestPlanDTO> getPlanList(@Param("request") AssociatePlanPageRequest request);
|
||||
|
||||
List<TestPlanCaseExecuteHistoryDTO>getPlanExecuteHistoryList(@Param("caseId") String caseId, @Param("planId") String planId);
|
||||
List<TestPlanCaseExecuteHistoryDTO> getPlanExecuteHistoryList(@Param("caseId") String caseId, @Param("planId") String planId);
|
||||
|
||||
List<ApiTestCase> selectApiCaseByCaseIds(@Param("caseIds") List<String> caseIds);
|
||||
|
||||
List<ApiScenario> selectApiScenarioByCaseIds(@Param("caseIds") List<String> caseIds);
|
||||
}
|
||||
|
|
|
@ -205,4 +205,43 @@
|
|||
</foreach>
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
|
||||
<select id="selectApiCaseByCaseIds" resultType="io.metersphere.api.domain.ApiTestCase">
|
||||
SELECT
|
||||
api_test_case.id,
|
||||
api_test_case.create_user,
|
||||
api_test_case.environment_id
|
||||
FROM
|
||||
api_test_case
|
||||
INNER JOIN functional_case_test ON api_test_case.id = functional_case_test.source_id
|
||||
WHERE
|
||||
api_test_case.deleted = FALSE
|
||||
<if test="caseIds != null and caseIds.size() > 0">
|
||||
AND functional_case_test.case_id in
|
||||
<foreach collection="caseIds" item="caseId" open="(" close=")" separator=",">
|
||||
#{caseId}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectApiScenarioByCaseIds" resultType="io.metersphere.api.domain.ApiScenario">
|
||||
SELECT
|
||||
api_scenario.id,
|
||||
api_scenario.create_user,
|
||||
api_scenario.environment_id,
|
||||
api_scenario.grouped
|
||||
FROM
|
||||
api_scenario
|
||||
INNER JOIN functional_case_test ON api_scenario.id = functional_case_test.source_id
|
||||
WHERE
|
||||
api_scenario.deleted = FALSE
|
||||
<if test="caseIds != null and caseIds.size() > 0">
|
||||
AND functional_case_test.case_id in
|
||||
<foreach collection="caseIds" item="caseId" open="(" close=")" separator=",">
|
||||
#{caseId}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
|
@ -23,6 +23,7 @@ import io.metersphere.request.*;
|
|||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
|
@ -134,7 +135,7 @@ public class FunctionalTestCaseService {
|
|||
functionalCaseTest.setSourceId(apiScenario.getId());
|
||||
functionalCaseTest.setVersionId(apiScenario.getVersionId());
|
||||
functionalCaseTest.setSourceType(request.getSourceType());
|
||||
functionalCaseTest.setId(IdGenerator.random().generateId());
|
||||
functionalCaseTest.setId(IDGenerator.nextStr());
|
||||
functionalCaseTest.setCreateUser(userId);
|
||||
functionalCaseTest.setCreateTime(System.currentTimeMillis());
|
||||
functionalCaseTest.setUpdateUser(userId);
|
||||
|
@ -160,7 +161,7 @@ public class FunctionalTestCaseService {
|
|||
functionalCaseTest.setSourceId(apiTestCase.getId());
|
||||
functionalCaseTest.setVersionId(apiTestCase.getVersionId());
|
||||
functionalCaseTest.setSourceType(request.getSourceType());
|
||||
functionalCaseTest.setId(IdGenerator.random().generateId());
|
||||
functionalCaseTest.setId(IDGenerator.nextStr());
|
||||
functionalCaseTest.setCreateUser(userId);
|
||||
functionalCaseTest.setCreateTime(System.currentTimeMillis());
|
||||
functionalCaseTest.setUpdateUser(userId);
|
||||
|
|
|
@ -31,5 +31,14 @@ public class TestPlanCollectionAssociateDTO implements Serializable {
|
|||
@NotBlank(message = "{functional_case.project_id.not_blank}")
|
||||
private String projectId;
|
||||
|
||||
@Schema(description = "是否同步添加功能用例的关联用例")
|
||||
private boolean syncCase = false;
|
||||
|
||||
@Schema(description = "接口计划集id")
|
||||
private String apiCaseCollectionId;
|
||||
|
||||
@Schema(description = "场景计划集id")
|
||||
private String apiScenarioCollectionId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -628,7 +628,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
* @param user
|
||||
* @param testPlanApiCaseList
|
||||
*/
|
||||
private void buildTestPlanApiCaseDTO(BaseCollectionAssociateRequest apiCase, List<ApiTestCase> apiTestCaseList, TestPlan testPlan, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList) {
|
||||
public void buildTestPlanApiCaseDTO(BaseCollectionAssociateRequest apiCase, List<ApiTestCase> apiTestCaseList, TestPlan testPlan, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList) {
|
||||
AtomicLong nextOrder = new AtomicLong(getNextOrder(apiCase.getCollectionId()));
|
||||
apiTestCaseList.forEach(apiTestCase -> {
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
|
|
|
@ -217,7 +217,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
|||
* @param user
|
||||
* @param testPlanApiScenarioList
|
||||
*/
|
||||
private void buildTestPlanApiScenarioDTO(BaseCollectionAssociateRequest apiScenario, List<ApiScenario> scenarioList, TestPlan testPlan, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList) {
|
||||
public void buildTestPlanApiScenarioDTO(BaseCollectionAssociateRequest apiScenario, List<ApiScenario> scenarioList, TestPlan testPlan, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList) {
|
||||
AtomicLong nextOrder = new AtomicLong(getNextOrder(apiScenario.getCollectionId()));
|
||||
scenarioList.forEach(scenario -> {
|
||||
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import com.alibaba.excel.util.BooleanUtils;
|
||||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.bug.domain.Bug;
|
||||
import io.metersphere.bug.domain.BugRelationCase;
|
||||
import io.metersphere.bug.domain.BugRelationCaseExample;
|
||||
|
@ -15,6 +18,7 @@ import io.metersphere.functional.domain.FunctionalCaseModule;
|
|||
import io.metersphere.functional.dto.*;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseMapper;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseModuleMapper;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseTestMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||
import io.metersphere.functional.service.FunctionalCaseAttachmentService;
|
||||
import io.metersphere.functional.service.FunctionalCaseModuleService;
|
||||
|
@ -122,6 +126,16 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
private TestPlanConfigService testPlanConfigService;
|
||||
@Resource
|
||||
private ExtFunctionalCaseMapper extFunctionalCaseMapper;
|
||||
@Resource
|
||||
private TestPlanApiCaseService testPlanApiCaseService;
|
||||
@Resource
|
||||
private ExtFunctionalCaseTestMapper extFunctionalCaseTestMapper;
|
||||
@Resource
|
||||
private TestPlanApiCaseMapper testPlanApiCaseMapper;
|
||||
@Resource
|
||||
private TestPlanApiScenarioService testPlanApiScenarioService;
|
||||
@Resource
|
||||
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
|
||||
|
||||
@Override
|
||||
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
|
||||
|
@ -783,15 +797,86 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
if (selectAllModule) {
|
||||
// 选择了全部模块
|
||||
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.selectAllFunctionalCase(isRepeat, functional.getModules().getProjectId(), testPlan.getId());
|
||||
bulidTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
|
||||
buildTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
|
||||
handleSyncCase(functionalCaseList, functional, testPlan, user);
|
||||
} else {
|
||||
AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
|
||||
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.selectCaseByModules(isRepeat, functional.getModules().getProjectId(), dto, testPlan.getId());
|
||||
bulidTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
|
||||
buildTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
|
||||
handleSyncCase(functionalCaseList, functional, testPlan, user);
|
||||
}
|
||||
}
|
||||
|
||||
private void bulidTestPlanFunctionalCaseDTO(BaseCollectionAssociateRequest functional, List<FunctionalCase> functionalCaseList, TestPlan testPlan, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList) {
|
||||
|
||||
/**
|
||||
* 处理同步添加功能用例关联的用例
|
||||
*
|
||||
* @param functionalCaseList
|
||||
* @param functional
|
||||
* @param testPlan
|
||||
* @param user
|
||||
*/
|
||||
private void handleSyncCase(List<FunctionalCase> functionalCaseList, BaseCollectionAssociateRequest functional, TestPlan testPlan, SessionUser user) {
|
||||
if (BooleanUtils.isTrue(functional.getModules().isSyncCase())) {
|
||||
handleApiCaseData(functionalCaseList, functional, testPlan, user);
|
||||
handleApiScenarioData(functionalCaseList, functional, testPlan, user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理场景用例数据
|
||||
*
|
||||
* @param functionalCaseList
|
||||
* @param functional
|
||||
* @param testPlan
|
||||
* @param user
|
||||
*/
|
||||
private void handleApiScenarioData(List<FunctionalCase> functionalCaseList, BaseCollectionAssociateRequest functional, TestPlan testPlan, SessionUser user) {
|
||||
if (StringUtils.isNotBlank(functional.getModules().getApiScenarioCollectionId()) && checkApiCollection(testPlan, functional.getModules().getApiScenarioCollectionId(), CaseType.SCENARIO_CASE.getKey())) {
|
||||
List<String> caseIds = functionalCaseList.stream().map(FunctionalCase::getId).toList();
|
||||
List<ApiScenario> scenarioList = extFunctionalCaseTestMapper.selectApiScenarioByCaseIds(caseIds);
|
||||
List<TestPlanApiScenario> testPlanApiScenarioList = new ArrayList<>();
|
||||
testPlanApiScenarioService.buildTestPlanApiScenarioDTO(functional, scenarioList, testPlan, user, testPlanApiScenarioList);
|
||||
if (CollectionUtils.isNotEmpty(testPlanApiScenarioList)) {
|
||||
testPlanApiScenarioMapper.batchInsert(testPlanApiScenarioList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理接口用例数据
|
||||
*
|
||||
* @param functionalCaseList
|
||||
* @param functional
|
||||
* @param testPlan
|
||||
* @param user
|
||||
*/
|
||||
private void handleApiCaseData(List<FunctionalCase> functionalCaseList, BaseCollectionAssociateRequest functional, TestPlan testPlan, SessionUser user) {
|
||||
if (StringUtils.isNotBlank(functional.getModules().getApiCaseCollectionId()) && checkApiCollection(testPlan, functional.getModules().getApiCaseCollectionId(), CaseType.API_CASE.getKey())) {
|
||||
List<String> caseIds = functionalCaseList.stream().map(FunctionalCase::getId).toList();
|
||||
List<ApiTestCase> apiTestCaseList = extFunctionalCaseTestMapper.selectApiCaseByCaseIds(caseIds);
|
||||
List<TestPlanApiCase> testPlanApiCaseList = new ArrayList<>();
|
||||
testPlanApiCaseService.buildTestPlanApiCaseDTO(functional, apiTestCaseList, testPlan, user, testPlanApiCaseList);
|
||||
if (CollectionUtils.isNotEmpty(testPlanApiCaseList)) {
|
||||
testPlanApiCaseMapper.batchInsert(testPlanApiCaseList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验测试集
|
||||
*
|
||||
* @param testPlan
|
||||
* @param apiCaseCollectionId
|
||||
* @return
|
||||
*/
|
||||
private boolean checkApiCollection(TestPlan testPlan, String apiCaseCollectionId, String type) {
|
||||
TestPlanCollectionExample collectionExample = new TestPlanCollectionExample();
|
||||
collectionExample.createCriteria().andIdEqualTo(apiCaseCollectionId).andTestPlanIdEqualTo(testPlan.getId()).andTypeEqualTo(type);
|
||||
return testPlanCollectionMapper.countByExample(collectionExample) > 0;
|
||||
}
|
||||
|
||||
private void buildTestPlanFunctionalCaseDTO(BaseCollectionAssociateRequest functional, List<FunctionalCase> functionalCaseList, TestPlan testPlan, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList) {
|
||||
AtomicLong nextOrder = new AtomicLong(getNextOrder(functional.getCollectionId()));
|
||||
functionalCaseList.forEach(functionalCase -> {
|
||||
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
|
||||
|
|
|
@ -389,6 +389,9 @@ public class TestPlanCaseControllerTests extends BaseTest {
|
|||
associateDTO.setAssociateType(AssociateCaseType.FUNCTIONAL);
|
||||
associateDTO.setProjectId("123");
|
||||
associateDTO.setModuleMaps(buildModuleMap());
|
||||
associateDTO.setSyncCase(true);
|
||||
associateDTO.setApiCaseCollectionId("223");
|
||||
associateDTO.setApiScenarioCollectionId("323");
|
||||
return associateDTO;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,9 @@ INSERT INTO template (id,name,remark,internal,update_time,create_time,create_use
|
|||
|
||||
INSERT INTO `test_plan_collection`(`id`, `test_plan_id`, `name`, `type`, `environment_id`, `test_resource_pool_id`, `pos`, `create_user`, `create_time`, `parent_id`)
|
||||
VALUES
|
||||
('123', 'plan_1', 'coll_1', 'FUNCTIONAL', 'NONE', 'NONE', 1, 'admin', 1716370415311, '123456');
|
||||
('123', 'plan_1', 'coll_1', 'FUNCTIONAL', 'NONE', 'NONE', 1, 'admin', 1716370415311, '123456'),
|
||||
('223', 'plan_1', 'api_coll_1', 'API', 'NONE', 'NONE', 2, 'admin', 1716370415311, '123456'),
|
||||
('323', 'plan_1', 'scenario_coll_1', 'SCENARIO', 'NONE', 'NONE', 3, 'admin', 1716370415311, '123456');
|
||||
|
||||
INSERT INTO `test_plan_case_execute_history`(`id`, `test_plan_case_id`, `test_plan_id`, `case_id`, `status`, `content`, `steps`, `deleted`, `notifier`, `create_user`, `create_time`)
|
||||
VALUES
|
||||
|
|
Loading…
Reference in New Issue