feat(测试计划): 测试规划关联用例校验
This commit is contained in:
parent
301d55294e
commit
5500254a15
|
@ -131,3 +131,4 @@ test_plan.mind.case_count=Case count
|
|||
test_plan.mind.environment=Environment
|
||||
test_plan.mind.test_resource_pool=Resource pool
|
||||
test_plan.mind.collection_name_repeat=Duplicate test set name
|
||||
test_plan.collection_not_exist=Test plan collection does not exist
|
||||
|
|
|
@ -131,3 +131,4 @@ test_plan.mind.case_count=用例数
|
|||
test_plan.mind.environment=环境
|
||||
test_plan.mind.test_resource_pool=资源池
|
||||
test_plan.mind.collection_name_repeat=测试集名称重复
|
||||
test_plan.collection_not_exist=测试集不存在
|
||||
|
|
|
@ -130,3 +130,4 @@ test_plan.mind.case_count=用例數
|
|||
test_plan.mind.environment=環境
|
||||
test_plan.mind.test_resource_pool=資源池
|
||||
test_plan.mind.collection_name_repeat=測試集名稱重複
|
||||
test_plan.collection_not_exist=測試集不存在
|
||||
|
|
|
@ -602,6 +602,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
|||
* @param testPlanApiCaseList
|
||||
*/
|
||||
private void buildTestPlanApiCase(TestPlan testPlan, List<ApiTestCase> apiTestCases, String collectionId, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, List<LogDTO> logDTOS) {
|
||||
super.checkCollection(testPlan.getId(), collectionId, CaseType.API_CASE.getKey());
|
||||
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
|
||||
apiTestCases.forEach(apiTestCase -> {
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
|
|
|
@ -213,6 +213,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
|||
* @param testPlanApiScenarioList
|
||||
*/
|
||||
private void buildTestPlanApiScenario(TestPlan testPlan, List<ApiScenario> scenarios, String collectionId, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, List<LogDTO> logDTOS) {
|
||||
super.checkCollection(testPlan.getId(), collectionId, CaseType.SCENARIO_CASE.getKey());
|
||||
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
|
||||
scenarios.forEach(scenario -> {
|
||||
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
||||
|
|
|
@ -769,6 +769,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
|||
* @param testPlanFunctionalCaseList
|
||||
*/
|
||||
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList, List<LogDTO> logDTOS) {
|
||||
super.checkCollection(testPlan.getId(), functional.getCollectionId(), CaseType.FUNCTIONAL_CASE.getKey());
|
||||
List<String> functionalIds = functional.getIds();
|
||||
if (CollectionUtils.isNotEmpty(functionalIds)) {
|
||||
FunctionalCaseExample example = new FunctionalCaseExample();
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package io.metersphere.plan.service;
|
||||
|
||||
import io.metersphere.plan.domain.TestPlan;
|
||||
import io.metersphere.plan.domain.TestPlanCollectionExample;
|
||||
import io.metersphere.plan.dto.ResourceLogInsertModule;
|
||||
import io.metersphere.plan.dto.TestPlanCollectionDTO;
|
||||
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
|
||||
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
|
||||
import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest;
|
||||
import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
|
||||
import io.metersphere.plan.mapper.TestPlanCollectionMapper;
|
||||
import io.metersphere.plan.mapper.TestPlanMapper;
|
||||
import io.metersphere.sdk.constants.ModuleConstants;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.LogInsertModule;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -31,6 +36,8 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
|
|||
private TestPlanMapper testPlanMapper;
|
||||
@Resource
|
||||
private TestPlanResourceLogService testPlanResourceLogService;
|
||||
@Resource
|
||||
private TestPlanCollectionMapper testPlanCollectionMapper;
|
||||
|
||||
/**
|
||||
* 取消关联资源od
|
||||
|
@ -67,8 +74,25 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
|
|||
|
||||
/**
|
||||
* 初始化旧的关联资源到默认测试集
|
||||
*
|
||||
* @param planId
|
||||
* @param defaultCollections 默认的测试集集合
|
||||
*/
|
||||
public abstract void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections);
|
||||
|
||||
|
||||
/**
|
||||
* 校验测试集是否存在
|
||||
*
|
||||
* @param testPlanId
|
||||
* @param collectionId
|
||||
* @param type
|
||||
*/
|
||||
public void checkCollection(String testPlanId, String collectionId, String type) {
|
||||
TestPlanCollectionExample collectionExample = new TestPlanCollectionExample();
|
||||
collectionExample.createCriteria().andIdEqualTo(collectionId).andParentIdNotEqualTo(ModuleConstants.ROOT_NODE_PARENT_ID).andTestPlanIdEqualTo(testPlanId).andTypeEqualTo(type);
|
||||
if (testPlanCollectionMapper.countByExample(collectionExample) == 0) {
|
||||
throw new MSException(Translator.get("test_plan.collection_not_exist"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
|||
Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates = new HashMap<>();
|
||||
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
|
||||
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx_1");
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx_2");
|
||||
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_1"));
|
||||
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
|
||||
collectionAssociates.put(AssociateCaseType.API, baseCollectionAssociateRequests);
|
||||
|
@ -263,17 +263,17 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
|
|||
userDTO.setName("admin");
|
||||
userDTO.setLastOrganizationId("wxx_1234");
|
||||
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
|
||||
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates, user);
|
||||
testPlanApiCaseService.associateCollection("wxxx_1", collectionAssociates, user);
|
||||
|
||||
//api case
|
||||
Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates1 = new HashMap<>();
|
||||
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests1 = new ArrayList<>();
|
||||
BaseCollectionAssociateRequest baseCollectionAssociateRequest1 = new BaseCollectionAssociateRequest();
|
||||
baseCollectionAssociateRequest1.setCollectionId("wxxx_1");
|
||||
baseCollectionAssociateRequest1.setCollectionId("wxxx_2");
|
||||
baseCollectionAssociateRequest1.setIds(List.of("wxxx_api_case_1"));
|
||||
baseCollectionAssociateRequests1.add(baseCollectionAssociateRequest1);
|
||||
collectionAssociates1.put(AssociateCaseType.API_CASE, baseCollectionAssociateRequests1);
|
||||
testPlanApiCaseService.associateCollection("wxxx_2", collectionAssociates1, user);
|
||||
testPlanApiCaseService.associateCollection("wxxx_1", collectionAssociates1, user);
|
||||
|
||||
apiTestCase = initApiData();
|
||||
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
|
||||
|
|
|
@ -267,7 +267,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
|
|||
Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates = new HashMap<>();
|
||||
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
|
||||
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx_collection_1");
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx_collection_3");
|
||||
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_scenario_1"));
|
||||
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
|
||||
collectionAssociates.put(AssociateCaseType.API_SCENARIO, baseCollectionAssociateRequests);
|
||||
|
|
|
@ -25,7 +25,6 @@ import io.metersphere.system.controller.handler.ResultHolder;
|
|||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
@ -362,7 +361,7 @@ public class TestPlanCaseControllerTests extends BaseTest {
|
|||
Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates = new HashMap<>();
|
||||
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
|
||||
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx_1");
|
||||
baseCollectionAssociateRequest.setCollectionId("123");
|
||||
baseCollectionAssociateRequest.setIds(List.of("fc_1"));
|
||||
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
|
||||
collectionAssociates.put(AssociateCaseType.FUNCTIONAL, baseCollectionAssociateRequests);
|
||||
|
@ -372,6 +371,11 @@ public class TestPlanCaseControllerTests extends BaseTest {
|
|||
userDTO.setLastOrganizationId("wxx_1234");
|
||||
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
|
||||
testPlanFunctionalCaseService.associateCollection("plan_1", collectionAssociates, user);
|
||||
|
||||
baseCollectionAssociateRequest.setCollectionId("wxxx1231_1");
|
||||
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
|
||||
collectionAssociates.put(AssociateCaseType.FUNCTIONAL, baseCollectionAssociateRequests);
|
||||
Assertions.assertThrows(Exception.class, () -> testPlanFunctionalCaseService.associateCollection("plan_1", collectionAssociates, user));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -57,7 +57,9 @@ VALUES ('100001', 'functional_default', '', 1, UNIX_TIMESTAMP() * 1000, UNIX_TIM
|
|||
INSERT INTO template (id,name,remark,internal,update_time,create_time,create_user,scope_type,scope_id,enable_third_part, scene, ref_id) VALUES ('bug-template-id', 'bug_default', '', 1, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'PROJECT', 'gyq_disassociate', 0, 'BUG', 'bug-template-id');
|
||||
-- 初始化项目默认模板内置字段, 项目默认模板内置字段
|
||||
|
||||
|
||||
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');
|
||||
|
||||
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