fix(接口测试): 修复api定义不填响应体,mock返回未找到mock配置的问题

--bug=1010453 --user=宋天阳 【接口测试】api定义不填响应体,mock匹配不到期望应该显示api定义的响应体
https://www.tapd.cn/55049933/s/1106962
This commit is contained in:
song-tianyang 2022-02-21 18:31:18 +08:00 committed by CountryBuilder
parent b42d4f457f
commit 7496801454
2 changed files with 30 additions and 31 deletions

View File

@ -1116,7 +1116,7 @@ public class MockConfigService {
public String checkReturnWithMockExpectByBodyParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
request, HttpServletResponse response) {
String returnStr = "";
boolean isMatch = false;
boolean matchApi = false;
String url = request.getRequestURL().toString();
if (project != null) {
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
@ -1124,24 +1124,23 @@ public class MockConfigService {
JSON paramJson = MockApiUtils.getPostParamMap(request);
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
for (ApiDefinitionWithBLOBs api : aualifiedApiList) {
if(StringUtils.isEmpty(returnStr)){
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) {
isMatch = true;
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
break;
}
if (!isMatch) {
}else {
returnStr = this.getApiDefinitionResponse(api, response);
if (StringUtils.isNotEmpty(returnStr)) {
isMatch = true;
}
}
}
if(CollectionUtils.isNotEmpty(aualifiedApiList)){
matchApi = true;
}
}
if (!isMatch) {
if (!matchApi) {
response.setStatus(404);
returnStr = Translator.get("mock_warning");
}
@ -1151,7 +1150,7 @@ public class MockConfigService {
public String checkReturnWithMockExpectByUrlParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
request, HttpServletResponse response) {
String returnStr = "";
boolean isMatch = false;
boolean matchApi = false;
String url = request.getRequestURL().toString();
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
if (project != null) {
@ -1169,27 +1168,26 @@ public class MockConfigService {
JSONObject parameterObject = MockApiUtils.getParameterJsonObject(request);
for (ApiDefinitionWithBLOBs api : aualifiedApiList) {
if(StringUtils.isEmpty(returnStr)){
RequestMockParams paramMap = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson, false);
MockConfigResponse mockConfigData = this.findByApiId(api.getId());
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), paramMap);
if (finalExpectConfig != null) {
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, paramMap, response);
isMatch = true;
break;
}
}
if (!isMatch) {
}else {
returnStr = this.getApiDefinitionResponse(api, response);
if (StringUtils.isNotEmpty(returnStr)) {
isMatch = true;
}
}
}
}
if (!isMatch) {
if(CollectionUtils.isNotEmpty(aualifiedApiList)){
matchApi = true;
}
}
if (!matchApi) {
response.setStatus(404);
returnStr = Translator.get("mock_warning");
}

View File

@ -83,6 +83,7 @@ public class TCPServicer {
LogUtil.error(e);
}
}
LogUtil.info("TCP-Mock start. port: " + this.port + "; Message:" + message + "; response:" + returnMsg);
return returnMsg;
}