fix(接口测试): 修复api定义不填响应体,mock返回未找到mock配置的问题
--bug=1010453 --user=宋天阳 【接口测试】api定义不填响应体,mock匹配不到期望应该显示api定义的响应体 https://www.tapd.cn/55049933/s/1106962
This commit is contained in:
parent
b42d4f457f
commit
7496801454
|
@ -1116,7 +1116,7 @@ public class MockConfigService {
|
||||||
public String checkReturnWithMockExpectByBodyParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
|
public String checkReturnWithMockExpectByBodyParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
|
||||||
request, HttpServletResponse response) {
|
request, HttpServletResponse response) {
|
||||||
String returnStr = "";
|
String returnStr = "";
|
||||||
boolean isMatch = false;
|
boolean matchApi = false;
|
||||||
String url = request.getRequestURL().toString();
|
String url = request.getRequestURL().toString();
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
String urlSuffix = this.getUrlSuffix(project.getSystemId(), request);
|
||||||
|
@ -1124,24 +1124,23 @@ public class MockConfigService {
|
||||||
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, true);
|
if(StringUtils.isEmpty(returnStr)){
|
||||||
MockConfigResponse mockConfigData = this.findByApiId(api.getId());
|
RequestMockParams mockParams = MockApiUtils.getParams(urlSuffix, api.getPath(), parameterObject, paramJson, true);
|
||||||
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
|
MockConfigResponse mockConfigData = this.findByApiId(api.getId());
|
||||||
if (finalExpectConfig != null) {
|
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), mockParams);
|
||||||
isMatch = true;
|
if (finalExpectConfig != null) {
|
||||||
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
|
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
|
||||||
break;
|
}else {
|
||||||
}
|
returnStr = this.getApiDefinitionResponse(api, response);
|
||||||
if (!isMatch) {
|
|
||||||
returnStr = this.getApiDefinitionResponse(api, response);
|
|
||||||
if (StringUtils.isNotEmpty(returnStr)) {
|
|
||||||
isMatch = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(CollectionUtils.isNotEmpty(aualifiedApiList)){
|
||||||
|
matchApi = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMatch) {
|
if (!matchApi) {
|
||||||
response.setStatus(404);
|
response.setStatus(404);
|
||||||
returnStr = Translator.get("mock_warning");
|
returnStr = Translator.get("mock_warning");
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1150,7 @@ public class MockConfigService {
|
||||||
public String checkReturnWithMockExpectByUrlParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
|
public String checkReturnWithMockExpectByUrlParam(String method, Map<String, String> requestHeaderMap, Project project, HttpServletRequest
|
||||||
request, HttpServletResponse response) {
|
request, HttpServletResponse response) {
|
||||||
String returnStr = "";
|
String returnStr = "";
|
||||||
boolean isMatch = false;
|
boolean matchApi = false;
|
||||||
String url = request.getRequestURL().toString();
|
String url = request.getRequestURL().toString();
|
||||||
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
List<ApiDefinitionWithBLOBs> aualifiedApiList = new ArrayList<>();
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
|
@ -1169,27 +1168,26 @@ 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, false);
|
if(StringUtils.isEmpty(returnStr)){
|
||||||
|
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) {
|
||||||
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), paramMap);
|
MockExpectConfigResponse finalExpectConfig = this.findExpectConfig(requestHeaderMap, mockConfigData.getMockExpectConfigList(), paramMap);
|
||||||
if (finalExpectConfig != null) {
|
if (finalExpectConfig != null) {
|
||||||
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, paramMap, response);
|
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, paramMap, response);
|
||||||
isMatch = true;
|
}else {
|
||||||
break;
|
returnStr = this.getApiDefinitionResponse(api, response);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!isMatch) {
|
|
||||||
returnStr = this.getApiDefinitionResponse(api, response);
|
|
||||||
if (StringUtils.isNotEmpty(returnStr)) {
|
|
||||||
isMatch = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(CollectionUtils.isNotEmpty(aualifiedApiList)){
|
||||||
|
matchApi = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMatch) {
|
if (!matchApi) {
|
||||||
response.setStatus(404);
|
response.setStatus(404);
|
||||||
returnStr = Translator.get("mock_warning");
|
returnStr = Translator.get("mock_warning");
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class TCPServicer {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LogUtil.info("TCP-Mock start. port: " + this.port + "; Message:" + message + "; response:" + returnMsg);
|
||||||
return returnMsg;
|
return returnMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue