mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 20:19:16 +08:00
fix(Mock接口): 修复Mock匹配不上post请求中form-data参数的问题
修复Mock匹配不上post请求中form-data参数的问题
This commit is contained in:
parent
de55237091
commit
209988d19b
@ -432,8 +432,8 @@ public class MockApiUtils {
|
||||
|
||||
}
|
||||
|
||||
public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject, JSON paramJson) {
|
||||
RequestMockParams returnParams = getGetParamMap(urlParams, apiPath, queryParamsObject);
|
||||
public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject, JSON paramJson, boolean isPostRequest) {
|
||||
RequestMockParams returnParams = getGetParamMap(urlParams, apiPath, queryParamsObject, isPostRequest);
|
||||
if (paramJson != null) {
|
||||
if (paramJson instanceof JSONObject) {
|
||||
if (!((JSONObject) paramJson).isEmpty()) {
|
||||
@ -462,13 +462,19 @@ public class MockApiUtils {
|
||||
return queryParamsObject;
|
||||
}
|
||||
|
||||
private static RequestMockParams getGetParamMap(String urlParams, String apiPath, JSONObject queryParamsObject) {
|
||||
private static RequestMockParams getGetParamMap(String urlParams, String apiPath, JSONObject queryParamsObject, boolean isPostRequest) {
|
||||
RequestMockParams requestMockParams = new RequestMockParams();
|
||||
|
||||
JSONObject urlParamsObject = getSendRestParamMapByIdAndUrl(apiPath, urlParams);
|
||||
|
||||
requestMockParams.setRestParamsObj(urlParamsObject);
|
||||
requestMockParams.setQueryParamsObj(queryParamsObject);
|
||||
|
||||
if(isPostRequest){
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.add(queryParamsObject);
|
||||
requestMockParams.setBodyParams(jsonArray);
|
||||
}
|
||||
return requestMockParams;
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ public class MockConfigService {
|
||||
if (jsonObject.containsKey("name") && jsonObject.containsKey("value")) {
|
||||
String headerName = jsonObject.getString("name");
|
||||
String headerValue = jsonObject.getString("value");
|
||||
if(StringUtils.isNotEmpty(headerName)){
|
||||
if (StringUtils.isNotEmpty(headerName)) {
|
||||
if (!requestHeaderMap.containsKey(headerName) || !StringUtils.equals(requestHeaderMap.get(headerName), headerValue)) {
|
||||
return false;
|
||||
}
|
||||
@ -1155,13 +1155,10 @@ public class MockConfigService {
|
||||
if (project != null) {
|
||||
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
||||
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix);
|
||||
|
||||
JSON paramJson = MockApiUtils.getPostParamMap(request);
|
||||
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
|
||||
|
||||
for (ApiDefinitionWithBLOBs api : aualifiedApiList) {
|
||||
RequestMockParams mockParams = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson);
|
||||
|
||||
RequestMockParams mockParams = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson, true);
|
||||
MockConfigResponse mockConfigData = this.findByApiId(api.getId());
|
||||
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
|
||||
if (finalExpectConfig != null) {
|
||||
@ -1170,36 +1167,6 @@ public class MockConfigService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// List<String> apiIdList = aualifiedApiList.stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList());
|
||||
// MockConfigResponse mockConfigData = this.findByApiIdList(apiIdList);
|
||||
|
||||
// if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
|
||||
// String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
||||
// aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, null, urlSuffix);
|
||||
// JSON paramJson = MockApiUtils.getParams(request);
|
||||
// if (paramJson instanceof JSONObject) {
|
||||
// JSONArray paramsArray = new JSONArray();
|
||||
// paramsArray.add(paramJson);
|
||||
// RequestMockParams mockParams = new RequestMockParams();
|
||||
// mockParams.setBodyParams(paramsArray);
|
||||
// MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
|
||||
// if (finalExpectConfig != null) {
|
||||
// isMatch = true;
|
||||
// returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
|
||||
// }
|
||||
// } else if (paramJson instanceof JSONArray) {
|
||||
// JSONArray paramArray = (JSONArray) paramJson;
|
||||
// RequestMockParams mockParams = new RequestMockParams();
|
||||
// mockParams.setBodyParams(paramArray);
|
||||
// MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
|
||||
// if (finalExpectConfig != null) {
|
||||
// isMatch = true;
|
||||
// returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
if (!isMatch) {
|
||||
@ -1230,7 +1197,7 @@ public class MockConfigService {
|
||||
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
|
||||
|
||||
for (ApiDefinitionWithBLOBs api : aualifiedApiList) {
|
||||
RequestMockParams paramMap = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson);
|
||||
RequestMockParams paramMap = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson, false);
|
||||
|
||||
MockConfigResponse mockConfigData = this.findByApiId(api.getId());
|
||||
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
|
||||
|
@ -1,14 +1,15 @@
|
||||
<template>
|
||||
<span>
|
||||
<ms-tag v-if="value == 'Prepare'" type="info" :content="$t('test_track.plan.plan_status_prepare')"/>
|
||||
<ms-tag v-if="value == 'Underway'" type="primary" :content="$t('test_track.plan.plan_status_running')"/>
|
||||
<ms-tag v-if="value == 'Pass'" type="success" :content="$t('test_track.plan_view.pass')"/>
|
||||
<ms-tag v-if="value == 'UnPass'" type="danger" :content="$t('test_track.plan_view.not_pass')"/>
|
||||
<ms-tag v-if="value == 'STOP'" type="info" :content="$t('test_track.plan_view.stop')"/>
|
||||
<ms-tag v-if="value == 'stop'" type="info" :content="$t('test_track.plan_view.stop')"/>
|
||||
<ms-tag v-if="value == 'Failure'" type="danger" :content="$t('test_track.plan_view.failure')"/>
|
||||
<ms-tag v-if="value == 'Blocking'" type="warning" :content="$t('test_track.plan_view.blocking')"/>
|
||||
<ms-tag v-if="value == 'Skip'" type="info" :content="$t('test_track.plan_view.skip')"/>
|
||||
<ms-tag v-else-if="value == 'Underway'" type="primary" :content="$t('test_track.plan.plan_status_running')"/>
|
||||
<ms-tag v-else-if="value == 'Pass'" type="success" :content="$t('test_track.plan_view.pass')"/>
|
||||
<ms-tag v-else-if="value == 'UnPass'" type="danger" :content="$t('test_track.plan_view.not_pass')"/>
|
||||
<ms-tag v-else-if="value == 'STOP'" type="info" :content="$t('test_track.plan_view.stop')"/>
|
||||
<ms-tag v-else-if="value == 'stop'" type="info" :content="$t('test_track.plan_view.stop')"/>
|
||||
<ms-tag v-else-if="value == 'Failure'" type="danger" :content="$t('test_track.plan_view.failure')"/>
|
||||
<ms-tag v-else-if="value == 'Blocking'" type="warning" :content="$t('test_track.plan_view.blocking')"/>
|
||||
<ms-tag v-else-if="value == 'Skip'" type="info" :content="$t('test_track.plan_view.skip')"/>
|
||||
<ms-tag v-else type="info" :content="value"/>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
|
@ -44,6 +44,8 @@
|
||||
<status-table-item v-if="row.lastResult === 'Success'" :value="'Pass'"/>
|
||||
<status-table-item v-else-if="row.lastResult === 'Fail'" :value="'Failure'"/>
|
||||
<status-table-item v-else-if="row.lastResult === 'STOP'" :value="'STOP'"/>
|
||||
<status-table-item v-else-if="row.lastResult === 'Running'" :value="'Underway'"/>
|
||||
<status-table-item v-else-if="row.lastResult === 'Watting'" :value="'Underway'"/>
|
||||
<status-table-item v-else :value="'Prepare'"/>
|
||||
</template>
|
||||
</ms-table-column>
|
||||
|
Loading…
Reference in New Issue
Block a user