test(接口测试): 调整接口覆盖率计算的单元测试
This commit is contained in:
parent
bde39eb0c5
commit
f6daf2fe8d
|
@ -45,6 +45,6 @@
|
|||
where scenario.project_id = #{0}
|
||||
AND scenario.deleted IS FALSE
|
||||
AND step.step_type IN ('API', 'API_CASE', 'CUSTOM_REQUEST')
|
||||
AND JSON_EXTRACT(step.config, '$.protocol') = 'http'
|
||||
AND JSON_UNQUOTE(JSON_EXTRACT(LOWER(step.config), '$.protocol')) = 'http'
|
||||
</select>
|
||||
</mapper>
|
|
@ -2635,7 +2635,6 @@ public class ApiScenarioService extends MoveNodeService {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
// 分批处理配置请求 ID 列表
|
||||
Map<String, Set<String>> methodPathMap = new HashMap<>();
|
||||
SubListUtils.dealForSubList(requestIdList, 200, batchIds -> {
|
||||
|
|
|
@ -25,49 +25,43 @@ public class ApiDefinitionUtils {
|
|||
if (StringUtils.isEmpty(customRequestUrl)) {
|
||||
continue;
|
||||
}
|
||||
if (customRequestUrl.startsWith("/")) {
|
||||
customRequestUrl = customRequestUrl.substring(1);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(customRequestUrl)) {
|
||||
if (customRequestUrl.contains("?")) {
|
||||
customRequestUrl = customRequestUrl.substring(0, customRequestUrl.indexOf("?"));
|
||||
|
||||
customRequestUrl = pretreatmentUrl(customRequestUrl);
|
||||
|
||||
String[] customUrlArr = customRequestUrl.split("/");
|
||||
|
||||
if (StringUtils.startsWithAny(customRequestUrl.toLowerCase(), "https://", "http://")
|
||||
&& customUrlArr.length >= urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) {
|
||||
String urlItem = urlParams[urlIndex];
|
||||
String customUrlItem = customUrlArr[customUrlArr.length - urlParams.length + urlIndex];
|
||||
// 不为rest参数的要进行全匹配。 而且忽略大小写
|
||||
if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) {
|
||||
if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) {
|
||||
isFetch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] customUrlArr = customRequestUrl.split("/");
|
||||
|
||||
if (StringUtils.startsWithAny(customRequestUrl.toLowerCase(), "https://", "http://")
|
||||
&& customUrlArr.length >= urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) {
|
||||
String urlItem = urlParams[urlIndex];
|
||||
String customUrlItem = customUrlArr[customUrlArr.length - urlParams.length + urlIndex];
|
||||
// 不为rest参数的要进行全匹配。 而且忽略大小写
|
||||
if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) {
|
||||
if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) {
|
||||
isFetch = false;
|
||||
break;
|
||||
}
|
||||
if (isFetch) {
|
||||
return true;
|
||||
}
|
||||
} else if (customUrlArr.length == urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) {
|
||||
String urlItem = urlParams[urlIndex];
|
||||
String customUrlItem = customUrlArr[urlIndex];
|
||||
// 不为rest参数的要进行全匹配。 而且忽略大小写
|
||||
if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) {
|
||||
if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) {
|
||||
isFetch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isFetch) {
|
||||
return true;
|
||||
}
|
||||
} else if (customUrlArr.length == urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int urlIndex = 0; urlIndex < urlParams.length; urlIndex++) {
|
||||
String urlItem = urlParams[urlIndex];
|
||||
String customUrlItem = customUrlArr[urlIndex];
|
||||
// 不为rest参数的要进行全匹配。 而且忽略大小写
|
||||
if (isRestUrlParam(customUrlItem) && isRestUrlParam(urlItem)) {
|
||||
if (!StringUtils.equalsIgnoreCase(customUrlItem, urlItem)) {
|
||||
isFetch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isFetch) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
if (isFetch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +69,17 @@ public class ApiDefinitionUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static String pretreatmentUrl(String customRequestUrl) {
|
||||
if (customRequestUrl.startsWith("/")) {
|
||||
customRequestUrl = customRequestUrl.substring(1);
|
||||
}
|
||||
|
||||
if (customRequestUrl.contains("?")) {
|
||||
customRequestUrl = customRequestUrl.substring(0, customRequestUrl.indexOf("?"));
|
||||
}
|
||||
return customRequestUrl;
|
||||
}
|
||||
|
||||
private static boolean isRestUrlParam(String urlParam) {
|
||||
return !StringUtils.startsWith(urlParam, "{") || !StringUtils.endsWith(urlParam, "}") || StringUtils.equals(urlParam, "{}");
|
||||
}
|
||||
|
|
|
@ -165,6 +165,9 @@ public class ApiCalculateTest extends BaseTest {
|
|||
stepRequest.setName(apiTestCase.getName() + "_step");
|
||||
stepRequest.setRefType(ApiScenarioStepRefType.REF.name());
|
||||
stepRequest.setProjectId(project.getId());
|
||||
stepRequest.setConfig(new HashMap<>() {{
|
||||
this.put("protocol", "http");
|
||||
}});
|
||||
steps.add(stepRequest);
|
||||
steptDetailMap.put(stepRequest.getId(), JSON.parseObject(ApiDataUtils.toJSONString(msHttpElement)));
|
||||
}
|
||||
|
@ -179,6 +182,9 @@ public class ApiCalculateTest extends BaseTest {
|
|||
stepRequest.setName("custom_step");
|
||||
stepRequest.setRefType(ApiScenarioStepRefType.DIRECT.name());
|
||||
stepRequest.setProjectId(project.getId());
|
||||
stepRequest.setConfig(new HashMap<>() {{
|
||||
this.put("protocol", "http");
|
||||
}});
|
||||
steps.add(stepRequest);
|
||||
|
||||
MsHTTPElement customElement = MsHTTPElementTest.getMsHttpElement();
|
||||
|
@ -197,6 +203,9 @@ public class ApiCalculateTest extends BaseTest {
|
|||
stepRequest.setName(resultData.getName() + "_step");
|
||||
stepRequest.setRefType(ApiScenarioStepRefType.REF.name());
|
||||
stepRequest.setProjectId(project.getId());
|
||||
stepRequest.setConfig(new HashMap<>() {{
|
||||
this.put("protocol", "http");
|
||||
}});
|
||||
steps.add(stepRequest);
|
||||
steptDetailMap.put(stepRequest.getId(), JSON.parseObject(ApiDataUtils.toJSONString(msHttpElement)));
|
||||
}
|
||||
|
@ -226,12 +235,12 @@ public class ApiCalculateTest extends BaseTest {
|
|||
Assertions.assertEquals(16, apiCoverageDTO.getUnCoverWithApiCase());
|
||||
Assertions.assertEquals(apiCoverageDTO.getApiCaseCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiCase(), apiCoverageDTO.getAllApiCount()));
|
||||
|
||||
Assertions.assertEquals(4, apiCoverageDTO.getCoverWithApiScenario());
|
||||
Assertions.assertEquals(16, apiCoverageDTO.getUnCoverWithApiScenario());
|
||||
Assertions.assertEquals(8, apiCoverageDTO.getCoverWithApiScenario());
|
||||
Assertions.assertEquals(12, apiCoverageDTO.getUnCoverWithApiScenario());
|
||||
Assertions.assertEquals(apiCoverageDTO.getScenarioCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiScenario(), apiCoverageDTO.getAllApiCount()));
|
||||
|
||||
Assertions.assertEquals(6, apiCoverageDTO.getCoverWithApiDefinition());
|
||||
Assertions.assertEquals(14, apiCoverageDTO.getUnCoverWithApiDefinition());
|
||||
Assertions.assertEquals(10, apiCoverageDTO.getCoverWithApiDefinition());
|
||||
Assertions.assertEquals(10, apiCoverageDTO.getUnCoverWithApiDefinition());
|
||||
Assertions.assertEquals(apiCoverageDTO.getApiCoverage(), CalculateUtils.reportPercentage(apiCoverageDTO.getCoverWithApiDefinition(), apiCoverageDTO.getAllApiCount()));
|
||||
|
||||
Assertions.assertEquals("0.00%", CalculateUtils.reportPercentage(0, 0));
|
||||
|
|
Loading…
Reference in New Issue