feat(测试跟踪): 测试计划关联场景支持全选

--story=1008184 --user=陈建星 测试计划优化 https://www.tapd.cn/55049933/s/1198664
This commit is contained in:
chenjianxing 2022-07-12 11:57:12 +08:00 committed by jianxing
parent ed76c92ce3
commit 2fde5e2b9a
9 changed files with 159 additions and 160 deletions

View File

@ -273,12 +273,6 @@ public class ApiAutomationController {
return apiAutomationService.addScenarioToPlan(request);
}
@PostMapping("/relevance")
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.ASSOCIATE_CASE, content = "#msClass.getLogDetails(#request)", msClass = ApiAutomationService.class)
public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) {
apiAutomationService.relevance(request);
}
@PostMapping("/relevance/review")
public void testCaseReviewRelevance(@RequestBody ApiCaseRelevanceRequest request) {
apiAutomationService.relevanceReview(request);

View File

@ -187,6 +187,12 @@ public class ApiAutomationService {
return list;
}
public void buildApiCaseRelevanceRequest(ApiCaseRelevanceRequest request) {
this.initRequest(request.getCondition(), true, true);
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectRelevanceIdsByQuery(query));
}
public List<ApiScenarioDTO> listAll(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery(query));
@ -1010,45 +1016,6 @@ public class ApiAutomationService {
return extApiScenarioMapper.countRunResultByProjectID(projectId);
}
public void relevance(ApiCaseRelevanceRequest request) {
Map<String, List<String>> mapping = request.getMapping();
Map<String, String> envMap = request.getEnvMap();
Set<String> set = mapping.keySet();
List<String> relevanceIds = request.getSelectIds();
Collections.reverse(relevanceIds);
String envType = request.getEnvironmentType();
String envGroupId = request.getEnvGroupId();
if (set.isEmpty()) {
return;
}
Long nextOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanScenarioCaseMapper::getLastOrder);
for (String id : relevanceIds) {
Map<String, String> newEnvMap = new HashMap<>(16);
List<String> list = mapping.get(id);
list.forEach(l -> newEnvMap.put(l, envMap == null ? "" : envMap.getOrDefault(l, "")));
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(UUID.randomUUID().toString());
testPlanApiScenario.setCreateUser(SessionUtils.getUserId());
testPlanApiScenario.setApiScenarioId(id);
testPlanApiScenario.setTestPlanId(request.getPlanId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
String environmentJson = JSON.toJSONString(newEnvMap);
if (StringUtils.equals(envType, EnvironmentType.JSON.name())) {
testPlanApiScenario.setEnvironment(environmentJson);
testPlanApiScenario.setEnvironmentType(EnvironmentType.JSON.name());
} else if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) {
testPlanApiScenario.setEnvironmentType(EnvironmentType.GROUP.name());
testPlanApiScenario.setEnvironmentGroupId(envGroupId);
// JSON类型环境中也保存最新值
testPlanApiScenario.setEnvironment(environmentJson);
}
testPlanApiScenario.setOrder(nextOrder);
nextOrder += ServiceUtils.ORDER_STEP;
testPlanApiScenarioMapper.insert(testPlanApiScenario);
}
}
public void relevanceReview(ApiCaseRelevanceRequest request) {
Map<String, List<String>> mapping = request.getMapping();
Map<String, String> envMap = request.getEnvMap();
@ -2263,7 +2230,7 @@ public class ApiAutomationService {
e.printStackTrace();
}
//Compare the basic information of the APIScenario.
//Compare the basic information of the APIScenario.
if (!StringUtils.equals(exScenario.getName(), scenario.getName())) {
return true;

View File

@ -93,5 +93,5 @@ public interface ExtApiScenarioMapper {
List<ApiScenarioWithBLOBs> selectRepeatByBLOBs(@Param("names") List<String> names, @Param("projectId") String projectId);
List<String> selectRelevanceIdsByQuery(@Param("request") BaseQueryRequest query);
}

View File

@ -266,75 +266,7 @@
</foreach>
</when>
</choose>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_scenario.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_scenario.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='level'">
and api_scenario.level in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='last_result'">
and api_scenario.last_result in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='project_id'">
and api_scenario.project_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='principal'">
and api_scenario.principal in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='principal_name'">
and api_scenario.principal in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_name'">
and api_scenario.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='creator' or key=='creator_name'">
and api_scenario.create_user in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='version_id'">
and api_scenario.version_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
<include refid="filter"/>
<if test="request.filters == null || request.filters.size() == 0 ">
and (api_scenario.status is null or api_scenario.status != 'Trash')
</if>
@ -387,6 +319,78 @@
</where>
</sql>
<sql id="filter">
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_scenario.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_scenario.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='level'">
and api_scenario.level in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='last_result'">
and api_scenario.last_result in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='project_id'">
and api_scenario.project_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='principal'">
and api_scenario.principal in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='principal_name'">
and api_scenario.principal in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_name'">
and api_scenario.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='creator' or key=='creator_name'">
and api_scenario.create_user in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='version_id'">
and api_scenario.version_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
</sql>
<select id="selectByTagId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select *
from api_scenario
@ -439,17 +443,6 @@
and scenario_definition like CONCAT('%', #{request.id},'%') and id != #{request.id}
</where>
</select>
<update id="removeToGc">
update api_scenario
set original_state=status,
status = 'Trash'
where id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</update>
<update id="removeToGcByExample" parameterType="io.metersphere.base.domain.ApiScenarioExample">
update api_scenario
set original_state=status,
@ -458,7 +451,6 @@
<include refid="Example_Where_Clause"/>
</if>
</update>
<update id="reduction">
update api_scenario
set
@ -495,12 +487,6 @@
WHERE project_id = #{0}
AND status != 'Trash' AND latest = 1
</select>
<select id="selectIdAndScenarioByProjectId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
SELECT id, scenario_definition
FROM api_scenario
WHERE project_id = #{0}
AND status != 'Trash'
</select>
<select id="countByProjectIDAndCreatInThisWeek" resultType="java.lang.Long">
SELECT count(id) AS countNumber
FROM api_scenario
@ -829,6 +815,11 @@
and status != 'Trash'
and project_id = #{projectId}
</select>
<select id="selectRelevanceIdsByQuery" resultType="java.lang.String">
select api_scenario.id
from api_scenario
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
</mapper>

View File

@ -3,6 +3,7 @@ package io.metersphere.track.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.automation.*;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.OperLogModule;
@ -14,6 +15,7 @@ import io.metersphere.dto.MsExecResponseDTO;
import io.metersphere.dto.RunModeConfigDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.track.dto.RelevanceScenarioRequest;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.request.testcase.TestPlanScenarioCaseBatchRequest;
import io.metersphere.track.service.TestPlanScenarioCaseService;
import org.springframework.web.bind.annotation.*;
@ -66,6 +68,12 @@ public class TestPlanScenarioCaseController {
return testPlanScenarioCaseService.relevanceList(request, goPage, pageSize);
}
@PostMapping("/relevance")
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.ASSOCIATE_CASE, content = "#msClass.getLogDetails(#request)", msClass = ApiAutomationService.class)
public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) {
testPlanScenarioCaseService.relevance(request);
}
@GetMapping("/delete/{id}")
@MsAuditLog(module = OperLogModule.TRACK_TEST_CASE_REVIEW, type = OperLogConstants.UN_ASSOCIATE_CASE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = TestPlanScenarioCaseService.class)
public int deleteTestCase(@PathVariable String id) {

View File

@ -1,5 +1,6 @@
package io.metersphere.track.request.testcase;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import lombok.Getter;
import lombok.Setter;
@ -17,11 +18,6 @@ public class ApiCaseRelevanceRequest {
private String environmentId;
/**
* 当选择关联全部用例时把加载条件送到后台从后台查询
*/
// private QueryTestCaseRequest request;
/**
* 具体要关联的用例
*/
@ -42,5 +38,10 @@ public class ApiCaseRelevanceRequest {
private String reviewId;
private String environmentType;
private String envGroupId;
private List<String> ids;
private ApiScenarioRequest condition;
}

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.EnvironmentType;
import io.metersphere.api.dto.ScenarioEnv;
import io.metersphere.api.dto.automation.*;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiScenarioReportService;
@ -19,11 +20,7 @@ import io.metersphere.commons.constants.ExecuteResult;
import io.metersphere.commons.constants.ProjectApplicationType;
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.TestPlanUtils;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.commons.utils.*;
import io.metersphere.controller.request.ResetOrderRequest;
import io.metersphere.dto.MsExecResponseDTO;
import io.metersphere.dto.ProjectConfig;
@ -32,9 +29,9 @@ import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.service.ProjectApplicationService;
import io.metersphere.service.ProjectService;
import io.metersphere.track.dto.*;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.request.testcase.TestPlanScenarioCaseBatchRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -142,6 +139,57 @@ public class TestPlanScenarioCaseService {
return PageUtils.setPageInfo(page, apiAutomationService.list(request));
}
public void relevance(ApiCaseRelevanceRequest request) {
if (testPlanService.isAllowedRepeatCase(request.getPlanId())) {
request.getCondition().setNotInTestPlan(false);
} else {
request.getCondition().setNotInTestPlan(true);
}
apiAutomationService.buildApiCaseRelevanceRequest(request);
Map<String, List<String>> mapping = request.getMapping();
Map<String, String> envMap = request.getEnvMap();
Set<String> set = mapping.keySet();
List<String> relevanceIds = request.getIds();
Collections.reverse(relevanceIds);
String envType = request.getEnvironmentType();
String envGroupId = request.getEnvGroupId();
if (set.isEmpty()) {
return;
}
Long nextOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanScenarioCaseMapper::getLastOrder);
for (String id : relevanceIds) {
Map<String, String> newEnvMap = new HashMap<>(16);
List<String> list = mapping.get(id);
if (CollectionUtils.isEmpty(list)) {
ScenarioEnv scenarioEnv = apiAutomationService.getApiScenarioProjectId(id);
list = new ArrayList<>(scenarioEnv.getProjectIds());
}
list.forEach(l -> newEnvMap.put(l, envMap == null ? "" : envMap.getOrDefault(l, "")));
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(UUID.randomUUID().toString());
testPlanApiScenario.setCreateUser(SessionUtils.getUserId());
testPlanApiScenario.setApiScenarioId(id);
testPlanApiScenario.setTestPlanId(request.getPlanId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
String environmentJson = JSON.toJSONString(newEnvMap);
if (StringUtils.equals(envType, EnvironmentType.JSON.name())) {
testPlanApiScenario.setEnvironment(environmentJson);
testPlanApiScenario.setEnvironmentType(EnvironmentType.JSON.name());
} else if (StringUtils.equals(envType, EnvironmentType.GROUP.name())) {
testPlanApiScenario.setEnvironmentType(EnvironmentType.GROUP.name());
testPlanApiScenario.setEnvironmentGroupId(envGroupId);
// JSON类型环境中也保存最新值
testPlanApiScenario.setEnvironment(environmentJson);
}
testPlanApiScenario.setOrder(nextOrder);
nextOrder += ServiceUtils.ORDER_STEP;
testPlanApiScenarioMapper.insert(testPlanApiScenario);
}
}
public int delete(String id) {
TestPlanApiScenarioExample example = new TestPlanApiScenarioExample();
example.createCriteria()

View File

@ -32,7 +32,6 @@
@order="search"
@filter="filterSearch"
:disable-header-config="true"
:show-select-all="false"
@selectCountChange="selectCountChange">
<el-table-column v-if="!customNum" prop="num" label="ID" sortable="custom"
@ -150,7 +149,6 @@ export default {
},
currentScenario: {},
schedule: {},
selectAll: false,
tableData: [],
currentPage: 1,
pageSize: 10,

View File

@ -58,7 +58,6 @@ export default {
selectNodeIds: [],
moduleOptions: {},
trashEnable: false,
condition: {},
currentRow: {},
projectId: ""
};
@ -72,14 +71,6 @@ export default {
default: false
}
},
watch: {
planId() {
this.condition.planId = this.planId;
},
projectId() {
this.getVersionOptions();
}
},
methods: {
open() {
this.$refs.baseRelevance.open();
@ -107,7 +98,7 @@ export default {
},
postRelevance() {
let url = '/api/automation/relevance';
let url = '/test/plan/scenario/case/relevance';
const envMap = this.$refs.apiScenarioList.projectEnvMap;
let envType = this.$refs.apiScenarioList.environmentType;
let map = this.$refs.apiScenarioList.map;
@ -141,7 +132,7 @@ export default {
return false;
}
let selectIds = [];
let url = '/api/automation/relevance';
let url = '/test/plan/scenario/case/relevance';
let selectRows = this.$refs.apiScenarioList.selectRows;
const envMap = this.$refs.apiScenarioList.projectEnvMap;
let envType = this.$refs.apiScenarioList.environmentType;
@ -164,7 +155,8 @@ export default {
param.envMap = strMapToObj(envMap);
param.environmentType = envType;
param.envGroupId = envGroupId;
param.selectIds = selectIds;
param.ids = selectIds;
param.condition = this.$refs.apiScenarioList.condition;
this.result = this.$post(url, param, () => {
this.$success(this.$t('commons.save_success'));