feat(测试计划): 关联场景用例时保存执行环境
This commit is contained in:
parent
e228a8eb43
commit
eed41fab06
|
@ -13,4 +13,9 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs {
|
|||
private String projectName;
|
||||
private String userName;
|
||||
private List<String> tagNames;
|
||||
|
||||
/**
|
||||
* 场景跨项目ID
|
||||
*/
|
||||
private List<String> projectIds;
|
||||
}
|
||||
|
|
|
@ -654,24 +654,29 @@ public class ApiAutomationService {
|
|||
}
|
||||
|
||||
public void relevance(ApiCaseRelevanceRequest request) {
|
||||
List<String> ids = request.getSelectIds();
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
Map<String, List<String>> mapping = request.getMapping();
|
||||
Map<String, String> envMap = request.getEnvMap();
|
||||
Set<String> set = mapping.keySet();
|
||||
if (set.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<ApiScenario> apiScenarios = selectByIds(ids);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
|
||||
ExtTestPlanScenarioCaseMapper batchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
|
||||
apiScenarios.forEach(scenario -> {
|
||||
set.forEach(id -> {
|
||||
Map<String, String> newEnvMap = new HashMap<>(16);
|
||||
if (envMap != null && !envMap.isEmpty()) {
|
||||
List<String> list = mapping.get(id);
|
||||
list.forEach(l -> {
|
||||
newEnvMap.put(l, envMap.get(l));
|
||||
});
|
||||
}
|
||||
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
|
||||
testPlanApiScenario.setId(UUID.randomUUID().toString());
|
||||
testPlanApiScenario.setApiScenarioId(scenario.getId());
|
||||
testPlanApiScenario.setApiScenarioId(id);
|
||||
testPlanApiScenario.setTestPlanId(request.getPlanId());
|
||||
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
|
||||
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
|
||||
batchMapper.insertIfNotExists(testPlanApiScenario);
|
||||
testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap));
|
||||
testPlanApiScenarioMapper.insert(testPlanApiScenario);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
|
||||
public List<ApiScenario> selectByIds(List<String> ids) {
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
</sql>
|
||||
<select id="list" resultMap="BaseResultMap">
|
||||
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
|
||||
api_scenario.scenario_definition,
|
||||
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
|
||||
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
|
||||
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
|
||||
|
|
|
@ -5,6 +5,7 @@ import lombok.Setter;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -25,4 +26,14 @@ public class ApiCaseRelevanceRequest {
|
|||
* 具体要关联的用例
|
||||
*/
|
||||
private List<String> selectIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 项目环境对应关系
|
||||
*/
|
||||
private Map<String, String> envMap;
|
||||
|
||||
/**
|
||||
* 用例的环境的对应关系
|
||||
*/
|
||||
private Map<String, List<String>> mapping;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package io.metersphere.track.service;
|
||||
|
||||
import io.metersphere.api.dto.DeleteAPIReportRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.RunScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
|
||||
import io.metersphere.api.dto.definition.RunDefinitionRequest;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
import io.metersphere.base.domain.TestPlanApiCase;
|
||||
import io.metersphere.base.domain.TestPlanApiCaseExample;
|
||||
import io.metersphere.base.domain.TestPlanApiScenario;
|
||||
import io.metersphere.base.domain.TestPlanApiScenarioExample;
|
||||
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
|
||||
|
@ -20,7 +19,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -49,13 +47,24 @@ public class TestPlanScenarioCaseService {
|
|||
}
|
||||
|
||||
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
|
||||
// List<String> ids = apiAutomationService.selectIdsNotExistsInPlan(request.getProjectId(), request.getPlanId());
|
||||
// if (CollectionUtils.isEmpty(ids)) {
|
||||
// return new ArrayList<>();
|
||||
// }
|
||||
// request.setIds(ids);
|
||||
request.setNotInTestPlan(true);
|
||||
return apiAutomationService.list(request);
|
||||
List<ApiScenarioDTO> list = apiAutomationService.list(request);
|
||||
list.forEach(data -> {
|
||||
String definition = data.getScenarioDefinition();
|
||||
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
|
||||
Map<String, String> map = d.getEnvironmentMap();
|
||||
List<String> idList = new ArrayList<>();
|
||||
if (map != null) {
|
||||
Set<String> set = d.getEnvironmentMap().keySet();
|
||||
idList = new ArrayList<>(set);
|
||||
} else {
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(d.getEnvironmentId())) {
|
||||
idList.add(d.getEnvironmentId());
|
||||
}
|
||||
}
|
||||
data.setProjectIds(idList);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public int delete(String id) {
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
<div>
|
||||
<el-card class="table-card" v-loading="result.loading">
|
||||
|
||||
<env-popover :env-map="projectEnvMap" :project-ids="projectIds" @setProjectEnvMap="setProjectEnvMap"
|
||||
:project-list="projectList" ref="envPopover" class="env-popover"/>
|
||||
|
||||
<el-table ref="scenarioTable" border :data="tableData" class="adjust-table" @select-all="handleSelectAll" @select="handleSelect">
|
||||
<el-table-column type="selection"/>
|
||||
|
||||
|
@ -56,10 +59,12 @@
|
|||
import MsTestPlanList from "../../../../../api/automation/scenario/testplan/TestPlanList";
|
||||
import TestPlanScenarioListHeader from "./TestPlanScenarioListHeader";
|
||||
import {_handleSelect, _handleSelectAll} from "../../../../../../../common/js/tableUtils";
|
||||
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
|
||||
|
||||
export default {
|
||||
name: "RelevanceScenarioList",
|
||||
components: {
|
||||
EnvPopover,
|
||||
TestPlanScenarioListHeader,
|
||||
MsTablePagination, MsTableMoreBtn, ShowMoreBtn, MsTableHeader, MsTag, MsApiReportDetail, MsTestPlanList},
|
||||
props: {
|
||||
|
@ -84,7 +89,10 @@
|
|||
total: 0,
|
||||
reportId: "",
|
||||
infoDb: false,
|
||||
selectRows: new Set()
|
||||
selectRows: new Set(),
|
||||
projectEnvMap: new Map(),
|
||||
projectList: [],
|
||||
projectIds: new Set(),
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
@ -95,8 +103,13 @@
|
|||
this.search();
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.getWsProjects();
|
||||
},
|
||||
methods: {
|
||||
search() {
|
||||
this.projectEnvMap.clear();
|
||||
this.projectIds.clear();
|
||||
if (!this.projectId) {
|
||||
return;
|
||||
}
|
||||
|
@ -129,10 +142,31 @@
|
|||
},
|
||||
handleSelectAll(selection) {
|
||||
_handleSelectAll(this, selection, this.tableData, this.selectRows);
|
||||
this.initProjectIds();
|
||||
},
|
||||
handleSelect(selection, row) {
|
||||
_handleSelect(this, selection, row, this.selectRows);
|
||||
this.initProjectIds();
|
||||
},
|
||||
setProjectEnvMap(projectEnvMap) {
|
||||
this.projectEnvMap = projectEnvMap;
|
||||
},
|
||||
getWsProjects() {
|
||||
this.$get("/project/listAll", res => {
|
||||
this.projectList = res.data;
|
||||
})
|
||||
},
|
||||
initProjectIds() {
|
||||
this.projectIds.clear();
|
||||
this.selectRows.forEach(row => {
|
||||
row.projectIds.forEach(id => {
|
||||
this.projectIds.add(id);
|
||||
})
|
||||
})
|
||||
},
|
||||
checkEnv() {
|
||||
return this.$refs.envPopover.checkEnv();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -141,4 +175,9 @@
|
|||
/deep/ .el-drawer__header {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.env-popover {
|
||||
float: right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
import TestCaseRelevanceBase from "../base/TestCaseRelevanceBase";
|
||||
import MsApiModule from "../../../../../api/definition/components/module/ApiModule";
|
||||
import {getCurrentProjectID} from "../../../../../../../common/js/utils";
|
||||
import {getCurrentProjectID, strMapToObj} from "../../../../../../../common/js/utils";
|
||||
import ApiList from "../../../../../api/definition/components/list/ApiList";
|
||||
import ApiCaseSimpleList from "../../../../../api/definition/components/list/ApiCaseSimpleList";
|
||||
import MsApiScenarioList from "../../../../../api/automation/scenario/ApiScenarioList";
|
||||
|
@ -98,13 +98,21 @@
|
|||
},
|
||||
|
||||
saveCaseRelevance() {
|
||||
const sign = this.$refs.apiScenarioList.checkEnv();
|
||||
if (!sign) {
|
||||
return false;
|
||||
}
|
||||
let param = {};
|
||||
let url = '';
|
||||
let selectIds = [];
|
||||
url = '/api/automation/relevance';
|
||||
selectIds = Array.from(this.$refs.apiScenarioList.selectRows).map(row => row.id);
|
||||
let url = '/api/automation/relevance';
|
||||
let rows = this.$refs.apiScenarioList.selectRows;
|
||||
const envMap = this.$refs.apiScenarioList.projectEnvMap;
|
||||
let map = new Map();
|
||||
rows.forEach(row => {
|
||||
map.set(row.id, row.projectIds);
|
||||
})
|
||||
param.planId = this.planId;
|
||||
param.selectIds = selectIds;
|
||||
param.mapping = strMapToObj(map);
|
||||
param.envMap = strMapToObj(envMap);
|
||||
|
||||
this.result = this.$post(url, param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
|
|
Loading…
Reference in New Issue