fix(接口自动化): 添加场景到测试计划时未选择环境

This commit is contained in:
shiziyuan9527 2021-03-10 14:15:01 +08:00
parent 842cf07ccf
commit e1d18909e2
5 changed files with 91 additions and 24 deletions

View File

@ -34,4 +34,14 @@ public class SaveApiPlanRequest {
private String projectId;
/**
* 项目环境对应关系
*/
private Map<String, String> envMap;
/**
* 用例的环境的对应关系
*/
private Map<String, List<String>> mapping;
}

View File

@ -611,27 +611,38 @@ public class ApiAutomationService {
if (CollectionUtils.isEmpty(request.getPlanIds())) {
MSException.throwException(Translator.get("plan id is null "));
}
List<String> scenarioIds = request.getScenarioIds();
if (request.isSelectAllDate()) {
scenarioIds = this.getAllScenarioIdsByFontedSelect(
request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
}
// List<String> scenarioIds = request.getScenarioIds();
// if (request.isSelectAllDate()) {
// scenarioIds = this.getAllScenarioIdsByFontedSelect(
// request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds());
// }
Map<String, List<String>> mapping = request.getMapping();
Map<String, String> envMap = request.getEnvMap();
Set<String> set = mapping.keySet();
List<TestPlanDTO> list = extTestPlanMapper.selectByIds(request.getPlanIds());
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class);
ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class);
for (TestPlanDTO testPlan : list) {
if (scenarioIds != null) {
for (String scenarioId : scenarioIds) {
if (!set.isEmpty()) {
set.forEach(id -> {
Map<String, String> newEnvMap = new HashMap<>(16);
if (envMap != null && !envMap.isEmpty()) {
List<String> lt = mapping.get(id);
lt.forEach(l -> {
newEnvMap.put(l, envMap.get(l));
});
}
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(UUID.randomUUID().toString());
testPlanApiScenario.setApiScenarioId(scenarioId);
testPlanApiScenario.setApiScenarioId(id);
testPlanApiScenario.setTestPlanId(testPlan.getId());
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setUpdateTime(System.currentTimeMillis());
testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap));
scenarioBatchMapper.insertIfNotExists(testPlanApiScenario);
}
});
}
if (request.getApiIds() != null) {
for (String caseId : request.getApiIds()) {

View File

@ -5,8 +5,8 @@
<insert id="insertIfNotExists" parameterType="io.metersphere.base.domain.TestPlanApiScenario">
-- 查询没有数据再插入
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time)
SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}
INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time, environment)
SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}, #{request.environment}
FROM DUAL
WHERE NOT EXISTS(
SELECT id FROM

View File

@ -145,7 +145,7 @@
<!--测试计划-->
<el-drawer :visible.sync="planVisible" :destroy-on-close="true" direction="ltr" :withHeader="false"
:title="$t('test_track.plan_view.test_result')" :modal="false" size="90%">
<ms-test-plan-list @addTestPlan="addTestPlan" @cancel="cancel"/>
<ms-test-plan-list @addTestPlan="addTestPlan(arguments)" @cancel="cancel" ref="testPlanList" :row="selectRows"/>
</el-drawer>
</div>
</el-card>
@ -318,7 +318,7 @@
],
principal: [],
environmentId: [],
projectEnv: []
projectEnv: [],
},
}
},
@ -496,17 +496,31 @@
cancel() {
this.planVisible = false;
},
addTestPlan(plans) {
let obj = {planIds: plans, scenarioIds: this.selection};
addTestPlan(params) {
let obj = {planIds: params[0], scenarioIds: this.selection};
obj.projectId = getCurrentProjectID();
obj.selectAllDate = this.isSelectAllDate;
obj.unSelectIds = this.unSelection;
obj = Object.assign(obj, this.condition);
// obj.projectId = getCurrentProjectID();
// obj.selectAllDate = this.isSelectAllDate;
// obj.unSelectIds = this.unSelection;
// obj = Object.assign(obj, this.condition);
// todo
if (this.isSelectAllDate) {
this.$warning("暂不支持批量添加所有场景到测试计划!");
}
this.planVisible = false;
let map = new Map();
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
obj.mapping = strMapToObj(map);
obj.envMap = strMapToObj(params[1]);
this.$post("/api/automation/scenario/plan", obj, response => {
this.$success(this.$t("commons.save_success"));
this.search();
});
},
getReport() {

View File

@ -3,9 +3,11 @@
<template v-slot:header>
<ms-table-header :is-tester-permission="true" :condition.sync="condition"
@search="initTableData" :showCreate="false"
:title="$t('test_track.plan.test_plan')"/>
:title="$t('test_track.plan.test_plan')">
</ms-table-header>
</template>
<env-popover :env-map="projectEnvMap" :project-ids="projectIds" @setProjectEnvMap="setProjectEnvMap"
:project-list="projectList" ref="envPopover" class="env-popover" style="float: right; margin-top: 4px;"/>
<el-table
border
class="adjust-table"
@ -142,7 +144,7 @@ import MsTableOperatorButton from "../../../../common/components/MsTableOperator
import MsTableOperator from "../../../../common/components/MsTableOperator";
import PlanStatusTableItem from "../../../../track/common/tableItems/plan/PlanStatusTableItem";
import PlanStageTableItem from "../../../../track/common/tableItems/plan/PlanStageTableItem";
import {checkoutTestManagerOrTestUser} from "@/common/js/utils";
import {checkoutTestManagerOrTestUser, strMapToObj} from "@/common/js/utils";
import TestReportTemplateList from "../../../../track/plan/view/comonents/TestReportTemplateList";
import TestCaseReportView from "../../../../track/plan/view/comonents/report/TestCaseReportView";
import MsDeleteConfirm from "../../../../common/components/MsDeleteConfirm";
@ -150,6 +152,7 @@ import {TEST_PLAN_CONFIGS} from "../../../../common/components/search/search-com
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
import {getCurrentProjectID} from "../../../../../../common/js/utils";
import {_filter, _sort} from "@/common/js/tableUtils";
import EnvPopover from "@/business/components/api/automation/scenario/EnvPopover";
export default {
@ -160,7 +163,10 @@ export default {
TestReportTemplateList,
PlanStageTableItem,
PlanStatusTableItem,
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination
MsTableOperator, MsTableOperatorButton, MsDialogFooter, MsTableHeader, MsCreateBox, MsTablePagination, EnvPopover
},
props: {
row: Set
},
data() {
return {
@ -187,6 +193,9 @@ export default {
{text: this.$t('test_track.plan.system_test'), value: 'system'},
{text: this.$t('test_track.plan.regression_test'), value: 'regression'},
],
projectEnvMap: new Map(),
projectList: [],
projectIds: new Set()
}
},
watch: {
@ -200,22 +209,37 @@ export default {
this.projectId = this.$route.params.projectId;
this.isTestManagerOrTestUser = checkoutTestManagerOrTestUser();
this.initTableData();
this.setScenarioSelectRows(this.row);
this.getWsProjects();
},
methods: {
confirm() {
if (this.selection.length==0) {
this.$warning(this.$t("api_test.definition.request.test_plan_select"));
}else{
this.$emit('addTestPlan', this.selection);
const sign = this.checkEnv();
if (!sign) {
return false;
}
this.$emit('addTestPlan', this.selection, this.projectEnvMap);
}
},
cancel(){
this.$emit('cancel');
},
setProjectEnvMap(projectEnvMap) {
this.projectEnvMap = projectEnvMap;
},
select(selection) {
this.selection = selection.map(s => s.id);
this.$emit('selection', selection);
},
setScenarioSelectRows(rows) {
this.projectIds.clear();
rows.forEach(row => {
row.projectIds.forEach(id => this.projectIds.add(id));
})
},
initTableData() {
if (this.planId) {
this.condition.planId = this.planId;
@ -284,6 +308,14 @@ export default {
this.$refs.testCaseReportView.open(planId, reportId);
}
},
checkEnv() {
return this.$refs.envPopover.checkEnv();
},
getWsProjects() {
this.$get("/project/listAll", res => {
this.projectList = res.data;
})
},
}
}
</script>