refactor(接口测试): sql 添加自定义变量
This commit is contained in:
parent
0c3b154433
commit
cccb100ed0
|
@ -2,9 +2,12 @@ package io.metersphere.api.dto.scenario.request;
|
|||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@JSONType(typeName = RequestType.SQL)
|
||||
|
@ -25,4 +28,6 @@ public class SqlRequest extends Request {
|
|||
private String resultVariable;
|
||||
@JSONField(ordinal = 14)
|
||||
private String variableNames;
|
||||
@JSONField(ordinal = 15)
|
||||
private List<KeyValue> variables;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
<el-button :disabled="!request.enable || !scenario.enable || isReadOnly" class="debug-button" size="small" type="primary" @click="runDebug">{{$t('api_test.request.debug')}}</el-button>
|
||||
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane :label="$t('api_test.scenario.variables')" name="variables">
|
||||
<ms-api-scenario-variables :is-read-only="isReadOnly" :items="request.variables"
|
||||
:description="$t('api_test.scenario.kv_description')"/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('api_test.request.sql.sql_script')" name="sql">
|
||||
<div class="sql-content" >
|
||||
<ms-code-edit mode="sql" :read-only="isReadOnly" :modes="['sql']" :data.sync="request.query" theme="eclipse" ref="codeEdit"/>
|
||||
|
@ -74,10 +78,12 @@
|
|||
import MsDubboConsumerService from "@/business/components/api/test/components/request/dubbo/ConsumerAndService";
|
||||
import MsJsr233Processor from "../processor/Jsr233Processor";
|
||||
import MsCodeEdit from "../../../../common/components/MsCodeEdit";
|
||||
import MsApiScenarioVariables from "../ApiScenarioVariables";
|
||||
|
||||
export default {
|
||||
name: "MsApiSqlRequestForm",
|
||||
components: {
|
||||
MsApiScenarioVariables,
|
||||
MsCodeEdit,
|
||||
MsJsr233Processor,
|
||||
MsDubboConsumerService,
|
||||
|
@ -96,7 +102,7 @@
|
|||
|
||||
data() {
|
||||
return {
|
||||
activeName: "sql",
|
||||
activeName: "variables",
|
||||
databaseConfigsOptions: [],
|
||||
rules: {
|
||||
name: [
|
||||
|
|
|
@ -477,6 +477,7 @@ export class SqlRequest extends Request {
|
|||
this.useEnvironment = options.useEnvironment;
|
||||
this.resultVariable = options.resultVariable;
|
||||
this.variableNames = options.variableNames;
|
||||
this.variables = options.variables || [];
|
||||
this.debugReport = undefined;
|
||||
this.dataSource = options.dataSource;
|
||||
this.query = options.query;
|
||||
|
@ -1127,6 +1128,7 @@ class JMXGenerator {
|
|||
} else if (request instanceof SqlRequest) {
|
||||
request.dataSource = scenario.databaseConfigMap.get(request.dataSource);
|
||||
sampler = new JDBCSampler(request.name || "", request);
|
||||
this.addRequestVariables(sampler, request);
|
||||
} else if (request instanceof TCPRequest) {
|
||||
sampler = new TCPSampler(request.name || "", new JMXTCPRequest(request, scenario));
|
||||
}
|
||||
|
@ -1188,6 +1190,14 @@ class JMXGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
addRequestVariables(httpSamplerProxy, request) {
|
||||
let name = request.name + " Variables";
|
||||
let variables = this.filterKV(request.variables);
|
||||
if (variables && variables.length > 0) {
|
||||
httpSamplerProxy.put(new Arguments(name, variables));
|
||||
}
|
||||
}
|
||||
|
||||
addScenarioCookieManager(threadGroup, scenario) {
|
||||
if (scenario.enableCookieShare) {
|
||||
threadGroup.put(new CookieManager(scenario.name));
|
||||
|
|
Loading…
Reference in New Issue