fix(接口测试): 修复http协议请求参数为binary类型附件丢失问题
--bug=1013413 --user=赵勇 [接口测试]github#13849ES的api请求中有批量添加数据的方法,需要使用到binary的数据,上传一个文件,但是请求直接就报异常,找不到数据 https://www.tapd.cn/55049933/s/1162821
This commit is contained in:
parent
5da1e64301
commit
e0e4a4710a
|
@ -97,7 +97,7 @@ public class Body {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNotEmpty(this.getRaw())) {
|
if (StringUtils.isNotEmpty(this.getRaw())) {
|
||||||
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField,Feature.DisableSpecialKeyDetect);
|
JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField, Feature.DisableSpecialKeyDetect);
|
||||||
if (!this.getRaw().contains("$ref")) {
|
if (!this.getRaw().contains("$ref")) {
|
||||||
jsonMockParse(jsonObject);
|
jsonMockParse(jsonObject);
|
||||||
}
|
}
|
||||||
|
@ -128,23 +128,24 @@ public class Body {
|
||||||
List<HTTPFileArg> list = new ArrayList<>();
|
List<HTTPFileArg> list = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(this.getKvs())) {
|
if (CollectionUtils.isNotEmpty(this.getKvs())) {
|
||||||
this.getKvs().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
|
this.getKvs().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
|
||||||
setFileArg(list, keyValue.getFiles(), keyValue, requestId);
|
setFileArg(list, keyValue.getFiles(), keyValue, requestId, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(this.getBinary())) {
|
if (CollectionUtils.isNotEmpty(this.getBinary())) {
|
||||||
this.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
|
this.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> {
|
||||||
setFileArg(list, keyValue.getFiles(), keyValue, requestId);
|
setFileArg(list, keyValue.getFiles(), keyValue, requestId, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return list.toArray(new HTTPFileArg[0]);
|
return list.toArray(new HTTPFileArg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFileArg(List<HTTPFileArg> list, List<BodyFile> files, KeyValue keyValue, String requestId) {
|
private void setFileArg(List<HTTPFileArg> list, List<BodyFile> files,
|
||||||
|
KeyValue keyValue, String requestId, boolean isBinary) {
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
files.forEach(file -> {
|
files.forEach(file -> {
|
||||||
String paramName = keyValue.getName() == null ? requestId : keyValue.getName();
|
String paramName = keyValue.getName() == null ? requestId : keyValue.getName();
|
||||||
String path = null;
|
String path = null;
|
||||||
if (StringUtils.isNotBlank(file.getId())) {
|
if (StringUtils.isNotBlank(file.getId()) && !isBinary) {
|
||||||
// 旧数据
|
// 旧数据
|
||||||
path = FileUtils.BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName();
|
path = FileUtils.BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName();
|
||||||
} else if (StringUtils.isNotBlank(this.tmpFilePath)) {
|
} else if (StringUtils.isNotBlank(this.tmpFilePath)) {
|
||||||
|
|
|
@ -253,21 +253,38 @@ export default {
|
||||||
apiCaseClose() {
|
apiCaseClose() {
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
},
|
},
|
||||||
getBodyUploadFiles() {
|
getBodyUploadFiles(data) {
|
||||||
let bodyUploadFiles = [];
|
let bodyUploadFiles = [];
|
||||||
this.api.bodyUploadIds = [];
|
data.bodyUploadIds = [];
|
||||||
let request = this.api.request;
|
let request = data.request;
|
||||||
if (request.body) {
|
if (request.body) {
|
||||||
request.body.kvs.forEach(param => {
|
if (request.body.kvs) {
|
||||||
if (param.files) {
|
request.body.kvs.forEach(param => {
|
||||||
param.files.forEach(item => {
|
if (param.files) {
|
||||||
if (item.file) {
|
param.files.forEach(item => {
|
||||||
item.name = item.file.name;
|
if (item.file) {
|
||||||
bodyUploadFiles.push(item.file);
|
item.name = item.file.name;
|
||||||
}
|
bodyUploadFiles.push(item.file);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (request.body.binary) {
|
||||||
|
request.body.binary.forEach(param => {
|
||||||
|
if (param.files) {
|
||||||
|
param.files.forEach(item => {
|
||||||
|
if (item.file) {
|
||||||
|
let fileId = getUUID().substring(0, 8);
|
||||||
|
item.name = item.file.name;
|
||||||
|
item.id = fileId;
|
||||||
|
data.bodyUploadIds.push(fileId);
|
||||||
|
bodyUploadFiles.push(item.file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bodyUploadFiles;
|
return bodyUploadFiles;
|
||||||
},
|
},
|
||||||
|
@ -305,7 +322,7 @@ export default {
|
||||||
},
|
},
|
||||||
updateApi() {
|
updateApi() {
|
||||||
let url = "/api/definition/update";
|
let url = "/api/definition/update";
|
||||||
let bodyFiles = this.getBodyUploadFiles();
|
let bodyFiles = this.getBodyUploadFiles(this.api);
|
||||||
this.api.method = this.api.request.method;
|
this.api.method = this.api.request.method;
|
||||||
this.api.path = this.api.request.path;
|
this.api.path = this.api.request.path;
|
||||||
if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {
|
if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {
|
||||||
|
|
Loading…
Reference in New Issue