fix(Mock接口): 修复Mock匹配不上post请求中form-data参数的问题

修复Mock匹配不上post请求中form-data参数的问题
This commit is contained in:
song-tianyang 2022-01-13 12:40:18 +08:00 committed by fit2-zhao
parent de55237091
commit 209988d19b
4 changed files with 23 additions and 47 deletions

View File

@ -432,8 +432,8 @@ public class MockApiUtils {
} }
public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject, JSON paramJson) { public static RequestMockParams getParams(String urlParams, String apiPath, JSONObject queryParamsObject, JSON paramJson, boolean isPostRequest) {
RequestMockParams returnParams = getGetParamMap(urlParams, apiPath, queryParamsObject); RequestMockParams returnParams = getGetParamMap(urlParams, apiPath, queryParamsObject, isPostRequest);
if (paramJson != null) { if (paramJson != null) {
if (paramJson instanceof JSONObject) { if (paramJson instanceof JSONObject) {
if (!((JSONObject) paramJson).isEmpty()) { if (!((JSONObject) paramJson).isEmpty()) {
@ -462,13 +462,19 @@ public class MockApiUtils {
return queryParamsObject; 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(); RequestMockParams requestMockParams = new RequestMockParams();
JSONObject urlParamsObject = getSendRestParamMapByIdAndUrl(apiPath, urlParams); JSONObject urlParamsObject = getSendRestParamMapByIdAndUrl(apiPath, urlParams);
requestMockParams.setRestParamsObj(urlParamsObject); requestMockParams.setRestParamsObj(urlParamsObject);
requestMockParams.setQueryParamsObj(queryParamsObject); requestMockParams.setQueryParamsObj(queryParamsObject);
if(isPostRequest){
JSONArray jsonArray = new JSONArray();
jsonArray.add(queryParamsObject);
requestMockParams.setBodyParams(jsonArray);
}
return requestMockParams; return requestMockParams;
} }

View File

@ -1155,13 +1155,10 @@ public class MockConfigService {
if (project != null) { if (project != null) {
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request); String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix); aualifiedApiList = apiDefinitionService.preparedUrl(project.getId(), method, urlSuffix);
JSON paramJson = MockApiUtils.getPostParamMap(request); JSON paramJson = MockApiUtils.getPostParamMap(request);
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request); JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
for (ApiDefinitionWithBLOBs api : aualifiedApiList) { 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()); MockConfigResponse mockConfigData = this.findByApiId(api.getId());
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams); MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
if (finalExpectConfig != null) { if (finalExpectConfig != null) {
@ -1170,36 +1167,6 @@ public class MockConfigService {
break; 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) { if (!isMatch) {
@ -1230,7 +1197,7 @@ public class MockConfigService {
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request); JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
for (ApiDefinitionWithBLOBs api : aualifiedApiList) { 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()); MockConfigResponse mockConfigData = this.findByApiId(api.getId());
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) { if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {

View File

@ -1,14 +1,15 @@
<template> <template>
<span> <span>
<ms-tag v-if="value == 'Prepare'" type="info" :content="$t('test_track.plan.plan_status_prepare')"/> <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-else-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-else-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-else-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-else-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-else-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-else-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-else-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 == 'Skip'" type="info" :content="$t('test_track.plan_view.skip')"/>
<ms-tag v-else type="info" :content="value"/>
</span> </span>
</template> </template>

View File

@ -44,6 +44,8 @@
<status-table-item v-if="row.lastResult === 'Success'" :value="'Pass'"/> <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 === 'Fail'" :value="'Failure'"/>
<status-table-item v-else-if="row.lastResult === 'STOP'" :value="'STOP'"/> <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'"/> <status-table-item v-else :value="'Prepare'"/>
</template> </template>
</ms-table-column> </ms-table-column>