Skip to content

Commit

Permalink
feat(缺陷管理): 补充关联接口场景用例功能
Browse files Browse the repository at this point in the history
  • Loading branch information
song-cc-rock authored and liuruibin committed Apr 26, 2024
1 parent 439742a commit 1598b5f
Show file tree
Hide file tree
Showing 23 changed files with 538 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.metersphere.context;

import io.metersphere.provider.BaseAssociateCaseProvider;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
* 关联用例接口Bean实例上下文
*/
@Component
public class AssociateCaseFactory implements ApplicationContextAware {

public static final Map<String, BaseAssociateCaseProvider> PROVIDER_MAP = new HashMap<>();

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, BaseAssociateCaseProvider> beanMap = applicationContext.getBeansOfType(BaseAssociateCaseProvider.class);
PROVIDER_MAP.putAll(beanMap);
}

public static BaseAssociateCaseProvider getInstance(String serviceType) {
return PROVIDER_MAP.get(serviceType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.List;

/**
* 多个实现(关联用例基础接口)
*/
public interface BaseAssociateCaseProvider {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.metersphere.sdk.constants;

import io.metersphere.sdk.util.Translator;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -10,41 +9,41 @@ public enum CaseType {
/**
* 功能用例
*/
FUNCTIONAL_CASE("FUNCTIONAL", "test_case"),
FUNCTIONAL_CASE("FUNCTIONAL", "test_case", PermissionConstants.FUNCTIONAL_CASE_READ, "functional_case", "functional_case_module", "functional_case.module.default.name"),
/**
* 接口用例
*/
API_CASE("API", "api_case"),
API_CASE("API", "api_case", PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, "api_test_case", "api_definition_module", "api_unplanned_request"),
/**
* 性能用例
* 场景用例
*/
SCENARIO_CASE("SCENARIO", "scenario_case"),
/**
* UI用例
*/
UI_CASE("UI", "ui_case"),
/**
* 性能用例
*/
PERFORMANCE_CASE("PERFORMANCE", "performance_case");
SCENARIO_CASE("SCENARIO", "scenario_case", PermissionConstants.PROJECT_API_SCENARIO_READ, "api_scenario", "api_scenario_module", "api_unplanned_scenario");

private final String key;

private final String value;
private final String type;

CaseType(String key, String value) {
this.key = key;
this.value = value;
}
private final String usePermission;

private final String caseTable;

private final String moduleTable;

public String getValue() {
return Translator.get(value);
private final String unPlanName;

CaseType(String key, String type, String usePermission, String caseTable, String moduleTable, String unPlanName) {
this.key = key;
this.type = type;
this.usePermission = usePermission;
this.caseTable = caseTable;
this.moduleTable = moduleTable;
this.unPlanName = unPlanName;
}

public static String getValue(String key) {
public static CaseType getType(String key) {
for (CaseType caseType : CaseType.values()) {
if (StringUtils.equals(caseType.getKey(), key)) {
return caseType.getValue();
return caseType;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bug_comment_not_exist=缺陷评论不存在
bug_comment_not_owner=非当前评论创建人, 无法操作!
bug_relate_case_not_found=未查询到关联的用例
bug_relate_case_type_unknown=关联的用例类型未知, 无法查看
unknown_case_type_of_relate_case=参数错误, 未知的用例类型
bug_relate_case_permission_error=无用例查看权限, 请联系管理员
bug_status_can_not_be_empty=缺陷状态不能为空
handle_user_can_not_be_empty=缺陷处理人不能为空
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bug_comment_not_exist=Bug comment does not exist
bug_comment_not_owner=Not owner of the bug comment!
bug_relate_case_not_found=Bug related case not found
bug_relate_case_type_unknown=Bug related case type unknown
unknown_case_type_of_relate_case=Parameter error, unknown case type
bug_relate_case_permission_error=No permission to show the case
bug_status_can_not_be_empty=Status cannot be empty
handle_user_can_not_be_empty=Handle user cannot be empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bug_comment_not_exist=缺陷评论不存在
bug_comment_not_owner=非当前评论创建人, 无法操作!
bug_relate_case_not_found=未查询到关联的用例
bug_relate_case_type_unknown=关联的用例类型未知, 无法查看
unknown_case_type_of_relate_case=参数错误, 未知的用例类型
bug_relate_case_permission_error=无用例查看权限, 请联系管理员
bug_status_can_not_be_empty=缺陷状态不能为空
handle_user_can_not_be_empty=缺陷处理人不能为空
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bug_comment_not_exist=缺陷評論不存在
bug_comment_not_owner=非當前評論創建人, 無法操作!
bug_relate_case_not_found=未查詢到關聯的用例
bug_relate_case_type_unknown=關聯的用例類型未知, 無法查看
unknown_case_type_of_relate_case=參數錯誤, 未知的用例類型
bug_relate_case_permission_error=無權限查看, 請聯繫管理員
bug_status_can_not_be_empty=缺陷狀態不能為空
handle_user_can_not_be_empty=缺陷處理人不能為空
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,21 @@ public interface ExtApiScenarioMapper {
List<ApiScenario> getScenarioExecuteInfoByIds(@Param("ids") List<String> ids);

List<ModuleCountDTO> countModuleIdByRequest(@Param("request") ApiScenarioModuleRequest request, @Param("deleted") boolean deleted);

/**
* 获取缺陷未关联的场景用例列表
* @param request provider参数
* @param deleted 是否删除状态
* @param sort 排序
* @return 通用的列表Case集合
*/
List<TestCaseProviderDTO> listUnRelatedCaseWithBug(@Param("request") TestCasePageProviderRequest request, @Param("deleted") boolean deleted, @Param("sort") String sort);

/**
* 根据关联条件获取关联的用例ID
* @param request 关联参数
* @param deleted 是否删除状态
* @return 关联的用例ID集合
*/
List<String> getSelectIdsByAssociateParam(@Param("request")AssociateOtherCaseRequest request, @Param("deleted") boolean deleted);
}
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,49 @@
GROUP BY api_scenario.module_id
</select>

<select id="listUnRelatedCaseWithBug" resultMap="TestCaseProviderDTO">
select
ao.id,
ao.num,
ao.name,
ao.priority,
ao.project_id,
ao.tags,
pv.name as versionName,
ao.create_user,
u.name as createUserName,
ao.create_time
from api_scenario ao
left join project_version pv ON ao.version_id = pv.id
left join user u ON ao.create_user = u.id
where ao.deleted = #{deleted}
and ao.project_id = #{request.projectId}
and ao.id not in
(
select brc.case_id from bug_relation_case brc where brc.bug_id = #{request.sourceId} and brc.case_type = #{request.sourceType}
)
<include refid="queryByTestCaseProviderParam"/>
order by
<if test="sort != null and sort != ''">
ao.${sort}
</if>
<if test="sort == null or sort == ''">
ao.create_time desc
</if>
</select>

<select id="getSelectIdsByAssociateParam" resultType="java.lang.String">
select ac.id
from api_test_case ac
where ac.deleted = #{deleted}
and ac.project_id = #{request.projectId}
and ac.id not in
(
select brc.case_id from bug_relation_case brc where brc.bug_id = #{request.sourceId} and brc.case_type = #{request.sourceType}
)
<include refid="queryByAssociateParam"/>
</select>

<sql id="report_filters">
<if test="${filter} != null and ${filter}.size() > 0">
<foreach collection="${filter}.entrySet()" index="key" item="values">
Expand All @@ -577,4 +620,38 @@
</foreach>
</if>
</sql>

<sql id="queryByTestCaseProviderParam">
<!-- 待补充关联Case弹窗中的高级搜索条件filter, combine -->
<if test="request.keyword != null and request.keyword != ''">
and (
ao.num like concat('%', #{request.keyword}, '%')
or ao.name like concat('%', #{request.keyword}, '%')
or ao.tags like concat('%', #{request.keyword}, '%')
)
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
and ao.module_id in
<foreach collection="request.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
</sql>

<sql id="queryByAssociateParam">
<!-- 待补充关联Case弹窗中的高级搜索条件filter, combine -->
<if test="request.condition.keyword != null and request.condition.keyword != ''">
and (
ao.num like concat('%', #{request.keyword}, '%')
or ao.name like concat('%', #{request.keyword}, '%')
or ao.tags like concat('%', #{request.keyword}, '%')
)
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
and ao.module_id in
<foreach collection="request.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
</sql>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,21 @@ public interface ExtApiTestCaseMapper {
DropNode selectNodeByPosOperator(NodeSortQueryParam nodeSortQueryParam);

List<ApiTestCase> getApiCaseExecuteInfoByIds(@Param("ids")List<String> ids);

/**
* 获取缺陷未关联的接口用例列表
* @param request provider参数
* @param deleted 是否删除状态
* @param sort 排序
* @return 通用的列表Case集合
*/
List<TestCaseProviderDTO> listUnRelatedCaseWithBug(@Param("request") TestCasePageProviderRequest request, @Param("deleted") boolean deleted, @Param("sort") String sort);

/**
* 根据关联条件获取关联的用例ID
* @param request 关联参数
* @param deleted 是否删除状态
* @return 关联的用例ID集合
*/
List<String> getSelectIdsByAssociateParam(@Param("request")AssociateOtherCaseRequest request, @Param("deleted") boolean deleted);
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,52 @@
#{id}
</foreach>
</select>

<select id="listUnRelatedCaseWithBug" resultMap="TestCaseProviderDTO">
select
ac.id,
ac.num,
ac.name,
ac.priority,
ac.project_id,
ac.tags,
pv.name as versionName,
ac.create_user,
u.name as createUserName,
ac.create_time
from api_test_case ac
inner join api_definition ad on ac.api_definition_id = ad.id
left join project_version pv ON ac.version_id = pv.id
left join user u ON ac.create_user = u.id
where ac.deleted = #{deleted}
and ac.project_id = #{request.projectId}
and ac.id not in
(
select brc.case_id from bug_relation_case brc where brc.bug_id = #{request.sourceId} and brc.case_type = #{request.sourceType}
)
<include refid="queryByTestCaseProviderParam"/>
order by
<if test="sort != null and sort != ''">
ac.${sort}
</if>
<if test="sort == null or sort == ''">
ac.create_time desc
</if>
</select>

<select id="getSelectIdsByAssociateParam" resultType="java.lang.String">
select ac.id
from api_test_case ac
inner join api_definition ad on ac.api_definition_id = ad.id
where ac.deleted = #{deleted}
and ac.project_id = #{request.projectId}
and ac.id not in
(
select brc.case_id from bug_relation_case brc where brc.bug_id = #{request.sourceId} and brc.case_type = #{request.sourceType}
)
<include refid="queryByAssociateParam"/>
</select>

<sql id="report_filters">
<if test="${filter} != null and ${filter}.size() > 0">
<foreach collection="${filter}.entrySet()" index="key" item="values">
Expand Down Expand Up @@ -484,4 +530,50 @@
AND a.latest = 1
</if>
</sql>

<sql id="queryByTestCaseProviderParam">
<!-- 待补充关联Case弹窗中的高级搜索条件filter, combine -->
<if test="request.keyword != null and request.keyword != ''">
and (
ac.num like concat('%', #{request.keyword}, '%')
or ac.name like concat('%', #{request.keyword}, '%')
or ac.tags like concat('%', #{request.keyword}, '%')
)
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
and ac.module_id in
<foreach collection="request.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="request.protocol != null and request.protocol!=''">
and ad.protocol = #{request.protocol}
</if>
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
and ac.api_definition_id = #{request.apiDefinitionId}
</if>
</sql>

<sql id="queryByAssociateParam">
<!-- 待补充关联Case弹窗中的高级搜索条件filter, combine -->
<if test="request.condition.keyword != null and request.condition.keyword != ''">
and (
ac.num like concat('%', #{request.keyword}, '%')
or ac.name like concat('%', #{request.keyword}, '%')
or ac.tags like concat('%', #{request.keyword}, '%')
)
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
and ac.module_id in
<foreach collection="request.moduleIds" item="moduleId" open="(" separator="," close=")">
#{moduleId}
</foreach>
</if>
<if test="request.protocol != null and request.protocol!=''">
and ad.protocol = #{request.protocol}
</if>
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
and ac.api_definition_id = #{request.apiDefinitionId}
</if>
</sql>
</mapper>
Loading

0 comments on commit 1598b5f

Please sign in to comment.