feat(接口定义):添加协议处理

This commit is contained in:
fit2-zhao 2020-11-24 10:42:21 +08:00
parent 4bae9662de
commit c6a981e965
14 changed files with 100 additions and 58 deletions

View File

@ -11,8 +11,6 @@ public class ApiDefinitionResult extends ApiDefinition {
private String projectName;
private String url;
private String userName;
private String caseTotal;

View File

@ -20,6 +20,8 @@ public class SaveApiDefinitionRequest {
private String name;
private String path;
private String protocol;
private String moduleId;

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.scenario.request.RequestType;
import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.api.jmeter.TestResult;
import io.metersphere.base.domain.*;
@ -141,9 +142,16 @@ public class ApiDefinitionService {
private void checkNameExist(SaveApiDefinitionRequest request) {
ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andProtocolEqualTo(request.getProtocol()).andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("api_definition_url_not_repeating"));
if (request.getProtocol().equals(RequestType.HTTP)) {
example.createCriteria().andProtocolEqualTo(request.getProtocol()).andPathEqualTo(request.getPath()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("api_definition_url_not_repeating"));
}
} else {
example.createCriteria().andProtocolEqualTo(request.getProtocol()).andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
if (apiDefinitionMapper.countByExample(example) > 0) {
MSException.throwException(Translator.get("load_test_already_exists"));
}
}
}
@ -153,6 +161,7 @@ public class ApiDefinitionService {
final ApiDefinition test = new ApiDefinition();
test.setId(request.getId());
test.setName(request.getName());
test.setPath(request.getPath());
test.setProjectId(request.getProjectId());
test.setRequest(JSONObject.toJSONString(request.getRequest()));
test.setUpdateTime(System.currentTimeMillis());
@ -177,6 +186,7 @@ public class ApiDefinitionService {
test.setName(request.getName());
test.setProtocol(request.getProtocol());
test.setMethod(request.getMethod());
test.setPath(request.getPath());
test.setModuleId(request.getModuleId());
test.setProjectId(request.getProjectId());
test.setRequest(JSONObject.toJSONString(request.getRequest()));

View File

@ -14,6 +14,8 @@ public class ApiDefinition implements Serializable {
private String method;
private String path;
private String protocol;
private String environmentId;

View File

@ -264,6 +264,12 @@ public class ApiDefinitionExample {
return (Criteria) this;
}
public Criteria andPathEqualTo(String value) {
addCriterion("path =", value, "path");
return (Criteria) this;
}
public Criteria andProtocolEqualTo(String value) {
addCriterion("protocol =", value, "protocol");
return (Criteria) this;

View File

@ -8,6 +8,7 @@
<result column="module_path" jdbcType="VARCHAR" property="modulePath"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="protocol" jdbcType="VARCHAR" property="protocol"/>
<result column="path" jdbcType="VARCHAR" property="path"/>
<result column="method" jdbcType="VARCHAR" property="method"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
@ -80,7 +81,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, project_id, name,module_id,module_path,protocol ,method ,description, status, user_id, create_time, update_time
id, project_id, name,module_id,module_path,protocol ,path,method ,description, status, user_id, create_time, update_time
</sql>
<sql id="Blob_Column_List">
request
@ -204,7 +205,7 @@
<select id="list" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
select api_definition.id, api_definition.project_id,
api_definition.name,api_definition.protocol,api_definition.module_id,api_definition.module_path,api_definition.method,
api_definition.name,api_definition.protocol,api_definition.path,api_definition.module_id,api_definition.module_path,api_definition.method,
api_definition.description,api_definition.request,api_definition.response,api_definition.environment_id,
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time, project.name as
project_name, user.name as user_name
@ -306,10 +307,10 @@
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDefinition">
insert into api_definition (id, project_id, name, protocol,module_id,module_path,method,
insert into api_definition (id, project_id, name, protocol,path,module_id,module_path,method,
description, status, user_id,create_time, update_time, request,response,environment_id )
values
(#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR},#{modulePath,jdbcType=VARCHAR},#{method,jdbcType=VARCHAR},
(#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{protocol,jdbcType=VARCHAR},#{path,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR},#{modulePath,jdbcType=VARCHAR},#{method,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{request,jdbcType=LONGVARCHAR},#{response,jdbcType=LONGVARCHAR},#{environmentId,jdbcType=VARCHAR}
)
@ -334,10 +335,13 @@
</if>
<if test="moduleId != null">
module_id = #{moduleId,jdbcType=BIGINT},
module_id = #{moduleId,jdbcType=VARCHAR},
</if>
<if test="protocol != null">
protocol = #{protocol,jdbcType=LONGVARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
</if>
<if test="path != null">
path = #{path,jdbcType=VARCHAR},
</if>
<if test="method != null">
method = #{method,jdbcType=VARCHAR},
@ -382,6 +386,7 @@
module_id = #{moduleId,jdbcType=VARCHAR},
module_path = #{modulePath,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
path = #{path,jdbcType=VARCHAR},
method = #{method,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
@ -396,6 +401,7 @@
name = #{name,jdbcType=VARCHAR},
module_id = #{moduleId,jdbcType=VARCHAR},
protocol = #{protocol,jdbcType=VARCHAR},
path = #{path,jdbcType=VARCHAR},
module_path = #{modulePath,jdbcType=VARCHAR},
method = #{method,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},

View File

@ -117,6 +117,7 @@
this.apiTabs = [];
this.apiDefaultTab = tabs.name;
this.apiTabs.push(tabs);
this.refresh();
}
else {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
@ -138,6 +139,7 @@
}
this.apiDefaultTab = activeName;
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
this.refresh();
} else {
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');

View File

@ -4,10 +4,10 @@
<el-header style="width: 100% ;padding: 0px">
<el-card>
<el-row>
<el-col :span="3">
<el-col :span="api.protocol==='HTTP'? 3:5">
<div class="variable-combine"> {{api.name}}</div>
</el-col>
<el-col :span="1">
<el-col :span="api.protocol==='HTTP'? 1:3">
<template>
<div>
<ms-tag v-if="api.status == 'Prepare'" type="info"
@ -19,11 +19,11 @@
</div>
</template>
</el-col>
<el-col :span="4">
<div class="variable-combine">{{api.url ===undefined ? "暂无路径" : api.url}}</div>
<el-col :span="api.protocol==='HTTP'? 4:0">
<div class="variable-combine">{{api.path ===null ? " " : api.path}}</div>
</el-col>
<el-col :span="2">
<div>{{$t('test_track.plan_view.case_count')}}5</div>
<div>{{$t('test_track.plan_view.case_count')}}{{apiCaseList.length}}</div>
</el-col>
<el-col :span="4">
<div>

View File

@ -4,7 +4,7 @@
<!-- HTTP 请求参数 -->
<ms-add-complete-http-api @runTest="runTest" @saveApi="saveApi" :request="request" :headers="headers" :response="response" :basisData="currentApi"
:moduleOptions="moduleOptions" :currentProject="currentProject"
v-if="reqType === 'HTTP'"></ms-add-complete-http-api>
v-if="currentProtocol === 'HTTP'"/>
</div>
</template>
@ -21,7 +21,6 @@
components: {MsAddCompleteHttpApi},
data() {
return {
reqType: Request.TYPES.HTTP,
reqUrl: "",
request: Sampler,
response: {},
@ -56,7 +55,6 @@
}
if (this.currentApi != null && this.currentApi.id != null) {
this.reqUrl = "/api/definition/update";
this.currentApi.url = this.request.path;
} else {
this.reqUrl = "/api/definition/create";
this.currentApi.id = getUUID().substring(0, 8);
@ -64,10 +62,7 @@
},
methods: {
runTest(data) {
data.projectId = this.currentProject.id;
this.request.hashTree[0].headers = this.headers;
data.request = this.request;
data.response = this.response;
this.setParameters(data);
let bodyFiles = this.getBodyUploadFiles(data);
this.$fileUpload(this.reqUrl, null, bodyFiles, data, () => {
this.$success(this.$t('commons.save_success'));
@ -88,10 +83,7 @@
}
},
saveApi(data) {
data.projectId = this.currentProject.id;
this.request.hashTree[0].headers = this.headers;
data.request = this.request;
data.response = this.response;
this.setParameters(data);
let bodyFiles = this.getBodyUploadFiles(data);
this.$fileUpload(this.reqUrl, null, bodyFiles, data, () => {
this.$success(this.$t('commons.save_success'));
@ -100,6 +92,12 @@
});
},
setParameters(data) {
data.projectId = this.currentProject.id;
this.request.hashTree[0].headers = this.headers;
data.request = this.request;
data.response = this.response;
},
getBodyUploadFiles(data) {
let bodyUploadFiles = [];
data.bodyUploadIds = [];

View File

@ -44,10 +44,10 @@
</template>
</el-table-column>
<!--<el-table-column-->
<!--prop="url"-->
<!--:label="$t('api_test.definition.api_path')"-->
<!--show-overflow-tooltip/>-->
<el-table-column
prop="path"
:label="$t('api_test.definition.api_path')"
show-overflow-tooltip/>
<el-table-column
prop="userName"
@ -153,12 +153,15 @@
watch: {
currentProject() {
this.initApiTable();
this.apiCaseClose();
},
currentModule() {
this.initApiTable();
this.apiCaseClose();
},
currentProtocol() {
this.initApiTable();
this.apiCaseClose();
}
},
methods: {

View File

@ -87,7 +87,7 @@
</template>
<script>
import MsAddBasisHttpApi from "./basis/AddBasisHttpApi";
import MsAddBasisHttpApi from "./basis/AddBasisApi";
import SelectMenu from "../../../track/common/SelectMenu";
import {OPTIONS, DEFAULT_DATA} from "../model/JsonData";

View File

@ -7,8 +7,9 @@
<el-input v-model="httpForm.name" autocomplete="off" :placeholder="$t('commons.name')"/>
</el-form-item>
<el-form-item :label="$t('api_report.request')" prop="url" v-if="currentProtocol==='HTTP'">
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.url"
<!--HTTP 协议特有参数-->
<el-form-item :label="$t('api_report.request')" prop="path" v-if="currentProtocol==='HTTP'">
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.path"
class="ms-http-input" size="small">
<el-select v-model="httpForm.method" slot="prepend" style="width: 100px" size="small">
<el-option v-for="item in options" :key="item.id" :label="item.label" :value="item.id"/>
@ -16,7 +17,6 @@
</el-input>
</el-form-item>
<el-form-item :label="$t('api_test.definition.request.responsible')" prop="userId">
<el-select v-model="httpForm.userId"
:placeholder="$t('api_test.definition.request.responsible')" filterable size="small"
@ -57,11 +57,10 @@
import {WORKSPACE_ID} from '../../../../../../common/js/constants';
import {REQ_METHOD} from "../../model/JsonData";
import {getCurrentUser, getUUID} from "../../../../../../common/js/utils";
import {createComponent} from "../jmeter/components";
import {createComponent,Request} from "../jmeter/components";
import HeaderManager from "../jmeter/components/configurations/header-manager";
export default {
name: "MsAddBasisHttpApi",
name: "MsAddBasisApi",
components: {MsDialogFooter},
props: {
currentProtocol: {
@ -81,7 +80,7 @@
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'}
],
url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
path: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
},
value: REQ_METHOD[0].id,
@ -93,25 +92,17 @@
this.$refs['httpForm'].validate((valid) => {
if (valid) {
let bodyFiles = [];
let url = "/api/definition/create";
this.httpForm.bodyUploadIds = [];
this.httpForm.projectId = this.projectId;
this.httpForm.id = getUUID().substring(0, 8);
this.httpForm.protocol = this.currentProtocol;
let path = "/api/definition/create";
this.setParameter();
let header = createComponent("HeaderManager");
let request = createComponent("HTTPSamplerProxy");
request.path = this.httpForm.url;
request.path = this.httpForm.path;
request.hashTree = [header];
this.httpForm.request = request;
if (this.currentModule != null) {
this.httpForm.modulePath = this.currentModule.method != undefined ? this.currentModule.method : null;
this.httpForm.moduleId = this.currentModule.id;
}
this.result = this.$fileUpload(url, null, bodyFiles, this.httpForm, () => {
this.result = this.$fileUpload(path, null, bodyFiles, this.httpForm, () => {
this.httpVisible = false;
if (saveAs) {
this.httpForm.request = JSON.stringify(request);
console.log(this.httpForm)
this.$parent.saveAsEdit(this.httpForm);
} else {
this.$parent.refresh(this.currentModule);
@ -122,6 +113,29 @@
}
})
},
setParameter() {
this.httpForm.bodyUploadIds = [];
this.httpForm.projectId = this.projectId;
this.httpForm.id = getUUID().substring(0, 8);
this.httpForm.protocol = this.currentProtocol;
if (this.currentModule != null) {
this.httpForm.modulePath = this.currentModule.method != undefined ? this.currentModule.method : null;
this.httpForm.moduleId = this.currentModule.id;
}
switch (this.currentProtocol) {
case Request.TYPES.SQL:
this.httpForm.method = Request.TYPES.SQL;
break;
case Request.TYPES.DUBBO:
this.httpForm.method = "dubbo://";
break;
case Request.TYPES.TCP:
this.httpForm.method = Request.TYPES.TCP;
break;
default:
break;
}
},
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => {

View File

@ -21,10 +21,10 @@
</el-select>
</el-form-item>
<el-form-item :label="$t('api_report.request')" prop="url">
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.url"
<el-form-item :label="$t('api_report.request')" prop="path">
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.path"
class="ms-http-input" size="small" style="margin-top: 5px">
<el-select v-model="request.method" slot="prepend" style="width: 100px" size="small">
<el-select v-model="httpForm.method" slot="prepend" style="width: 100px" size="small">
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
</el-select>
</el-input>
@ -90,7 +90,7 @@
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'}
],
url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
path: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
moduleId: [{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
status: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
@ -127,7 +127,8 @@
},
setParameter() {
this.httpForm.modulePath = this.getPath(this.httpForm.moduleId);
this.request.path = this.httpForm.url;
this.request.path = this.httpForm.path;
this.request.method = this.httpForm.method;
this.httpForm.request.useEnvironment = undefined;
},
saveApi() {

View File

@ -35,7 +35,7 @@ export const API_METHOD_COLOUR = [
['GET', "#61AFFE"], ['POST', '#49CC90'], ['PUT', '#fca130'],
['PATCH', '#E2EE11'], ['DELETE', '#f93e3d'], ['OPTIONS', '#0EF5DA'],
['HEAD', '#8E58E7'], ['CONNECT', '#90AFAE'],
['DUBBO', '#C36EEF'], ['SQL', '#0AEAD4'], ['TCP', '#0A52DF'],
['DUBBO', '#C36EEF'], ['dubbo://', '#C36EEF'],['SQL', '#0AEAD4'], ['TCP', '#0A52DF'],
]
export const REQUIRED = [
@ -47,4 +47,4 @@ export const RESULT_MAP = new Map([
['success','执行结果:通过'],
['error','执行结果:未通过'],
['default','执行结果:未执行']
]);
]);