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

View File

@ -136,7 +136,7 @@
<div v-if="item.active">
<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-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'"/>
@ -463,6 +463,7 @@
caseChecked(row) {
row.type = "CASE";
row.protocol = this.api.protocol;
row.hashTree = [];
if (this.checkedCases.has(row)) {
this.checkedCases.delete(row);
} else {

View File

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

View File

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

View File

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

View File

@ -61,7 +61,7 @@
<!-- 请求参数 -->
<div>
<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>
</el-form>
@ -103,7 +103,7 @@
options: API_STATUS,
}
},
props: {moduleOptions: {}, currentProject: {}, headers: Array, request: {}, response: {}, basisData: {}},
props: {moduleOptions: {}, currentProject: {}, request: {}, response: {}, basisData: {}},
methods: {
runTest() {
if (this.currentProject === null) {

View File

@ -26,12 +26,12 @@
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<!-- HTTP 请求参数 -->
<ms-api-request-form :headers="headers" :request="request"/>
<ms-api-request-form :headers="request.headers" :request="request"/>
</el-form>
<!-- HTTP 请求返回数据 -->
<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"/>
@ -69,27 +69,13 @@
loading: false,
debugResultId: "",
runData: [],
headers: [],
reportId: "",
reqOptions: REQ_METHOD,
request: {},
}
},
created() {
switch (this.protocol) {
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;
}
this.createHttp();
},
watch: {
debugResultId() {
@ -105,9 +91,7 @@
}
},
createHttp() {
let header = createComponent("HeaderManager");
this.request = createComponent("HTTPSamplerProxy");
this.request.hashTree = [header];
},
runDebug() {
this.$refs['debugForm'].validate((valid) => {
@ -115,7 +99,6 @@
this.loading = true;
this.request.url = this.debugForm.url;
this.request.method = this.debugForm.method;
this.request.hashTree[0].headers = this.headers;
this.request.name = getUUID().substring(0, 8);
this.runData = [];
this.runData.push(this.request);

View File

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

View File

@ -59,7 +59,7 @@
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
<!-- 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>
<!--返回结果-->

View File

@ -34,8 +34,6 @@
:currentProject="currentProject" :loaded="loaded"
ref="caseList"/>
</el-drawer>
>
<!-- 环境 -->
<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 {
constructor(options = {}) {
super();
@ -761,6 +771,7 @@ export class KeyValue extends BaseConfig {
export class Assertions extends BaseConfig {
constructor(options) {
super();
this.resourceId = uuid();
this.type = "Assertions";
this.text = [];
this.regex = [];
@ -830,6 +841,8 @@ export class BeanShellProcessor extends BaseConfig {
export class JSR223Processor extends BaseConfig {
constructor(options) {
super();
this.resourceId = uuid();
this.active = false;
this.type = "JSR223Processor";
this.script = undefined;
this.language = "beanshell";
@ -902,6 +915,7 @@ export class Duration extends AssertionType {
export class Extract extends BaseConfig {
constructor(options) {
super();
this.resourceId = uuid();
this.type = "Extract";
this.regex = [];
this.json = [];
@ -969,6 +983,7 @@ export class Controller extends BaseConfig {
super();
this.type = type
options.id = options.id || uuid();
options.resourceId = options.resourceId || uuid();
options.enable = options.enable === undefined ? true : options.enable;
}
}
@ -980,7 +995,7 @@ export class IfController extends Controller {
this.variable;
this.operator;
this.value;
this.children=[];
this.hashTree = [];
this.set(options);
}
@ -1011,6 +1026,7 @@ export class Timer extends BaseConfig {
super();
this.type = type;
options.id = options.id || uuid();
options.resourceId = options.resourceId || uuid();
options.enable = options.enable === undefined ? true : options.enable;
}
}
@ -1020,7 +1036,7 @@ export class ConstantTimer extends Timer {
super(Timer.TYPES.CONSTANT_TIMER, options);
this.delay;
this.type = "ConstantTimer";
this.children=[];
this.hashTree = [];
this.set(options);
}