Merge branch 'v1.8'

This commit is contained in:
Captain.B 2021-03-25 19:26:55 +08:00
commit 4cf1dd112b
8 changed files with 272 additions and 193 deletions

View File

@ -136,8 +136,10 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
try {
HTTPSamplerProxy source = (HTTPSamplerProxy) key;
BeanUtils.copyBean(samplerProxy, source);
samplerProxy.setRest(new ArrayList<KeyValue>(){{this.add(new KeyValue());}});
samplerProxy.setArguments(new ArrayList<KeyValue>(){{this.add(new KeyValue());}});
if (source != null && source.getHTTPFiles().length > 0) {
samplerProxy.getBody().setBinary(new ArrayList<>());
samplerProxy.getBody().initBinary();
samplerProxy.getBody().setType(Body.FORM_DATA);
List<KeyValue> keyValues = new LinkedList<>();
for (HTTPFileArg arg : source.getHTTPFiles()) {
@ -163,6 +165,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
samplerProxy.getBody().setRaw(v);
});
samplerProxy.getBody().initKvs();
} else {
List<KeyValue> keyValues = new LinkedList<>();
source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
@ -173,6 +176,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy.setArguments(keyValues);
}
}
samplerProxy.getBody().initBinary();
}
samplerProxy.setPath("");
samplerProxy.setMethod(source.getMethod());

View File

@ -65,15 +65,12 @@ public class Body {
sampler.setHTTPFiles(httpFileArgs(requestId));
sampler.setDoMultipart(true);
}
} else {
if (!this.isJson()) {
sampler.setPostBodyRaw(true);
} else {
if (StringUtils.isNotEmpty(this.format) && "JSON-SCHEMA".equals(this.format) && this.getJsonSchema() != null) {
this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
}
}
KeyValue keyValue = new KeyValue("", "JSON-SCHEMA", this.getRaw(), true, true);
sampler.setPostBodyRaw(true);
keyValue.setEnable(true);
keyValue.setEncode(false);
body.add(keyValue);

View File

@ -86,12 +86,12 @@ public class ApiDocumentService {
apiInfoDTO.setStatus(apiModel.getStatus());
if (apiModel.getRequest() != null) {
JSONObject requestJsonObj = JSONObject.parseObject(apiModel.getRequest());
//head赋值conversionModelToDTO
if (requestJsonObj.containsKey("headers")) {
JSONObject requestObj = this.genJSONObject(apiModel.getRequest());
if(requestObj!=null){
if (requestObj.containsKey("headers")) {
JSONArray requestHeadDataArr = new JSONArray();
//head赋值
JSONArray headArr = requestJsonObj.getJSONArray("headers");
JSONArray headArr = requestObj.getJSONArray("headers");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
@ -102,30 +102,37 @@ public class ApiDocumentService {
}
//url参数赋值
JSONArray urlParamArr = new JSONArray();
if (requestJsonObj.containsKey("arguments")) {
//urlParam -- query赋值
JSONArray headArr = requestJsonObj.getJSONArray("arguments");
if (requestObj.containsKey("arguments")) {
try{
JSONArray headArr = requestObj.getJSONArray("arguments");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
urlParamArr.add(headObj);
}
}
}catch (Exception e){
}
if (requestJsonObj.containsKey("rest")) {
}
if (requestObj.containsKey("rest")) {
try{
//urlParam -- rest赋值
JSONArray headArr = requestJsonObj.getJSONArray("rest");
JSONArray headArr = requestObj.getJSONArray("rest");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
urlParamArr.add(headObj);
}
}
}catch (Exception e){
}
}
apiInfoDTO.setUrlParams(urlParamArr.toJSONString());
//请求体参数类型
if (requestJsonObj.containsKey("body")) {
JSONObject bodyObj = requestJsonObj.getJSONObject("body");
if (requestObj.containsKey("body")) {
try{
JSONObject bodyObj = requestObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equals(type, "WWW_FORM")) {
@ -160,7 +167,6 @@ public class ApiDocumentService {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setRequestBodyStrutureData(raw);
JSONObject previewObj = JSONObject.parseObject(raw);
this.setPreviewData(previewJsonArray, raw);
}
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
@ -211,13 +217,19 @@ public class ApiDocumentService {
}
}
}
}catch (Exception e){
}
}
}
}
//赋值响应头
if (apiModel.getResponse() != null) {
JSONObject responseJsonObj = JSONObject.parseObject(apiModel.getResponse());
JSONObject responseJsonObj = this.genJSONObject(apiModel.getResponse());
if (responseJsonObj!=null && responseJsonObj.containsKey("headers")) {
try{
JSONArray responseHeadDataArr = new JSONArray();
JSONArray headArr = responseJsonObj.getJSONArray("headers");
for (int index = 0; index < headArr.size(); index++) {
@ -227,9 +239,13 @@ public class ApiDocumentService {
}
}
apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString());
}catch (Exception e){
}
}
// 赋值响应体
if (responseJsonObj!=null && responseJsonObj.containsKey("body")) {
try {
JSONObject bodyObj = responseJsonObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
@ -284,9 +300,14 @@ public class ApiDocumentService {
}
}
}
}catch (Exception e){
}
}
// 赋值响应码
if (responseJsonObj!=null && responseJsonObj.containsKey("statusCode")) {
try {
JSONArray responseStatusDataArr = new JSONArray();
JSONArray statusArr = responseJsonObj.getJSONArray("statusCode");
for (int index = 0; index < statusArr.size(); index++) {
@ -296,6 +317,9 @@ public class ApiDocumentService {
}
}
apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString());
}catch (Exception e){
}
}
}
}
@ -304,6 +328,15 @@ public class ApiDocumentService {
return apiInfoDTO;
}
private JSONObject genJSONObject(String request) {
JSONObject returnObj = null;
try{
returnObj = JSONObject.parseObject(request);
}catch (Exception e){
}
return returnObj;
}
private void setPreviewData(JSONArray previewArray, String data) {
try {
JSONObject previewObj = JSONObject.parseObject(data);

View File

@ -5,12 +5,12 @@
<el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
@ -78,12 +78,12 @@ export default {
const project = this.projectList.find(p => p.id === id);
return project ? project.name : "";
},
openEnvironmentConfig(projectId) {
openEnvironmentConfig(projectId, envId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId);
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();

View File

@ -77,7 +77,7 @@
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.projectId);
this.$refs.environmentConfig.open(this.projectId, this.environmentId);
},
environmentChange(value) {
for (let i in this.environments) {

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete',
func: this.deleteEnvironment
}
]
],
selectEnvironmentId: ''
}
},
methods: {
open: function (projectId) {
open: function (projectId, envId) {
this.visible = true;
this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments();
listenGoBack(this.close);
},
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
if (this.environments.length > 0) {
if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
let item = new Environment({
projectId: this.projectId

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete',
func: this.deleteEnvironment
}
]
],
selectEnvironmentId: ''
}
},
methods: {
open: function (projectId) {
open: function (projectId, envId) {
this.visible = true;
this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments();
listenGoBack(this.close);
},
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data;
if (this.environments.length > 0) {
if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
let item = new Environment({
projectId: this.projectId

View File

@ -4,7 +4,7 @@
<el-col>
<el-form :inline="true">
<el-form-item :label="$t('load_test.select_resource_pool')">
<el-select v-model="resourcePool" :disabled="isReadOnly" size="mini">
<el-select v-model="resourcePool" :disabled="isReadOnly" size="mini" @change="resourcePoolChange">
<el-option
v-for="item in resourcePools"
:key="item.id"
@ -42,6 +42,7 @@
v-model="threadGroup.threadNumber"
@change="calculateTotalChart(threadGroup)"
:min="resourcePoolResourceLength"
:max="maxThreadNumbers"
size="mini"/>
</el-form-item>
<br>
@ -219,7 +220,8 @@ export default {
resourcePools: [],
activeNames: ["0"],
threadGroups: [],
resourcePoolResourceLength: 1
resourcePoolResourceLength: 1,
maxThreadNumbers: 5000,
}
},
mounted() {
@ -336,6 +338,22 @@ export default {
});
}
},
resourcePoolChange() {
let result = this.resourcePools.filter(p => p.id === this.resourcePool);
if (result.length === 1) {
let threadNumber = 0;
result[0].resources.forEach(resource => {
threadNumber += JSON.parse(resource.configuration).maxConcurrency;
})
this.maxThreadNumbers = threadNumber;
this.threadGroups.forEach(tg => {
if (tg.threadNumber > threadNumber) {
this.$set(tg, "threadNumber", threadNumber);
}
})
this.calculateTotalChart();
}
},
calculateTotalChart() {
let handler = this;
if (handler.duration < handler.rampUpTime) {
@ -344,6 +362,11 @@ export default {
if (handler.rampUpTime < handler.step) {
handler.step = handler.rampUpTime;
}
// 线
let resourcePool = this.resourcePools.filter(v => v.id === this.resourcePool)[0];
if (resourcePool) {
this.resourcePoolResourceLength = resourcePool.resources.length;
}
let color = ['#60acfc', '#32d3eb', '#5bc49f', '#feb64d', '#ff7c7c', '#9287e7', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
handler.options = {
color: color,