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