fix(接口测试): 修复mock服务不支持接受get请求内body参数的问题

--bug=1024452 --user=宋天阳
[接口测试]github#22682在MOCK里设置mock请求参数和请求内容,点击执行,输入mock参数进行发送,响应的不是设置好的mock请求,而是该接口的响应内容
https://www.tapd.cn/55049933/s/1350225
This commit is contained in:
song-tianyang 2023-03-15 10:13:57 +08:00 committed by 建国
parent 383144ff65
commit 8cfdf5455f
2 changed files with 38 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.api.dto.mock;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
@ -29,12 +30,21 @@ public class RequestMockParams {
public boolean isEmpty() { public boolean isEmpty() {
boolean isJsonParamEmpty = false;
if (jsonParam instanceof JSONObject) {
isJsonParamEmpty = ((JSONObject) jsonParam).isEmpty();
} else if (jsonParam instanceof JSONArray) {
isJsonParamEmpty = ((JSONArray) jsonParam).isEmpty();
} else {
isJsonParamEmpty = jsonParam == null;
}
if (isPost) { if (isPost) {
return (restParamsObj == null || restParamsObj.isEmpty()) && return (restParamsObj == null || restParamsObj.isEmpty()) &&
isJsonParamEmpty &&
(queryParamsObj == null || queryParamsObj.isEmpty()) (queryParamsObj == null || queryParamsObj.isEmpty())
&& StringUtils.isBlank(raw); && StringUtils.isBlank(raw);
} else { } else {
return (restParamsObj == null || restParamsObj.isEmpty()) && return (restParamsObj == null || restParamsObj.isEmpty()) && isJsonParamEmpty &&
(queryParamsObj == null || queryParamsObj.isEmpty()); (queryParamsObj == null || queryParamsObj.isEmpty());
} }

View File

@ -45,13 +45,20 @@
:open-delay="800" :open-delay="800"
> >
<div <div
v-if="totalStatus === 'Success' || totalStatus === 'success'" v-if="
totalStatus === 'Success' ||
totalStatus === 'SUCCESS' ||
totalStatus === 'success'
"
style="color: #5daf34" style="color: #5daf34"
> >
{{ baseErrorCode }} {{ baseErrorCode }}
</div> </div>
<div <div
v-else-if="totalStatus === 'errorReportResult'" v-else-if="
totalStatus === 'errorReportResult' ||
totalStatus === 'FAKE_ERROR'
"
style="color: #f6972a" style="color: #f6972a"
> >
{{ baseErrorCode }} {{ baseErrorCode }}
@ -97,13 +104,20 @@
:open-delay="800" :open-delay="800"
> >
<div <div
v-if="totalStatus === 'Success' || totalStatus === 'success'" v-if="
totalStatus === 'Success' ||
totalStatus === 'SUCCESS' ||
totalStatus === 'success'
"
style="color: #5daf34" style="color: #5daf34"
> >
{{ request.responseResult.responseCode }} {{ request.responseResult.responseCode }}
</div> </div>
<div <div
v-else-if="totalStatus === 'errorReportResult'" v-else-if="
totalStatus === 'errorReportResult' ||
totalStatus === 'FAKE_ERROR'
"
style="color: #f6972a" style="color: #f6972a"
> >
{{ request.responseResult.responseCode }} {{ request.responseResult.responseCode }}
@ -145,13 +159,20 @@
<el-col :span="3"> <el-col :span="3">
<div v-if="totalStatus"> <div v-if="totalStatus">
<div <div
v-if="totalStatus === 'Success' || totalStatus === 'success'" v-if="
totalStatus === 'Success' ||
totalStatus === 'SUCCESS' ||
totalStatus === 'success'
"
style="color: #5daf34" style="color: #5daf34"
> >
{{ request.responseResult.responseTime }} {{ request.responseResult.responseTime }}
</div> </div>
<div <div
v-else-if="totalStatus === 'errorReportResult'" v-else-if="
totalStatus === 'errorReportResult' ||
totalStatus === 'FAKE_ERROR'
"
style="color: #f6972a" style="color: #f6972a"
> >
{{ request.responseResult.responseTime }} {{ request.responseResult.responseTime }}