feat(接口测试): 接口覆盖率增加自定义请求全路径的匹配

This commit is contained in:
Jianguo-Genius 2024-11-25 12:21:35 +08:00 committed by 刘瑞斌
parent ba5f7be8e5
commit 80cb7ad49c
2 changed files with 32 additions and 4 deletions

View File

@ -68,6 +68,8 @@ public abstract class PostmanAbstractParserParser<T> extends ApiImportAbstractPa
parseBody(request.getBody(), requestDesc);
request.setArguments(parseKeyValue(url == null ? new ArrayList<>() : url.getQuery()));
request.setHeaders(parseKeyValue(requestDesc.getHeader()));
request.setCustomizeReq(true);
request.setReferenced("Created");
return request;
}

View File

@ -727,10 +727,32 @@ public class MockApiUtils {
for (String path : urlList) {
if (StringUtils.equalsAny(path, url, "/" + url)) {
return true;
} else {
if (StringUtils.isEmpty(path)) {
continue;
} else if (StringUtils.isEmpty(path)) {
return false;
} else if (StringUtils.startsWithAny(path.toLowerCase(), "https://", "http://")) {
if (path.contains("?")) {
path = path.substring(0, path.indexOf("?"));
}
String[] pathArr = path.split("/");
if (pathArr.length >= urlParams.length) {
boolean isFetch = true;
for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) {
String urlItem = urlParams[urlIndex];
String customUrlItem = pathArr[pathArr.length - urlParams.length + urlIndex];
// 不为rest参数的要进行全匹配 而且忽略大小写
if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) {
if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) {
isFetch = false;
break;
}
}
}
if (isFetch) {
return true;
}
}
} else {
if (path.startsWith("/")) {
path = path.substring(1);
}
@ -741,7 +763,7 @@ public class MockApiUtils {
for (int i = 0; i < urlParams.length; i++) {
String pathItem = pathArr[i];
String urlItem = urlParams[i];
if (!(pathItem.startsWith("{") && pathItem.endsWith("}")) && !(urlItem.startsWith("{") && urlItem.endsWith("}"))) {
if (!(isRestUrlParam(pathItem)) && !(isRestUrlParam(urlItem))) {
if (!StringUtils.equals(pathArr[i], urlParams[i])) {
isFetch = false;
break;
@ -763,6 +785,10 @@ public class MockApiUtils {
return false;
}
private static boolean isRestUrlParam(String urlParam) {
return !StringUtils.startsWith(urlParam, "{") || !StringUtils.endsWith(urlParam, "}") || StringUtils.equals(urlParam, "{}");
}
/**
* 匹配自定义URL是否匹配截取前面的域名等信息
*