Merge remote-tracking branch 'origin/master'

This commit is contained in:
song.tianyang 2021-03-08 14:49:28 +08:00
commit d591bca29c
14 changed files with 113 additions and 29 deletions

View File

@ -117,6 +117,12 @@ public class ApiAutomationController {
apiAutomationService.bathEdit(request);
}
@PostMapping("/batch/update/env")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void batchUpdateEnv(@RequestBody ApiScenarioBatchRequest request) {
apiAutomationService.batchUpdateEnv(request);
}
@PostMapping("/getReference")
public ReferenceDTO getReference(@RequestBody ApiScenarioRequest request) {
return apiAutomationService.getReference(request);

View File

@ -6,6 +6,7 @@ import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@ -15,4 +16,14 @@ public class ApiScenarioBatchRequest extends ApiScenarioWithBLOBs {
private String environmentId;
private ApiScenarioRequest condition;
/**
* 环境和项目对应关系
*/
private Map<String, String> envMap;
/**
* 场景用例跨项目的关系
*/
private Map<String, List<String>> mapping;
}

View File

@ -30,7 +30,7 @@ public class MsHeaderManager extends MsTestElement {
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
HeaderManager headerManager = new HeaderManager();
headerManager.setEnabled(this.isEnable());
headerManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "HeaderManager");
headerManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "HeaderManager" : "HeaderManager");
headerManager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
headerManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HeaderPanel"));
headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->

View File

@ -306,7 +306,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
public void setHeader(HashTree tree, List<KeyValue> headers) {
HeaderManager headerManager = new HeaderManager();
headerManager.setEnabled(true);
headerManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "HeaderManager");
headerManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "HeaderManager" : "HeaderManager");
headerManager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
headerManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HeaderPanel"));
headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->

View File

@ -90,9 +90,28 @@ public class ApiAutomationService {
public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
request = this.initRequest(request, true, true);
List<ApiScenarioDTO> list = extApiScenarioMapper.list(request);
setApiScenarioProjectIds(list);
return list;
}
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
// 如果场景步骤涉及多项目则把涉及到的项目ID保存在projectIds属性
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 {
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
data.setProjectIds(idList);
});
}
/**
* 初始化部分参数
*
@ -415,6 +434,12 @@ public class ApiAutomationService {
String testPlanScenarioId = item.getId();
if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(item.getId())) {
testPlanScenarioId = request.getScenarioTestPlanIdMap().get(item.getId());
// 获取场景用例单独的执行环境
TestPlanApiScenario planApiScenario = testPlanApiScenarioMapper.selectByPrimaryKey(testPlanScenarioId);
String environment = planApiScenario.getEnvironment();
if (StringUtils.isNotBlank(environment)) {
scenario.setEnvironmentMap(JSON.parseObject(environment, Map.class));
}
}
createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(),
request.getExecuteType(), item.getProjectId(), request.getReportUserID());
@ -902,4 +927,28 @@ public class ApiAutomationService {
return resList;
}
public void batchUpdateEnv(ApiScenarioBatchRequest request) {
Map<String, String> envMap = request.getEnvMap();
Map<String, List<String>> mapping = request.getMapping();
Set<String> set = mapping.keySet();
if (set.isEmpty()) { return; }
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));
});
}
if (!newEnvMap.isEmpty()) {
ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id);
String definition = scenario.getScenarioDefinition();
JSONObject object = JSON.parseObject(definition);
object.put("environmentMap", newEnvMap);
String newDefinition = JSON.toJSONString(object);
scenario.setScenarioDefinition(newDefinition);
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
}
});
}
}

View File

@ -59,9 +59,8 @@ public class TestPlanScenarioCaseService {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
} else {
if (org.apache.commons.lang3.StringUtils.isNotBlank(d.getEnvironmentId())) {
idList.add(d.getEnvironmentId());
}
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
data.setProjectIds(idList);
});

View File

@ -27,10 +27,6 @@ CREATE TABLE IF NOT EXISTS `api_document_share` (
INDEX `share_api_id`(`share_api_id`(125)) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
-- test_case_review add coloumn
ALTER TABLE test_case_review
ADD tags VARCHAR(2000) NULL;
-- swagger_url_project
alter table swagger_url_project
modify module_id varchar(120) null;

View File

@ -151,9 +151,6 @@
</el-card>
<batch-edit ref="batchEdit" @batchEdit="batchEdit" :typeArr="typeArr" :value-arr="valueArr" :dialog-title="$t('test_track.case.batch_edit_case')">
<template v-slot:value>
<environment-select :current-data="{}" :project-id="projectId"/>
</template>
</batch-edit>
<batch-move @refresh="search" @moveSave="moveSave" ref="testBatchMove"/>
@ -166,7 +163,7 @@
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTag from "../../../common/components/MsTag";
import {downloadFile, getCurrentProjectID, getCurrentUser, getUUID} from "@/common/js/utils";
import {downloadFile, getCurrentProjectID, getCurrentUser, getUUID, strMapToObj} from "@/common/js/utils";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsTableMoreBtn from "./TableMoreBtn";
import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns";
@ -288,7 +285,8 @@
{id: 'level', name: this.$t('test_track.case.priority')},
{id: 'status', name: this.$t('test_track.plan.plan_status')},
{id: 'principal', name: this.$t('api_test.definition.request.responsible'), optionMethod: this.getPrincipalOptions},
{id: 'environmentId', name: this.$t('api_test.definition.request.run_env'), optionMethod: this.getEnvsOptions},
// {id: 'environmentId', name: this.$t('api_test.definition.request.run_env'), optionMethod: this.getEnvsOptions},
{id: 'projectEnv', name: this.$t('api_test.definition.request.run_env')},
],
statusFilters: [
{text: this.$t('test_track.plan.plan_status_prepare'), value: 'Prepare'},
@ -319,7 +317,8 @@
{name: this.$t('test_track.plan.plan_status_completed'), id: 'Completed'}
],
principal: [],
environmentId: []
environmentId: [],
projectEnv: []
},
}
},
@ -432,6 +431,7 @@
},
handleBatchEdit() {
this.$refs.batchEdit.open(this.selectDataCounts);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows);
},
handleBatchMove() {
this.$refs.testBatchMove.open(this.moduleTree, [], this.moduleOptions);
@ -446,13 +446,31 @@
});
},
batchEdit(form) {
let param = {};
param[form.type] = form.value;
this.buildBatchParam(param);
this.$post('/api/automation/batch/edit', param, () => {
this.$success(this.$t('commons.save_success'));
this.search();
});
//
if (form.type === 'projectEnv') {
let param = {};
let map = new Map();
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.mapping = strMapToObj(map);
param.envMap = strMapToObj(form.projectEnvMap);
this.$post('/api/automation/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success'));
this.search();
})
} else {
//
let param = {};
param[form.type] = form.value;
this.buildBatchParam(param);
this.$post('/api/automation/batch/edit', param, () => {
this.$success(this.$t('commons.save_success'));
this.search();
});
}
},
getPrincipalOptions(option) {
let workspaceId = localStorage.getItem(WORKSPACE_ID);

View File

@ -22,7 +22,7 @@
props: {
value: [Number, String],
duration:{},
duration: {},
edit: Boolean,
callback: Function,
isReadOnly: {
@ -51,7 +51,7 @@
this.$emit('input', value);
},
validate() {
if (Number(this.value) < 0 || this.value=='') {
if (this.value == '' || Number(this.value) <= 0) {
this.$error(this.$t('commons.formatErr'));
return false;
}

View File

@ -82,7 +82,7 @@
computed: {
isShow() {
let rt = this.assertions.duration;
return rt.value !== undefined;
return rt.value !== undefined && rt.value !== 0;
}
},
watch: {

View File

@ -202,8 +202,6 @@ export default {
let bodyFiles = this.getBodyUploadFiles();
this.api.method = this.api.request.method;
this.api.path = this.api.request.path;
console.log(this.api)
console.log(typeof (bodyFiles))
this.$fileUpload(url, null, bodyFiles, this.api, () => {
this.$success(this.$t('commons.save_success'));
this.$emit('saveApi', this.api);

View File

@ -121,7 +121,13 @@ export default {
if (this.loadType === 'resource') {
rows.forEach(row => {
this.tableData.push(row);
this.fileList.push(row);
this.tableData.push({
name: row.name,
size: (row.size / 1024).toFixed(2) + ' KB',
type: 'JMX',
updateTime: row.lastModified,
});
})
this.$success(this.$t('test_track.case.import.success'));
this.loadFileVisible = false;

View File

@ -97,6 +97,7 @@
},
open(size) {
this.dialogVisible = true;
this.projectEnvMap.clear();
if (size) {
this.size = size;
} else {

@ -1 +1 @@
Subproject commit ef5067d0de3ed940a5d31485f6370f201818dc3a
Subproject commit e4422e1dc640704febfbf469185cd85b78d2147a