feat(测试计划): 关联用例弹窗支持模块选择,重构关联逻辑

This commit is contained in:
WangXu10 2024-07-02 13:53:18 +08:00 committed by Craftsman
parent 0b0cee1a62
commit 8f31970302
23 changed files with 560 additions and 154 deletions

View File

@ -0,0 +1,32 @@
package io.metersphere.sdk.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author wx
*/
@Data
public class AssociateCaseDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
//排除的ids
private List<String> excludeIds;
//选中的ids
private List<String> selectIds;
//全选的模块
public List<String> moduleIds;
public AssociateCaseDTO(List<String> excludeIds, List<String> selectIds, List<String> moduleIds) {
this.excludeIds = excludeIds;
this.selectIds = selectIds;
this.moduleIds = moduleIds;
}
}

View File

@ -10,6 +10,7 @@ import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.request.AssociateOtherCaseRequest;
import io.metersphere.request.TestCasePageProviderRequest;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import org.apache.ibatis.annotations.Param;
@ -82,4 +83,8 @@ public interface ExtApiScenarioMapper {
ApiScenario getScenarioByResourceId(String id);
ApiScenario getScenarioByReportId(String reportId);
List<ApiScenario> selectAllCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId);
List<ApiScenario> selectCaseByModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("dto") AssociateCaseDTO dto, @Param("testPlanId") String testPlanId);
}

View File

@ -676,4 +676,56 @@
</foreach>
</if>
</sql>
<select id="selectAllCase" resultType="io.metersphere.api.domain.ApiScenario">
select
api_scenario.id,
api_scenario.create_user,
api_scenario.environment_id,
api_scenario.grouped
from api_scenario
where api_scenario.deleted = false
and api_scenario.project_id = #{projectId}
<if test="!isRepeat">
AND api_scenario.id not in (
select test_plan_api_scenario.api_scenario_id from test_plan_api_scenario where test_plan_api_scenario.test_plan_id = #{testPlanId}
)
</if>
order by api_scenario.pos asc
</select>
<select id="selectCaseByModules" resultType="io.metersphere.api.domain.ApiScenario">
select
api_scenario.id,
api_scenario.create_user,
api_scenario.environment_id,
api_scenario.grouped
from api_scenario
where api_scenario.deleted = false
and api_scenario.project_id = #{projectId}
<if test="!isRepeat">
AND api_scenario.id not in (
select test_plan_api_scenario.api_scenario_id from test_plan_api_scenario where test_plan_api_scenario.test_plan_id = #{testPlanId}
)
</if>
<if test="dto.moduleIds != null and dto.moduleIds.size() > 0">
and api_scenario.module_id in
<foreach collection="dto.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="dto.excludeIds != null and dto.excludeIds.size() > 0">
AND api_scenario.id not in
<foreach collection="dto.excludeIds" item="excludeId" separator="," open="(" close=")">
#{excludeId}
</foreach>
</if>
<if test="dto.selectIds != null and dto.selectIds.size() > 0">
or api_scenario.id in
<foreach collection="dto.selectIds" item="selectId" separator="," open="(" close=")">
#{selectId}
</foreach>
</if>
order by api_scenario.pos asc
</select>
</mapper>

View File

@ -10,6 +10,7 @@ import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.request.AssociateOtherCaseRequest;
import io.metersphere.request.TestCasePageProviderRequest;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.OptionDTO;
import org.apache.ibatis.annotations.Mapper;
@ -101,4 +102,10 @@ public interface ExtApiTestCaseMapper {
ApiTestCase getCaseByResourceId(String resourceId);
ApiTestCase getCaseByReportId(String resourceId);
List<ApiTestCase> selectAllApiCase(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("testPlanId") String testPlanId);
List<ApiTestCase> selectCaseByModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("dto") AssociateCaseDTO dto, @Param("testPlanId") String testPlanId);
List<ApiTestCase> selectCaseByApiModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("dto") AssociateCaseDTO dto, @Param("testPlanId") String testPlanId);
}

View File

@ -617,4 +617,92 @@
and ac.api_definition_id = #{request.apiDefinitionId}
</if>
</sql>
<select id="selectAllApiCase" 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
where api_test_case.deleted = false
and api_test_case.project_id = #{projectId}
<if test="!isRepeat">
AND api_test_case.id not in (
select test_plan_api_case.api_case_id from test_plan_api_case where test_plan_api_case.test_plan_id = #{testPlanId}
)
</if>
order by api_test_case.pos asc
</select>
<select id="selectCaseByModules" 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 api_definition on api_definition.id = api_test_case.api_definition_id
where api_test_case.deleted = false
and api_test_case.project_id = #{projectId}
<if test="!isRepeat">
AND api_test_case.id not in (
select test_plan_api_case.api_case_id from test_plan_api_case where test_plan_api_case.test_plan_id = #{testPlanId}
)
</if>
<if test="dto.moduleIds != null and dto.moduleIds.size() > 0">
and api_definition.module_id in
<foreach collection="dto.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="dto.excludeIds != null and dto.excludeIds.size() > 0">
AND api_test_case.id not in
<foreach collection="dto.excludeIds" item="excludeId" separator="," open="(" close=")">
#{excludeId}
</foreach>
</if>
<if test="dto.selectIds != null and dto.selectIds.size() > 0">
or api_test_case.id in
<foreach collection="dto.selectIds" item="selectId" separator="," open="(" close=")">
#{selectId}
</foreach>
</if>
order by api_test_case.pos asc
</select>
<select id="selectCaseByApiModules" 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 api_definition on api_definition.id = api_test_case.api_definition_id
where api_test_case.deleted = false
and api_test_case.project_id = #{projectId}
<if test="!isRepeat">
AND api_test_case.id not in (
select test_plan_api_case.api_case_id from test_plan_api_case where test_plan_api_case.test_plan_id =
#{testPlanId}
)
</if>
<if test="dto.moduleIds != null and dto.moduleIds.size() > 0">
and api_definition.module_id in
<foreach collection="dto.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="dto.excludeIds != null and dto.excludeIds.size() > 0">
AND api_definition.id not in
<foreach collection="dto.excludeIds" item="excludeId" separator="," open="(" close=")">
#{excludeId}
</foreach>
</if>
<if test="dto.selectIds != null and dto.selectIds.size() > 0">
or api_definition.id in
<foreach collection="dto.selectIds" item="selectId" separator="," open="(" close=")">
#{selectId}
</foreach>
</if>
order by api_test_case.pos asc
</select>
</mapper>

View File

@ -11,6 +11,7 @@ import io.metersphere.functional.request.*;
import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.request.AssociateOtherCaseRequest;
import io.metersphere.request.TestCasePageProviderRequest;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import org.apache.ibatis.annotations.Param;
@ -87,7 +88,7 @@ public interface ExtFunctionalCaseMapper {
*/
List<FunctionalCaseMindDTO> getMinderCaseList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted);
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);
/**
@ -97,5 +98,9 @@ public interface ExtFunctionalCaseMapper {
List<FunctionalCaseMindDTO> getMinderTestPlanList(@Param("request") FunctionalCasePlanMindRequest 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> selectCaseByModules(@Param("isRepeat") boolean isRepeat, @Param("projectId") String projectId, @Param("dto") AssociateCaseDTO dto, @Param("testPlanId") String testPlanId);
}

View File

@ -891,4 +891,51 @@
ORDER BY pos
</select>
<select id="selectAllFunctionalCase" resultType="io.metersphere.functional.domain.FunctionalCase">
select
functional_case.id,
functional_case.create_user
from functional_case
where functional_case.deleted = false
and functional_case.project_id = #{projectId}
<if test="!isRepeat">
AND functional_case.id not in (
select test_plan_functional_case.functional_case_id from test_plan_functional_case where test_plan_functional_case.test_plan_id = #{testPlanId}
)
</if>
order by functional_case.pos asc
</select>
<select id="selectCaseByModules" resultType="io.metersphere.functional.domain.FunctionalCase">
select
functional_case.id,
functional_case.create_user
from functional_case
where functional_case.deleted = false
and functional_case.project_id = #{projectId}
<if test="!isRepeat">
AND functional_case.id not in (
select test_plan_functional_case.functional_case_id from test_plan_functional_case where test_plan_functional_case.test_plan_id = #{testPlanId}
)
</if>
<if test="dto.moduleIds != null and dto.moduleIds.size() > 0">
and functional_case.module_id in
<foreach collection="dto.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="dto.excludeIds != null and dto.excludeIds.size() > 0">
AND functional_case.id not in
<foreach collection="dto.excludeIds" item="excludeId" separator="," open="(" close=")">
#{excludeId}
</foreach>
</if>
<if test="dto.selectIds != null and dto.selectIds.size() > 0">
or functional_case.id in
<foreach collection="dto.selectIds" item="selectId" separator="," open="(" close=")">
#{selectId}
</foreach>
</if>
order by functional_case.pos asc
</select>
</mapper>

View File

@ -0,0 +1,28 @@
package io.metersphere.plan.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @author wx
*/
@Data
public class ModuleSelectDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "是否选择当前模块下的全部数据")
private boolean selectAll;
@Schema(description = "不处理的ID")
List<String> excludeIds = new ArrayList<>();
@Schema(description = "选中的ID")
List<String> selectIds = new ArrayList<>();
}

View File

@ -1,11 +1,13 @@
package io.metersphere.plan.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* @author guoyuqi
@ -16,11 +18,18 @@ public class TestPlanCollectionAssociateDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "关联关系的ids", requiredMode = Schema.RequiredMode.REQUIRED)
private List<String> ids;
@Schema(description = "是否选择所有模块")
private boolean selectAllModule;
@Schema(description = "模块下的id集合属性", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Map<String, ModuleSelectDTO>> moduleMaps;
@Schema(description = "关联关系的type(功能FUNCTIONAL/接口定义API/接口用例API_CASE/场景API_SCENARIO)", requiredMode = Schema.RequiredMode.REQUIRED)
private String associateType;
@Schema(description = "项目id",requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.project_id.not_blank}")
private String projectId;
}

View File

@ -1,17 +1,16 @@
package io.metersphere.plan.dto.request;
import io.metersphere.plan.dto.TestPlanCollectionAssociateDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
public class BaseCollectionAssociateRequest {
@Schema(description = "测试集ID")
private String collectionId;
@Schema(description = "关联的用例ID集合")
private List<String> ids;
@Schema(description = "模块下的id集合属性")
private TestPlanCollectionAssociateDTO modules;
}

View File

@ -70,7 +70,6 @@ public interface ExtTestPlanApiCaseMapper {
List<TestPlanApiCase> getApiCaseExecuteInfoByIds(@Param("ids") List<String> ids);
List<ApiTestCase> selectApiCaseByDefinitionIds(@Param("ids") List<String> ids, @Param("isRepeat") boolean isRepeat, @Param("testPlanId") String testPlanId);
List<TestPlanApiCase> getSelectIdAndCollectionId(@Param("request") TestPlanApiCaseBatchRequest request);

View File

@ -709,31 +709,6 @@
</foreach>
</select>
<select id="selectApiCaseByDefinitionIds" resultType="io.metersphere.api.domain.ApiTestCase">
SELECT
api_test_case.id,
api_test_case.name,
api_test_case.api_definition_id,
api_test_case.environment_id,
api_test_case.create_user
FROM
api_test_case
WHERE
api_test_case.deleted = false
and api_test_case.api_definition_id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
<if test="!isRepeat">
AND api_test_case.id NOT IN (
SELECT
api_case_id
FROM
test_plan_api_case
where test_plan_api_case.test_plan_id = #{testPlanId}
)
</if>
</select>
<select id="getSelectIdAndCollectionId" resultType="io.metersphere.plan.domain.TestPlanApiCase">
SELECT t.id as id, t.test_plan_collection_id as test_plan_collection_id
FROM test_plan_api_case t

View File

@ -8,6 +8,7 @@ import io.metersphere.api.dto.definition.ApiTestCasePageRequest;
import io.metersphere.api.mapper.ApiReportMapper;
import io.metersphere.api.mapper.ApiTestCaseMapper;
import io.metersphere.api.mapper.ExtApiDefinitionModuleMapper;
import io.metersphere.api.mapper.ExtApiTestCaseMapper;
import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.definition.ApiDefinitionModuleService;
@ -33,6 +34,7 @@ import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.domain.EnvironmentExample;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.sdk.dto.api.task.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.EnvironmentMapper;
@ -42,7 +44,6 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.LogInsertModule;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
@ -71,8 +72,6 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ExtTestPlanMapper extTestPlanMapper;
@Resource
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@ -112,12 +111,12 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
@Resource
private ApiReportMapper apiReportMapper;
@Resource
private OperationLogService operationLogService;
@Resource
private ExtApiDefinitionModuleMapper extApiDefinitionModuleMapper;
@Resource
private TestPlanConfigMapper testPlanConfigMapper;
private static final String DEBUG_MODULE_COUNT_ALL = "all";
@Resource
private ExtApiTestCaseMapper extApiTestCaseMapper;
@Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -570,71 +569,71 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiCase> testPlanApiCaseList = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
//处理数据
handleApiData(collectionAssociates.get(AssociateCaseType.API), user, testPlanApiCaseList, testPlan);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), user, testPlanApiCaseList, testPlan);
handleApiData(collectionAssociates.get(AssociateCaseType.API), user, testPlanApiCaseList, testPlan, isRepeat);
handleApiCaseData(collectionAssociates.get(AssociateCaseType.API_CASE), user, testPlanApiCaseList, testPlan, isRepeat);
if (CollectionUtils.isNotEmpty(testPlanApiCaseList)) {
testPlanApiCaseMapper.batchInsert(testPlanApiCaseList);
}
}
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan) {
private void handleApiCaseData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, boolean isRepeat) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiTestCaseExample example = new ApiTestCaseExample();
example.createCriteria().andIdIn(ids);
List<ApiTestCase> apiTestCaseList = apiTestCaseMapper.selectByExample(example);
apiCaseList.forEach(apiCase -> {
List<String> apiCaseIds = apiCase.getIds();
if (CollectionUtils.isNotEmpty(apiCaseIds)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getId())).toList();
Map<String, ApiTestCase> apiTestCaseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, Function.identity()));
buildTestPlanApiCase(testPlan, apiCaseIds, apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList);
super.checkCollection(testPlan.getId(), apiCase.getCollectionId(), CaseType.API_CASE.getKey());
boolean selectAllModule = apiCase.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiCase.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId());
buildTestPlanApiCaseDTO(apiCase, apiTestCaseList, testPlan, user, testPlanApiCaseList);
} else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectCaseByModules(isRepeat, apiCase.getModules().getProjectId(), dto, testPlan.getId());
buildTestPlanApiCaseDTO(apiCase, apiTestCaseList, testPlan, user, testPlanApiCaseList);
}
});
}
}
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan) {
private void handleApiData(List<BaseCollectionAssociateRequest> apiCaseList, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList, TestPlan testPlan, boolean isRepeat) {
if (CollectionUtils.isNotEmpty(apiCaseList)) {
List<String> ids = apiCaseList.stream().flatMap(item -> item.getIds().stream()).toList();
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
List<ApiTestCase> apiTestCaseList = extTestPlanApiCaseMapper.selectApiCaseByDefinitionIds(ids, isRepeat, testPlan.getId());
apiCaseList.forEach(apiCase -> {
List<String> apiCaseIds = apiCase.getIds();
if (CollectionUtils.isNotEmpty(apiCaseIds) && CollectionUtils.isNotEmpty(apiTestCaseList)) {
List<ApiTestCase> apiTestCases = apiTestCaseList.stream().filter(item -> apiCaseIds.contains(item.getApiDefinitionId())).toList();
//生成map集合 key是apiDefinitionId value是apiTestCase
Map<String, ApiTestCase> apiTestCaseMap = apiTestCases.stream().collect(Collectors.toMap(ApiTestCase::getId, Function.identity()));
// apiTestCases 生成map key是apiDefinitionId value是List<String> id
Map<String, List<String>> apiTestCaseMapIds = apiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId, Collectors.mapping(ApiTestCase::getId, Collectors.toList())));
Collections.reverse(apiCaseIds);
apiCaseIds.forEach(apiCaseId -> {
buildTestPlanApiCase(testPlan, apiTestCaseMapIds.get(apiCaseId), apiTestCaseMap, apiCase.getCollectionId(), user, testPlanApiCaseList);
});
super.checkCollection(testPlan.getId(), apiCase.getCollectionId(), CaseType.API_CASE.getKey());
boolean selectAllModule = apiCase.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiCase.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectAllApiCase(isRepeat, apiCase.getModules().getProjectId(), testPlan.getId());
buildTestPlanApiCaseDTO(apiCase, apiTestCaseList, testPlan, user, testPlanApiCaseList);
} else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<ApiTestCase> apiTestCaseList = extApiTestCaseMapper.selectCaseByApiModules(isRepeat, apiCase.getModules().getProjectId(), dto, testPlan.getId());
buildTestPlanApiCaseDTO(apiCase, apiTestCaseList, testPlan, user, testPlanApiCaseList);
}
});
}
}
/**
* 构建测试计划接口用例对象
*
* @param apiCase
* @param apiTestCaseList
* @param testPlan
* @param apiTestCases
* @param collectionId
* @param user
* @param testPlanApiCaseList
*/
private void buildTestPlanApiCase(TestPlan testPlan, List<String> ids, Map<String, ApiTestCase> apiTestCases, String collectionId, SessionUser user, List<TestPlanApiCase> testPlanApiCaseList) {
super.checkCollection(testPlan.getId(), collectionId, CaseType.API_CASE.getKey());
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
Collections.reverse(ids);
ids.forEach(id -> {
ApiTestCase apiTestCase = apiTestCases.get(id);
private 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();
testPlanApiCase.setId(IDGenerator.nextStr());
testPlanApiCase.setTestPlanCollectionId(collectionId);
testPlanApiCase.setTestPlanCollectionId(apiCase.getCollectionId());
testPlanApiCase.setTestPlanId(testPlan.getId());
testPlanApiCase.setApiCaseId(apiTestCase.getId());
testPlanApiCase.setEnvironmentId(apiTestCase.getEnvironmentId());

View File

@ -4,9 +4,9 @@ import io.metersphere.api.domain.*;
import io.metersphere.api.dto.scenario.ApiScenarioDTO;
import io.metersphere.api.dto.scenario.ApiScenarioDetail;
import io.metersphere.api.dto.scenario.ApiScenarioPageRequest;
import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.api.mapper.ApiScenarioModuleMapper;
import io.metersphere.api.mapper.ApiScenarioReportMapper;
import io.metersphere.api.mapper.ExtApiScenarioMapper;
import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.scenario.ApiScenarioModuleService;
@ -32,6 +32,7 @@ import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.domain.EnvironmentExample;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.sdk.dto.api.task.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.mapper.EnvironmentMapper;
@ -51,13 +52,15 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.jetbrains.annotations.NotNull;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -80,8 +83,6 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
@Resource
private TestPlanMapper testPlanMapper;
@Resource
private ExtTestPlanMapper extTestPlanMapper;
@Resource
private TestPlanResourceLogService testPlanResourceLogService;
@Resource
private ApiScenarioRunService apiScenarioRunService;
@ -103,11 +104,13 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
@Resource
private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@Resource
private ApiScenarioModuleMapper apiScenarioModuleMapper;
@Resource
private ApiScenarioReportService apiScenarioReportService;
@Resource
private ExtApiScenarioMapper extApiScenarioMapper;
@Resource
private TestPlanConfigService testPlanConfigService;
@Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -179,25 +182,27 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
public void associateCollection(String planId, Map<String, List<BaseCollectionAssociateRequest>> collectionAssociates, SessionUser user) {
List<TestPlanApiScenario> testPlanApiScenarioList = new ArrayList<>();
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), user, testPlanApiScenarioList, testPlan);
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
handleApiScenarioData(collectionAssociates.get(AssociateCaseType.API_SCENARIO), user, testPlanApiScenarioList, testPlan, isRepeat);
if (CollectionUtils.isNotEmpty(testPlanApiScenarioList)) {
testPlanApiScenarioMapper.batchInsert(testPlanApiScenarioList);
}
}
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, TestPlan testPlan) {
private void handleApiScenarioData(List<BaseCollectionAssociateRequest> apiScenarioList, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList, TestPlan testPlan, boolean isRepeat) {
if (CollectionUtils.isNotEmpty(apiScenarioList)) {
List<String> ids = apiScenarioList.stream().flatMap(item -> item.getIds().stream()).toList();
ApiScenarioExample scenarioExample = new ApiScenarioExample();
scenarioExample.createCriteria().andIdIn(ids);
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(scenarioExample);
apiScenarioList.forEach(apiScenario -> {
List<String> apiScenarioIds = apiScenario.getIds();
if (CollectionUtils.isNotEmpty(apiScenarioIds)) {
List<ApiScenario> scenarios = apiScenarios.stream().filter(item -> apiScenarioIds.contains(item.getId())).toList();
// 生成map key为id value为scenario
Map<String, ApiScenario> scenarioMap = scenarios.stream().collect(Collectors.toMap(ApiScenario::getId, Function.identity()));
buildTestPlanApiScenario(testPlan, apiScenarioIds, scenarioMap, apiScenario.getCollectionId(), user, testPlanApiScenarioList);
super.checkCollection(testPlan.getId(), apiScenario.getCollectionId(), CaseType.SCENARIO_CASE.getKey());
boolean selectAllModule = apiScenario.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = apiScenario.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<ApiScenario> scenarioList = extApiScenarioMapper.selectAllCase(isRepeat, apiScenario.getModules().getProjectId(), testPlan.getId());
buildTestPlanApiScenarioDTO(apiScenario, scenarioList, testPlan, user, testPlanApiScenarioList);
} else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<ApiScenario> scenarioList = extApiScenarioMapper.selectCaseByModules(isRepeat, apiScenario.getModules().getProjectId(), dto, testPlan.getId());
buildTestPlanApiScenarioDTO(apiScenario, scenarioList, testPlan, user, testPlanApiScenarioList);
}
});
}
@ -206,23 +211,20 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
/**
* 构建测试计划场景用例对象
*
* @param apiScenario
* @param scenarioList
* @param testPlan
* @param scenarios
* @param collectionId
* @param user
* @param testPlanApiScenarioList
*/
private void buildTestPlanApiScenario(TestPlan testPlan, List<String> ids, Map<String, ApiScenario> scenarios, String collectionId, SessionUser user, List<TestPlanApiScenario> testPlanApiScenarioList) {
super.checkCollection(testPlan.getId(), collectionId, CaseType.SCENARIO_CASE.getKey());
AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId));
Collections.reverse(ids);
ids.forEach(id -> {
ApiScenario scenario = scenarios.get(id);
private 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();
testPlanApiScenario.setId(IDGenerator.nextStr());
testPlanApiScenario.setTestPlanId(testPlan.getId());
testPlanApiScenario.setApiScenarioId(scenario.getId());
testPlanApiScenario.setTestPlanCollectionId(collectionId);
testPlanApiScenario.setTestPlanCollectionId(apiScenario.getCollectionId());
testPlanApiScenario.setGrouped(scenario.getGrouped());
testPlanApiScenario.setEnvironmentId(scenario.getEnvironmentId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());

View File

@ -373,7 +373,7 @@ public class TestPlanCollectionMinderService {
testPlanCollection.setId(testPlanCollectionMinderEditDTO.getId());
testPlanCollection.setCreateUser(userId);
testPlanCollection.setCreateTime(null);
testPlanCollection.setPos((testPlanCollectionMinderEditDTO.getNum()+1) * 4096);
testPlanCollection.setPos((testPlanCollectionMinderEditDTO.getNum() + 1) * 4096);
collectionMapper.updateByPrimaryKeySelective(testPlanCollection);
return testPlanCollection;
}
@ -397,7 +397,7 @@ public class TestPlanCollectionMinderService {
testPlanCollection.setTestPlanId(request.getPlanId());
testPlanCollection.setCreateUser(userId);
testPlanCollection.setCreateTime(System.currentTimeMillis());
testPlanCollection.setPos((testPlanCollectionMinderEditDTO.getNum()+1) * 4096);
testPlanCollection.setPos((testPlanCollectionMinderEditDTO.getNum() + 1) * 4096);
collectionMapper.insert(testPlanCollection);
return testPlanCollection;
}
@ -422,7 +422,7 @@ public class TestPlanCollectionMinderService {
private static void addAssociate(TestPlanCollectionAssociateDTO associateDTO, TestPlanCollection testPlanCollection, List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests, Map<String, List<BaseCollectionAssociateRequest>> associateMap, String associateType) {
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
baseCollectionAssociateRequest.setCollectionId(testPlanCollection.getId());
baseCollectionAssociateRequest.setIds(associateDTO.getIds());
baseCollectionAssociateRequest.setModules(associateDTO);
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
associateMap.put(associateType, baseCollectionAssociateRequests);
}

View File

@ -11,9 +11,9 @@ import io.metersphere.bug.service.BugStatusService;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.functional.constants.CaseFileSourceType;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseExample;
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.FunctionalCaseMapper;
import io.metersphere.functional.service.FunctionalCaseAttachmentService;
@ -22,10 +22,7 @@ import io.metersphere.functional.service.FunctionalCaseService;
import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.constants.TreeTypeEnums;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.ResourceLogInsertModule;
import io.metersphere.plan.dto.TestPlanCaseRunResultCount;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.*;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.*;
import io.metersphere.plan.mapper.*;
@ -36,6 +33,7 @@ import io.metersphere.provider.BaseAssociateBugProvider;
import io.metersphere.request.AssociateBugPageRequest;
import io.metersphere.request.BugPageProviderRequest;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.dto.AssociateCaseDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.JSON;
@ -49,7 +47,6 @@ import io.metersphere.system.log.aspect.OperationLogAspect;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.ExtUserMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.service.UserLoginService;
@ -118,13 +115,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private ExtUserMapper extUserMapper;
private static final String CASE_MODULE_COUNT_ALL = "all";
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource
private OperationLogService operationLogService;
@Resource
private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper;
@Resource
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
@Resource
private TestPlanConfigService testPlanConfigService;
@Resource
private ExtFunctionalCaseMapper extFunctionalCaseMapper;
@Override
public long copyResource(String originalTestPlanId, String newTestPlanId, Map<String, String> oldCollectionIdToNewCollectionId, String operator, long operatorTime) {
@ -762,7 +759,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
List<BaseCollectionAssociateRequest> functionalList = collectionAssociates.get(AssociateCaseType.FUNCTIONAL);
if (CollectionUtils.isNotEmpty(functionalList)) {
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
functionalList.forEach(functional -> buildTestPlanFunctionalCase(testPlan, functional, user, testPlanFunctionalCaseList));
boolean isRepeat = testPlanConfigService.isRepeatCase(testPlan.getId());
functionalList.forEach(functional -> buildTestPlanFunctionalCase(testPlan, functional, user, testPlanFunctionalCaseList, isRepeat));
}
if (CollectionUtils.isNotEmpty(testPlanFunctionalCaseList)) {
testPlanFunctionalCaseMapper.batchInsert(testPlanFunctionalCaseList);
@ -777,34 +775,39 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
* @param user
* @param testPlanFunctionalCaseList
*/
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList) {
private void buildTestPlanFunctionalCase(TestPlan testPlan, BaseCollectionAssociateRequest functional, SessionUser user, List<TestPlanFunctionalCase> testPlanFunctionalCaseList, boolean isRepeat) {
super.checkCollection(testPlan.getId(), functional.getCollectionId(), CaseType.FUNCTIONAL_CASE.getKey());
List<String> functionalIds = functional.getIds();
if (CollectionUtils.isNotEmpty(functionalIds)) {
FunctionalCaseExample example = new FunctionalCaseExample();
example.createCriteria().andIdIn(functionalIds);
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(example);
AtomicLong nextOrder = new AtomicLong(getNextOrder(functional.getCollectionId()));
Map<String, FunctionalCase> collect = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, functionalCase -> functionalCase));
// 需要按列表顺序插入所以需要反转列表
Collections.reverse(functionalIds);
functionalIds.forEach(functionalId -> {
FunctionalCase functionalCase = collect.get(functionalId);
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
testPlanFunctionalCase.setId(IDGenerator.nextStr());
testPlanFunctionalCase.setTestPlanCollectionId(functional.getCollectionId());
testPlanFunctionalCase.setTestPlanId(testPlan.getId());
testPlanFunctionalCase.setFunctionalCaseId(functionalId);
testPlanFunctionalCase.setCreateUser(user.getId());
testPlanFunctionalCase.setCreateTime(System.currentTimeMillis());
testPlanFunctionalCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS));
testPlanFunctionalCase.setExecuteUser(functionalCase.getCreateUser());
testPlanFunctionalCase.setLastExecResult(ExecStatus.PENDING.name());
testPlanFunctionalCaseList.add(testPlanFunctionalCase);
});
boolean selectAllModule = functional.getModules().isSelectAllModule();
List<Map<String, ModuleSelectDTO>> moduleMaps = functional.getModules().getModuleMaps();
if (selectAllModule) {
// 选择了全部模块
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.selectAllFunctionalCase(isRepeat, functional.getModules().getProjectId(), testPlan.getId());
bulidTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
} else {
AssociateCaseDTO dto = super.getCaseIds(moduleMaps);
List<FunctionalCase> functionalCaseList = extFunctionalCaseMapper.selectCaseByModules(isRepeat, functional.getModules().getProjectId(), dto, testPlan.getId());
bulidTestPlanFunctionalCaseDTO(functional, functionalCaseList, testPlan, user, testPlanFunctionalCaseList);
}
}
private void bulidTestPlanFunctionalCaseDTO(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();
testPlanFunctionalCase.setId(IDGenerator.nextStr());
testPlanFunctionalCase.setTestPlanCollectionId(functional.getCollectionId());
testPlanFunctionalCase.setTestPlanId(testPlan.getId());
testPlanFunctionalCase.setFunctionalCaseId(functionalCase.getId());
testPlanFunctionalCase.setCreateUser(user.getId());
testPlanFunctionalCase.setCreateTime(System.currentTimeMillis());
testPlanFunctionalCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS));
testPlanFunctionalCase.setExecuteUser(functionalCase.getCreateUser());
testPlanFunctionalCase.setLastExecResult(ExecStatus.PENDING.name());
testPlanFunctionalCaseList.add(testPlanFunctionalCase);
});
}
@Override
public void initResourceDefaultCollection(String planId, List<TestPlanCollectionDTO> defaultCollections) {
TestPlanCollectionDTO defaultCollection = defaultCollections.stream().filter(collection -> StringUtils.equals(collection.getType(), CaseType.FUNCTIONAL_CASE.getKey())

View File

@ -2,7 +2,7 @@ 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.ModuleSelectDTO;
import io.metersphere.plan.dto.TestPlanCollectionDTO;
import io.metersphere.plan.dto.TestPlanResourceAssociationParam;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
@ -11,12 +11,14 @@ 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.dto.AssociateCaseDTO;
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;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@ -94,4 +96,34 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
throw new MSException(Translator.get("test_plan.collection_not_exist"));
}
}
/**
* 获取关联时的相关id数据
*
* @param moduleMaps
* @return
*/
protected AssociateCaseDTO getCaseIds(List<Map<String, ModuleSelectDTO>> moduleMaps) {
// 排除的ids
List<String> excludeIds = moduleMaps.stream()
.flatMap(map -> map.values().stream())
.flatMap(moduleSelectDTO -> moduleSelectDTO.getExcludeIds().stream())
.toList();
// 选中的ids
List<String> selectIds = moduleMaps.stream()
.flatMap(map -> map.values().stream())
.flatMap(moduleSelectDTO -> moduleSelectDTO.getSelectIds().stream())
.toList();
// 全选的模块
List<String> moduleIds = moduleMaps.stream()
.flatMap(map -> map.entrySet().stream())
.filter(entry -> BooleanUtils.isTrue(entry.getValue().isSelectAll()) && org.apache.commons.collections.CollectionUtils.isEmpty(entry.getValue().getSelectIds()))
.map(Map.Entry::getKey)
.toList();
AssociateCaseDTO associateCaseDTO = new AssociateCaseDTO(excludeIds, selectIds, moduleIds);
return associateCaseDTO;
}
}

View File

@ -21,6 +21,8 @@ import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.domain.TestPlanApiCase;
import io.metersphere.plan.domain.TestPlanApiCaseExample;
import io.metersphere.plan.dto.ModuleSelectDTO;
import io.metersphere.plan.dto.TestPlanCollectionAssociateDTO;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanOperationResponse;
import io.metersphere.plan.mapper.TestPlanApiCaseMapper;
@ -254,7 +256,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
baseCollectionAssociateRequest.setCollectionId("wxxx_2");
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_1"));
baseCollectionAssociateRequest.setModules(buildModulesAll(AssociateCaseType.API));
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.API, baseCollectionAssociateRequests);
@ -265,16 +267,22 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanApiCaseService.associateCollection("wxxx_1", collectionAssociates, user);
baseCollectionAssociateRequest.setModules(buildModules(AssociateCaseType.API));
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_2");
baseCollectionAssociateRequest1.setIds(List.of("wxxx_api_case_1"));
baseCollectionAssociateRequest1.setModules(buildModulesAll(AssociateCaseType.API_CASE));
baseCollectionAssociateRequests1.add(baseCollectionAssociateRequest1);
collectionAssociates1.put(AssociateCaseType.API_CASE, baseCollectionAssociateRequests1);
testPlanApiCaseService.associateCollection("wxxx_1", collectionAssociates1, user);
baseCollectionAssociateRequest1.setModules(buildModules(AssociateCaseType.API));
testPlanApiCaseService.associateCollection("wxxx_1", collectionAssociates1, user);
apiTestCase = initApiData();
TestPlanApiCase testPlanApiCase = new TestPlanApiCase();
testPlanApiCase.setApiCaseId(apiTestCase.getId());
@ -289,6 +297,34 @@ public class TestPlanApiCaseControllerTests extends BaseTest {
// todo 关联的接口测试
}
private TestPlanCollectionAssociateDTO buildModules(String type) {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(false);
associateDTO.setAssociateType(type);
associateDTO.setProjectId("wxx_1234");
associateDTO.setModuleMaps(buildModuleMap());
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("wxxx_api_1"));
moduleMap.put("123", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
}
private TestPlanCollectionAssociateDTO buildModulesAll(String type) {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(true);
associateDTO.setAssociateType(type);
associateDTO.setProjectId("wxx_1234");
return associateDTO;
}
@Test
@Order(7)
public void run() throws Exception {

View File

@ -20,6 +20,8 @@ import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.domain.TestPlanApiScenario;
import io.metersphere.plan.domain.TestPlanApiScenarioExample;
import io.metersphere.plan.dto.ModuleSelectDTO;
import io.metersphere.plan.dto.TestPlanCollectionAssociateDTO;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanOperationResponse;
import io.metersphere.plan.mapper.TestPlanApiScenarioMapper;
@ -268,7 +270,7 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
baseCollectionAssociateRequest.setCollectionId("wxxx_collection_3");
baseCollectionAssociateRequest.setIds(List.of("wxxx_api_scenario_1"));
baseCollectionAssociateRequest.setModules(buildModulesAll());
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.API_SCENARIO, baseCollectionAssociateRequests);
@ -278,6 +280,38 @@ public class TestPlanApiScenarioControllerTests extends BaseTest {
userDTO.setLastOrganizationId("wxx_1234");
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanApiScenarioService.associateCollection("wxxx_plan_2", collectionAssociates, user);
baseCollectionAssociateRequest.setModules(buildModules());
testPlanApiScenarioService.associateCollection("wxxx_plan_2", collectionAssociates, user);
}
private TestPlanCollectionAssociateDTO buildModules() {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(false);
associateDTO.setAssociateType(AssociateCaseType.API_SCENARIO);
associateDTO.setProjectId("wxx_project_1234");
associateDTO.setModuleMaps(buildModuleMap());
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("wxxx_api_scenario_1"));
moduleMap.put("wx_scenario_module_123", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
}
private TestPlanCollectionAssociateDTO buildModulesAll() {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(true);
associateDTO.setAssociateType(AssociateCaseType.API_SCENARIO);
associateDTO.setProjectId("wxx_project_1234");
return associateDTO;
}
@Test

View File

@ -12,6 +12,8 @@ import io.metersphere.plan.constants.AssociateCaseType;
import io.metersphere.plan.domain.TestPlanCaseExecuteHistory;
import io.metersphere.plan.domain.TestPlanFunctionalCase;
import io.metersphere.plan.domain.TestPlanFunctionalCaseExample;
import io.metersphere.plan.dto.ModuleSelectDTO;
import io.metersphere.plan.dto.TestPlanCollectionAssociateDTO;
import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.mapper.TestPlanCaseExecuteHistoryMapper;
import io.metersphere.plan.mapper.TestPlanFunctionalCaseMapper;
@ -362,7 +364,7 @@ public class TestPlanCaseControllerTests extends BaseTest {
List<BaseCollectionAssociateRequest> baseCollectionAssociateRequests = new ArrayList<>();
BaseCollectionAssociateRequest baseCollectionAssociateRequest = new BaseCollectionAssociateRequest();
baseCollectionAssociateRequest.setCollectionId("123");
baseCollectionAssociateRequest.setIds(List.of("fc_1"));
baseCollectionAssociateRequest.setModules(buildModulesAll());
baseCollectionAssociateRequests.add(baseCollectionAssociateRequest);
collectionAssociates.put(AssociateCaseType.FUNCTIONAL, baseCollectionAssociateRequests);
UserDTO userDTO = new UserDTO();
@ -372,12 +374,43 @@ public class TestPlanCaseControllerTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
testPlanFunctionalCaseService.associateCollection("plan_1", collectionAssociates, user);
baseCollectionAssociateRequest.setModules(buildModules());
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));
}
private TestPlanCollectionAssociateDTO buildModules() {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(false);
associateDTO.setAssociateType(AssociateCaseType.FUNCTIONAL);
associateDTO.setProjectId("123");
associateDTO.setModuleMaps(buildModuleMap());
return associateDTO;
}
private List<Map<String, ModuleSelectDTO>> buildModuleMap() {
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
Map<String, ModuleSelectDTO> moduleMap = new HashMap<>();
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(false);
moduleSelectDTO.setSelectIds(List.of("fc_1"));
moduleMap.put("100001", moduleSelectDTO);
moduleMaps.add(moduleMap);
return moduleMaps;
}
private TestPlanCollectionAssociateDTO buildModulesAll() {
TestPlanCollectionAssociateDTO associateDTO = new TestPlanCollectionAssociateDTO();
associateDTO.setSelectAllModule(true);
associateDTO.setAssociateType(AssociateCaseType.FUNCTIONAL);
associateDTO.setProjectId("123");
return associateDTO;
}
@Test
@Order(18)
public void testFunctionalBatchMove() throws Exception {

View File

@ -2,6 +2,7 @@ package io.metersphere.plan.controller;
import io.metersphere.plan.domain.TestPlanCollection;
import io.metersphere.plan.domain.TestPlanCollectionExample;
import io.metersphere.plan.dto.ModuleSelectDTO;
import io.metersphere.plan.dto.TestPlanCollectionAssociateDTO;
import io.metersphere.plan.dto.TestPlanCollectionMinderEditDTO;
import io.metersphere.plan.dto.TestPlanCollectionMinderTreeDTO;
@ -23,6 +24,7 @@ import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -43,7 +45,7 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
@Sql(scripts = {"/dml/init_test_plan_mind.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
void tesPagePlanReportSuccess() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(PLAN_MIND+"gyq_plan_1");
MvcResult mvcResult = this.requestGetWithOkAndReturn(PLAN_MIND + "gyq_plan_1");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
@ -131,10 +133,12 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
testPlanCollectionMinderEditDTO.setRetryTimes(5);
testPlanCollectionMinderEditDTO.setRetryInterval(1000);
testPlanCollectionMinderEditDTO.setStopOnFail(true);
List<TestPlanCollectionAssociateDTO>associateDTOS = new ArrayList<>();
List<TestPlanCollectionAssociateDTO> associateDTOS = new ArrayList<>();
TestPlanCollectionAssociateDTO testPlanCollectionAssociateDTO = new TestPlanCollectionAssociateDTO();
testPlanCollectionAssociateDTO.setAssociateType("API_CASE");
testPlanCollectionAssociateDTO.setIds(List.of("gyq_plan_api-case-associate-1"));
testPlanCollectionAssociateDTO.setSelectAllModule(true);
testPlanCollectionAssociateDTO.setProjectId("gyq_plan_project");
testPlanCollectionAssociateDTO.setModuleMaps(getModuleMaps());
associateDTOS.add(testPlanCollectionAssociateDTO);
testPlanCollectionMinderEditDTO.setAssociateDTOS(associateDTOS);
deleteDTO = testPlanCollectionMinderEditDTO;
@ -147,9 +151,9 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
List<TestPlanCollection> testPlanCollections1 = testPlanCollectionMapper.selectByExample(testPlanCollectionExample);
Assertions.assertEquals(4, testPlanCollections1.size());
TestPlanCollection testPlanCollection = testPlanCollectionMapper.selectByPrimaryKey("gyq_wxxx_4");
Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getName(),"更新名称"));
Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getName(), "更新名称"));
Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getEnvironmentId(),"NONE"));
Assertions.assertTrue(StringUtils.equalsIgnoreCase(testPlanCollection.getEnvironmentId(), "NONE"));
editList = new ArrayList<>();
editList.addAll(parentList);
testPlanCollectionMinderEditDTO = new TestPlanCollectionMinderEditDTO();
@ -171,7 +175,9 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
associateDTOS = new ArrayList<>();
testPlanCollectionAssociateDTO = new TestPlanCollectionAssociateDTO();
testPlanCollectionAssociateDTO.setAssociateType("API_CASE");
testPlanCollectionAssociateDTO.setIds(List.of("gyq_plan_api-case-associate-1"));
testPlanCollectionAssociateDTO.setSelectAllModule(true);
testPlanCollectionAssociateDTO.setProjectId("gyq_plan_project");
testPlanCollectionAssociateDTO.setModuleMaps(getModuleMaps());
associateDTOS.add(testPlanCollectionAssociateDTO);
testPlanCollectionMinderEditDTO.setAssociateDTOS(associateDTOS);
editList.add(testPlanCollectionMinderEditDTO);
@ -185,7 +191,8 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
editList.add(deleteDTO);
editList.add(deleteDTO);
request.setEditList(editList);
this.requestPost(EDIT_MIND, request).andExpect(status().is5xxServerError());;
this.requestPost(EDIT_MIND, request).andExpect(status().is5xxServerError());
;
testPlanCollectionExample = new TestPlanCollectionExample();
testPlanCollectionExample.createCriteria().andNameEqualTo("新建名称");
testPlanCollections = testPlanCollectionMapper.selectByExample(testPlanCollectionExample);
@ -215,5 +222,14 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest {
Assertions.assertTrue(CollectionUtils.isEmpty(testPlanCollections));
}
private List<Map<String, ModuleSelectDTO>> getModuleMaps() {
ModuleSelectDTO moduleSelectDTO = new ModuleSelectDTO();
moduleSelectDTO.setSelectAll(true);
moduleSelectDTO.setSelectIds(List.of("gyq_plan_api-case-associate-1"));
List<Map<String, ModuleSelectDTO>> moduleMaps = new ArrayList<>();
moduleMaps.add(Map.of("testmodule", moduleSelectDTO));
return moduleMaps;
}
}

View File

@ -68,4 +68,7 @@ INSERT INTO functional_case_blob(id, steps, text_description, expected_result, p
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)
VALUES
('123', 2, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]');
('123', 2, 1, 'wx', 'wx', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,'["bugManagement","caseManagement","apiTest","testPlan"]');
INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repeat_case`, `pass_threshold`, `case_run_mode`)
VALUES ('plan_1', b'0', b'0', 100.00, 'PARALLEL');

View File

@ -44,3 +44,5 @@ INSERT INTO test_resource_pool (id, name, type, description, enable, create_time
VALUES ('gyq_123_pool', '默认资源池', 'Node', '系统初始化资源池', true, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', true, false);
INSERT INTO `test_plan_config`(`test_plan_id`, `automatic_status_update`, `repeat_case`, `pass_threshold`, `case_run_mode`)
VALUES ('gyq_plan_1', b'0', b'0', 100.00, 'PARALLEL');