fix: 优化脚本编写域、修复旧Mock环境数据引起的报错、修复测试计划无法关联接口和案例的问题

优化脚本编写域、修复旧Mock环境数据引起的报错、修复测试计划无法关联接口和案例的问题
This commit is contained in:
song-tianyang 2021-04-23 14:16:17 +08:00 committed by 刘瑞斌
parent d65a0a3b7b
commit d984187f12
3 changed files with 59 additions and 23 deletions

View File

@ -88,6 +88,34 @@ public class ApiTestEnvironmentService {
this.add(returnModel);
} else {
returnModel = list.get(0);
returnModel = this.checkMockEvnIsRightful(returnModel, projectId, apiName, baseUrl);
}
return returnModel;
}
private ApiTestEnvironmentWithBLOBs checkMockEvnIsRightful(ApiTestEnvironmentWithBLOBs returnModel, String projectId, String name, String url) {
boolean needUpdate = true;
if (returnModel.getConfig() != null) {
try {
JSONObject configObj = JSONObject.parseObject(returnModel.getConfig());
if (configObj.containsKey("httpConfig")) {
JSONObject httpObj = configObj.getJSONObject("httpConfig");
if (httpObj.containsKey("isMock") && httpObj.getBoolean("isMock")) {
if (httpObj.containsKey("conditions")) {
JSONArray conditions = httpObj.getJSONArray("conditions");
needUpdate = false;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (needUpdate) {
String id = returnModel.getId();
returnModel = this.genHttpApiTestEnvironmentByUrl(projectId, name, url);
returnModel.setId(id);
apiTestEnvironmentMapper.updateByPrimaryKeyWithBLOBs(returnModel);
}
return returnModel;
}

View File

@ -1,15 +1,5 @@
<template>
<div>
<el-row style="margin:0px 10px 10px">
<el-col>
<div class="document-url">
<el-link href="https://jmeter.apache.org/usermanual/component_reference.html#BeanShell_PostProcessor"
target="componentReferenceDoc"
type="primary">{{$t('commons.reference_documentation')}}
</el-link>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="20" class="script-content">
<ms-code-edit v-if="isCodeEditAlive" :mode="codeEditModeMap[jsr223ProcessorData.scriptLanguage]"
@ -18,11 +8,16 @@
ref="codeEdit"/>
</el-col>
<el-col :span="4" class="script-index">
<ms-dropdown :default-command="jsr223ProcessorData.scriptLanguage" :commands="languages" @command="languageChange"/>
<div class="template-title">{{$t('api_test.request.processor.code_template')}}</div>
<ms-dropdown :default-command="jsr223ProcessorData.scriptLanguage" :commands="languages"
@command="languageChange"/>
<div class="template-title">{{ $t('api_test.request.processor.code_template') }}</div>
<div v-for="(template, index) in codeTemplates" :key="index" class="code-template">
<el-link :disabled="template.disabled" @click="addTemplate(template)">{{template.title}}</el-link>
<el-link :disabled="template.disabled" @click="addTemplate(template)">{{ template.title }}</el-link>
</div>
<el-link href="https://jmeter.apache.org/usermanual/component_reference.html#BeanShell_PostProcessor"
target="componentReferenceDoc" style="margin-top: 10px"
type="primary">{{ $t('commons.reference_documentation') }}
</el-link>
</el-col>
</el-row>
</div>
@ -162,7 +157,7 @@
.script-content {
height: calc(100vh - 570px);
min-height: 250px;
min-height: 300px;
}
.script-index {

View File

@ -125,26 +125,39 @@
saveCaseRelevance() {
let param = {};
let url = '';
let environmentId = undefined;
let selectIds = [];
if (this.isApiListEnable) {
//
let params = this.$refs.apiList.getConditions();
this.result = this.$post("/api/definition/list/batch", params, (response) => {
let apis = response.data;
url = '/api/definition/relevance';
environmentId = this.$refs.apiList.environmentId;
selectIds = Array.from(this.$refs.apiList.selectRows).map(row => row.id);
selectIds = Array.from(apis).map(row => row.id);
this.postRelevance(url, environmentId, selectIds);
});
} else {
let params = this.$refs.apiCaseList.getConditions();
this.result = this.$post("/api/testcase/get/caseBLOBs/request", params, (response) => {
let apiCases = response.data;
url = '/api/testcase/relevance';
environmentId = this.$refs.apiCaseList.environmentId;
selectIds = Array.from(this.$refs.apiCaseList.selectRows).map(row => row.id);
selectIds = Array.from(apiCases).map(row => row.id);
this.postRelevance(url, environmentId, selectIds);
});
}
},
postRelevance(url, environmentId, selectIds) {
let param = {};
if (!environmentId) {
this.$warning(this.$t('api_test.environment.select_environment'));
return;
}
param.planId = this.planId;
param.selectIds = selectIds;
param.environmentId = environmentId;