fix(接口定义): http 协议headers 收入到请求中

This commit is contained in:
fit2-zhao 2020-12-02 14:21:17 +08:00
parent 529b003c2b
commit d571c9dc07
11 changed files with 60 additions and 46 deletions

View File

@ -19,6 +19,8 @@ import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments; import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.http.control.Header;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.protocol.http.util.HTTPArgument; import org.apache.jmeter.protocol.http.util.HTTPArgument;
import org.apache.jmeter.protocol.http.util.HTTPFileArg; import org.apache.jmeter.protocol.http.util.HTTPFileArg;
@ -80,6 +82,8 @@ public class MsHTTPSamplerProxy extends MsTestElement {
@JSONField(ordinal = 23) @JSONField(ordinal = 23)
private String useEnvironment; private String useEnvironment;
@JSONField(ordinal = 24)
private List<KeyValue> headers;
public void toHashTree(HashTree tree, List<MsTestElement> hashTree) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree) {
HTTPSamplerProxy sampler = new HTTPSamplerProxy(); HTTPSamplerProxy sampler = new HTTPSamplerProxy();
@ -174,7 +178,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
final HashTree httpSamplerTree = tree.add(sampler); final HashTree httpSamplerTree = tree.add(sampler);
setHeader(httpSamplerTree);
//判断是否要开启DNS //判断是否要开启DNS
if (config != null && config.getCommonConfig() != null && config.getCommonConfig().isEnableHost()) { if (config != null && config.getCommonConfig() != null && config.getCommonConfig().isEnableHost()) {
MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config); MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config);
@ -244,6 +248,19 @@ public class MsHTTPSamplerProxy extends MsTestElement {
return list.toArray(new HTTPFileArg[0]); return list.toArray(new HTTPFileArg[0]);
} }
public void setHeader(HashTree tree) {
HeaderManager headerManager = new HeaderManager();
headerManager.setEnabled(true);
headerManager.setName(this.getName() + "Headers");
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 ->
headerManager.add(new Header(keyValue.getName(), keyValue.getValue()))
);
tree.add(headerManager);
}
private boolean isRest() { private boolean isRest() {
return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0; return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0;
} }

View File

@ -136,7 +136,7 @@
<div v-if="item.active"> <div v-if="item.active">
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p> <p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<ms-api-request-form :is-read-only="isReadOnly" :headers="item.request.hashTree[0].headers " :request="item.request" v-if="api.protocol==='HTTP'"/> <ms-api-request-form :is-read-only="isReadOnly" :headers="item.request.headers " :request="item.request" v-if="api.protocol==='HTTP'"/>
<ms-tcp-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='TCP'"/> <ms-tcp-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='TCP'"/>
<ms-sql-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='SQL'"/> <ms-sql-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='SQL'"/>
<ms-dubbo-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='DUBBO'"/> <ms-dubbo-basis-parameters :request="item.request" :currentProject="currentProject" v-if="api.protocol==='DUBBO'"/>
@ -463,6 +463,7 @@
caseChecked(row) { caseChecked(row) {
row.type = "CASE"; row.type = "CASE";
row.protocol = this.api.protocol; row.protocol = this.api.protocol;
row.hashTree = [];
if (this.checkedCases.has(row)) { if (this.checkedCases.has(row)) {
this.checkedCases.delete(row); this.checkedCases.delete(row);
} else { } else {

View File

@ -2,17 +2,17 @@
<div class="card-container"> <div class="card-container">
<!-- HTTP 请求参数 --> <!-- HTTP 请求参数 -->
<ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" :request="request" :headers="headers" :response="response" <ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" :request="request" :response="response"
:basisData="currentApi" :moduleOptions="moduleOptions" :currentProject="currentProject" v-if="currentProtocol === 'HTTP'"/> :basisData="currentApi" :moduleOptions="moduleOptions" :currentProject="currentProject" v-if="currentProtocol === 'HTTP'"/>
<!-- TCP --> <!-- TCP -->
<ms-edit-complete-tcp-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi" <ms-edit-complete-tcp-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'TCP'"/> :moduleOptions="moduleOptions" v-if="currentProtocol === 'TCP'"/>
<!--DUBBO--> <!--DUBBO-->
<ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi" <ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'DUBBO'"/> :moduleOptions="moduleOptions" v-if="currentProtocol === 'DUBBO'"/>
<!--SQL--> <!--SQL-->
<ms-edit-complete-sql-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi" <ms-edit-complete-sql-api :request="request" @runTest="runTest" @saveApi="saveApi" :currentProject="currentProject" :basisData="currentApi"
:moduleOptions="moduleOptions" v-if="currentProtocol === 'SQL'"/> :moduleOptions="moduleOptions" v-if="currentProtocol === 'SQL'"/>
</div> </div>
</template> </template>
@ -39,7 +39,6 @@
request: Sampler, request: Sampler,
config: {}, config: {},
response: {}, response: {},
headers: [],
maintainerOptions: [], maintainerOptions: [],
} }
}, },
@ -121,11 +120,8 @@
if (this.currentApi.request != undefined && this.currentApi.request != null) { if (this.currentApi.request != undefined && this.currentApi.request != null) {
this.request = JSON.parse(this.currentApi.request); this.request = JSON.parse(this.currentApi.request);
this.currentApi.request = this.request; this.currentApi.request = this.request;
this.headers = this.request.hashTree[0].headers;
} else { } else {
let header = createComponent("HeaderManager");
this.request = createComponent("HTTPSamplerProxy"); this.request = createComponent("HTTPSamplerProxy");
this.request.hashTree = [header];
this.currentApi.request = this.request; this.currentApi.request = this.request;
} }
}, },
@ -140,9 +136,6 @@
}, },
setParameters(data) { setParameters(data) {
data.projectId = this.currentProject.id; data.projectId = this.currentProject.id;
if (this.currentProtocol === 'HTTP') {
this.request.hashTree[0].headers = this.headers;
}
this.request.name = this.currentApi.name; this.request.name = this.currentApi.name;
data.protocol = this.currentProtocol; data.protocol = this.currentProtocol;
data.request = this.request; data.request = this.request;

View File

@ -198,6 +198,7 @@
}, },
handleSelect(selection, row) { handleSelect(selection, row) {
row.type = "API"; row.type = "API";
row.hashTree = [];
if (this.selectRows.has(row)) { if (this.selectRows.has(row)) {
this.$set(row, "showMore", false); this.$set(row, "showMore", false);
this.selectRows.delete(row); this.selectRows.delete(row);
@ -207,7 +208,9 @@
} }
let arr = Array.from(this.selectRows); let arr = Array.from(this.selectRows);
this.currentRow.apis = arr; if (this.currentRow) {
this.currentRow.apis = arr;
}
// 1 // 1
if (this.selectRows.size === 1) { if (this.selectRows.size === 1) {
this.$set(arr[0], "showMore", false); this.$set(arr[0], "showMore", false);
@ -221,10 +224,12 @@
if (selection.length > 0) { if (selection.length > 0) {
if (selection.length === 1) { if (selection.length === 1) {
selection.type = "API"; selection.type = "API";
selection.hashTree = [];
this.selectRows.add(selection[0]); this.selectRows.add(selection[0]);
} else { } else {
this.tableData.forEach(item => { this.tableData.forEach(item => {
item.type = "API"; item.type = "API";
item.hashTree = [];
this.$set(item, "showMore", true); this.$set(item, "showMore", true);
this.selectRows.add(item); this.selectRows.add(item);
}); });
@ -235,8 +240,10 @@
this.$set(row, "showMore", false); this.$set(row, "showMore", false);
}) })
} }
let arr = Array.from(this.selectRows); if (this.currentRow) {
this.currentRow.apis = arr; let arr = Array.from(this.selectRows);
this.currentRow.apis = arr;
}
}, },
search() { search() {
this.initApiTable(); this.initApiTable();

View File

@ -135,10 +135,8 @@
} }
}, },
initHTTP() { initHTTP() {
let header = createComponent("HeaderManager");
let request = createComponent("HTTPSamplerProxy"); let request = createComponent("HTTPSamplerProxy");
request.path = this.httpForm.path; request.path = this.httpForm.path;
request.hashTree = [header];
this.httpForm.request = request; this.httpForm.request = request;
}, },
initSQL() { initSQL() {

View File

@ -61,7 +61,7 @@
<!-- 请求参数 --> <!-- 请求参数 -->
<div> <div>
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p> <p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<ms-api-request-form :request="request" :headers="headers" :isShowEnable="isShowEnable"/> <ms-api-request-form :request="request" :headers="request.headers" :isShowEnable="isShowEnable"/>
</div> </div>
</el-form> </el-form>
@ -103,7 +103,7 @@
options: API_STATUS, options: API_STATUS,
} }
}, },
props: {moduleOptions: {}, currentProject: {}, headers: Array, request: {}, response: {}, basisData: {}}, props: {moduleOptions: {}, currentProject: {}, request: {}, response: {}, basisData: {}},
methods: { methods: {
runTest() { runTest() {
if (this.currentProject === null) { if (this.currentProject === null) {

View File

@ -26,12 +26,12 @@
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p> <p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<!-- HTTP 请求参数 --> <!-- HTTP 请求参数 -->
<ms-api-request-form :headers="headers" :request="request"/> <ms-api-request-form :headers="request.headers" :request="request"/>
</el-form> </el-form>
<!-- HTTP 请求返回数据 --> <!-- HTTP 请求返回数据 -->
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p> <p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
<ms-request-result-tail :response="responseData" ref="debugResult"/> <ms-request-result-tail :response="responseData" ref="debugResult"/>
<!-- 执行组件 --> <!-- 执行组件 -->
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/> <ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
@ -69,27 +69,13 @@
loading: false, loading: false,
debugResultId: "", debugResultId: "",
runData: [], runData: [],
headers: [],
reportId: "", reportId: "",
reqOptions: REQ_METHOD, reqOptions: REQ_METHOD,
request: {}, request: {},
} }
}, },
created() { created() {
switch (this.protocol) { this.createHttp();
case Request.TYPES.SQL:
this.request = createComponent("SQL");
break;
case Request.TYPES.DUBBO:
this.request = createComponent("JDBCSampler");
break;
case Request.TYPES.TCP:
this.request = createComponent("TCPSampler");
break;
default:
this.createHttp();
break;
}
}, },
watch: { watch: {
debugResultId() { debugResultId() {
@ -105,9 +91,7 @@
} }
}, },
createHttp() { createHttp() {
let header = createComponent("HeaderManager");
this.request = createComponent("HTTPSamplerProxy"); this.request = createComponent("HTTPSamplerProxy");
this.request.hashTree = [header];
}, },
runDebug() { runDebug() {
this.$refs['debugForm'].validate((valid) => { this.$refs['debugForm'].validate((valid) => {
@ -115,7 +99,6 @@
this.loading = true; this.loading = true;
this.request.url = this.debugForm.url; this.request.url = this.debugForm.url;
this.request.method = this.debugForm.method; this.request.method = this.debugForm.method;
this.request.hashTree[0].headers = this.headers;
this.request.name = getUUID().substring(0, 8); this.request.name = getUUID().substring(0, 8);
this.runData = []; this.runData = [];
this.runData.push(this.request); this.runData.push(this.request);

View File

@ -36,6 +36,7 @@ export default class HTTPSamplerProxy extends Sampler {
this.arguments = []; this.arguments = [];
this.rest = []; this.rest = [];
this.files = []; this.files = [];
this.headers = [];
} }
} }

View File

@ -59,7 +59,7 @@
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p> <p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<!-- HTTP 请求参数 --> <!-- HTTP 请求参数 -->
<ms-api-request-form :headers="api.request.hashTree[0].headers" :request="api.request"/> <ms-api-request-form :headers="api.request.headers" :request="api.request"/>
</el-form> </el-form>
<!--返回结果--> <!--返回结果-->

View File

@ -34,8 +34,6 @@
:currentProject="currentProject" :loaded="loaded" :currentProject="currentProject" :loaded="loaded"
ref="caseList"/> ref="caseList"/>
</el-drawer> </el-drawer>
>
<!-- 环境 --> <!-- 环境 -->
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/> <api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
<!-- 执行组件 --> <!-- 执行组件 -->

View File

@ -197,6 +197,16 @@ export class Test extends BaseConfig {
} }
} }
export class ScenarioObj extends BaseConfig {
constructor(options = {}) {
super();
this.id = undefined;
this.name = undefined;
this.type = "scenario";
this.hashTree = [];
}
}
export class Scenario extends BaseConfig { export class Scenario extends BaseConfig {
constructor(options = {}) { constructor(options = {}) {
super(); super();
@ -761,6 +771,7 @@ export class KeyValue extends BaseConfig {
export class Assertions extends BaseConfig { export class Assertions extends BaseConfig {
constructor(options) { constructor(options) {
super(); super();
this.resourceId = uuid();
this.type = "Assertions"; this.type = "Assertions";
this.text = []; this.text = [];
this.regex = []; this.regex = [];
@ -830,6 +841,8 @@ export class BeanShellProcessor extends BaseConfig {
export class JSR223Processor extends BaseConfig { export class JSR223Processor extends BaseConfig {
constructor(options) { constructor(options) {
super(); super();
this.resourceId = uuid();
this.active = false;
this.type = "JSR223Processor"; this.type = "JSR223Processor";
this.script = undefined; this.script = undefined;
this.language = "beanshell"; this.language = "beanshell";
@ -902,6 +915,7 @@ export class Duration extends AssertionType {
export class Extract extends BaseConfig { export class Extract extends BaseConfig {
constructor(options) { constructor(options) {
super(); super();
this.resourceId = uuid();
this.type = "Extract"; this.type = "Extract";
this.regex = []; this.regex = [];
this.json = []; this.json = [];
@ -969,6 +983,7 @@ export class Controller extends BaseConfig {
super(); super();
this.type = type this.type = type
options.id = options.id || uuid(); options.id = options.id || uuid();
options.resourceId = options.resourceId || uuid();
options.enable = options.enable === undefined ? true : options.enable; options.enable = options.enable === undefined ? true : options.enable;
} }
} }
@ -980,7 +995,7 @@ export class IfController extends Controller {
this.variable; this.variable;
this.operator; this.operator;
this.value; this.value;
this.children=[]; this.hashTree = [];
this.set(options); this.set(options);
} }
@ -1011,6 +1026,7 @@ export class Timer extends BaseConfig {
super(); super();
this.type = type; this.type = type;
options.id = options.id || uuid(); options.id = options.id || uuid();
options.resourceId = options.resourceId || uuid();
options.enable = options.enable === undefined ? true : options.enable; options.enable = options.enable === undefined ? true : options.enable;
} }
} }
@ -1020,7 +1036,7 @@ export class ConstantTimer extends Timer {
super(Timer.TYPES.CONSTANT_TIMER, options); super(Timer.TYPES.CONSTANT_TIMER, options);
this.delay; this.delay;
this.type = "ConstantTimer"; this.type = "ConstantTimer";
this.children=[]; this.hashTree = [];
this.set(options); this.set(options);
} }