feat(接口测试): 没有匹配到的Mock期望按照接口响应设置的内容来返回
没有匹配到的Mock期望按照接口响应设置的内容来返回
This commit is contained in:
parent
c44dfb0fe4
commit
b588cdf53a
|
@ -290,6 +290,23 @@ public class MockApiUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
if(respObj.containsKey("statusCode")){
|
||||
JSONArray statusCodeArray = respObj.getJSONArray("statusCode");
|
||||
if(statusCodeArray != null){
|
||||
for(int i = 0; i < statusCodeArray.size(); i ++){
|
||||
JSONObject object = statusCodeArray.getJSONObject(i);
|
||||
if(object.containsKey("name")){
|
||||
try{
|
||||
int code = Integer.parseInt(object.getString("name"));
|
||||
returnMap.put("code",code+"");
|
||||
break;
|
||||
}catch (Exception e){
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
}
|
||||
|
|
|
@ -1131,6 +1131,21 @@ public class MockConfigService {
|
|||
returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response);
|
||||
break;
|
||||
}
|
||||
if(!isMatch){
|
||||
Map<String,String> apiResponseMap = MockApiUtils.getApiResponse(api.getResponse());
|
||||
if(MapUtils.isNotEmpty(apiResponseMap)){
|
||||
returnStr = apiResponseMap.get("returnMsg");
|
||||
if(StringUtils.isNotEmpty(returnStr)){
|
||||
isMatch = true;
|
||||
int code = 200;
|
||||
if(apiResponseMap.containsKey("code")){
|
||||
code = Integer.parseInt(apiResponseMap.get("code"));
|
||||
}
|
||||
response.setStatus(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1173,6 +1188,21 @@ public class MockConfigService {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(!isMatch){
|
||||
Map<String,String> apiResponseMap = MockApiUtils.getApiResponse(api.getResponse());
|
||||
if(MapUtils.isNotEmpty(apiResponseMap)){
|
||||
returnStr = apiResponseMap.get("returnMsg");
|
||||
if(StringUtils.isNotEmpty(returnStr)){
|
||||
isMatch = true;
|
||||
int code = 200;
|
||||
if(apiResponseMap.containsKey("code")){
|
||||
code = Integer.parseInt(apiResponseMap.get("code"));
|
||||
}
|
||||
response.setStatus(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue