refactor(接口测试): 优化报告结构
This commit is contained in:
parent
33b110cd22
commit
cd57414bd2
|
@ -15,10 +15,12 @@ import io.metersphere.sdk.constants.ApiReportStatus;
|
||||||
import io.metersphere.sdk.domain.Environment;
|
import io.metersphere.sdk.domain.Environment;
|
||||||
import io.metersphere.sdk.domain.EnvironmentGroup;
|
import io.metersphere.sdk.domain.EnvironmentGroup;
|
||||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
|
||||||
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
||||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||||
import io.metersphere.sdk.util.*;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
|
import io.metersphere.sdk.util.JSON;
|
||||||
|
import io.metersphere.sdk.util.SubListUtils;
|
||||||
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
import io.metersphere.system.service.UserLoginService;
|
import io.metersphere.system.service.UserLoginService;
|
||||||
|
@ -195,37 +197,47 @@ public class ApiScenarioReportService {
|
||||||
List<ApiScenarioReportStepDTO> deatilList = extApiScenarioReportMapper.selectStepDeatilByReportId(id);
|
List<ApiScenarioReportStepDTO> deatilList = extApiScenarioReportMapper.selectStepDeatilByReportId(id);
|
||||||
//根据stepId进行分组
|
//根据stepId进行分组
|
||||||
Map<String, List<ApiScenarioReportStepDTO>> detailMap = deatilList.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getStepId));
|
Map<String, List<ApiScenarioReportStepDTO>> detailMap = deatilList.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getStepId));
|
||||||
|
//只处理请求的
|
||||||
|
List<String> stepTypes = Arrays.asList(ApiScenarioStepType.API_CASE.name(),
|
||||||
|
ApiScenarioStepType.API.name(),
|
||||||
|
ApiScenarioStepType.CUSTOM_REQUEST.name());
|
||||||
scenarioReportSteps.parallelStream().forEach(step -> {
|
scenarioReportSteps.parallelStream().forEach(step -> {
|
||||||
List<ApiScenarioReportStepDTO> details = detailMap.get(step.getStepId());
|
if (stepTypes.contains(step.getStepType())) {
|
||||||
if (CollectionUtils.isNotEmpty(details)) {
|
List<ApiScenarioReportStepDTO> details = detailMap.get(step.getStepId());
|
||||||
details.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getLoopIndex));
|
if (CollectionUtils.isNotEmpty(details) && details.size() > 1) {
|
||||||
//需要重新处理sort
|
details.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getLoopIndex));
|
||||||
for (int i = 0; i < details.size(); i++) {
|
if (details.size() > 1) {
|
||||||
ApiScenarioReportStepDTO detail = details.get(i);
|
//需要重新处理sort
|
||||||
detail.setSort((long) i + 1);
|
for (int i = 0; i < details.size(); i++) {
|
||||||
detail.setStepId(step.getStepId() + SPLITTER + detail.getSort());
|
ApiScenarioReportStepDTO detail = details.get(i);
|
||||||
detail.setStepType(step.getStepType());
|
detail.setSort((long) i + 1);
|
||||||
detail.setName(detail.getRequestName());
|
detail.setStepId(step.getStepId() + SPLITTER + detail.getSort());
|
||||||
}
|
detail.setStepType(step.getStepType());
|
||||||
step.setChildren(details);
|
detail.setName(detail.getRequestName());
|
||||||
//只处理请求的
|
}
|
||||||
List<String> stepTypes = Arrays.asList(ApiScenarioStepType.API_CASE.name(),
|
|
||||||
ApiScenarioStepType.API.name(),
|
step.setRequestTime(details.stream().mapToLong(ApiScenarioReportStepDTO::getRequestTime).sum());
|
||||||
ApiScenarioStepType.CUSTOM_REQUEST.name());
|
step.setResponseSize(details.stream().mapToLong(ApiScenarioReportStepDTO::getResponseSize).sum());
|
||||||
if (stepTypes.contains(step.getStepType())) {
|
List<String> requestStatus = details.stream().map(ApiScenarioReportStepDTO::getStatus).toList();
|
||||||
step.setRequestTime(details.stream().mapToLong(ApiScenarioReportStepDTO::getRequestTime).sum());
|
List<String> successStatus = requestStatus.stream().filter(status -> StringUtils.equals(ApiReportStatus.SUCCESS.name(), status)).toList();
|
||||||
step.setResponseSize(details.stream().mapToLong(ApiScenarioReportStepDTO::getResponseSize).sum());
|
if (requestStatus.contains(ApiReportStatus.ERROR.name())) {
|
||||||
List<String> requestStatus = details.stream().map(ApiScenarioReportStepDTO::getStatus).toList();
|
step.setStatus(ApiReportStatus.ERROR.name());
|
||||||
List<String> successStatus = requestStatus.stream().filter(status -> StringUtils.equals(ApiReportStatus.SUCCESS.name(), status)).toList();
|
} else if (requestStatus.contains(ApiReportStatus.FAKE_ERROR.name())) {
|
||||||
if (requestStatus.contains(ApiReportStatus.ERROR.name())) {
|
step.setStatus(ApiReportStatus.FAKE_ERROR.name());
|
||||||
step.setStatus(ApiReportStatus.ERROR.name());
|
} else if (successStatus.size() == details.size()) {
|
||||||
} else if (requestStatus.contains(ApiReportStatus.FAKE_ERROR.name())) {
|
step.setStatus(ApiReportStatus.SUCCESS.name());
|
||||||
step.setStatus(ApiReportStatus.FAKE_ERROR.name());
|
} else {
|
||||||
} else if (successStatus.size() == details.size()) {
|
step.setStatus(ApiReportStatus.PENDING.name());
|
||||||
step.setStatus(ApiReportStatus.SUCCESS.name());
|
}
|
||||||
} else {
|
|
||||||
step.setStatus(ApiReportStatus.PENDING.name());
|
|
||||||
}
|
}
|
||||||
|
step.setChildren(details);
|
||||||
|
} else if (CollectionUtils.isNotEmpty(details)){
|
||||||
|
step.setName(details.getFirst().getRequestName());
|
||||||
|
step.setReportId(details.getFirst().getReportId());
|
||||||
|
step.setRequestTime(details.getFirst().getRequestTime());
|
||||||
|
step.setResponseSize(details.getFirst().getResponseSize());
|
||||||
|
step.setStatus(details.getFirst().getStatus());
|
||||||
|
step.setScriptIdentifier(details.getFirst().getScriptIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -235,6 +247,7 @@ public class ApiScenarioReportService {
|
||||||
// TODO 查询修改
|
// TODO 查询修改
|
||||||
List<ApiScenarioReportStepDTO> steps = Optional.ofNullable(scenarioReportStepMap.get("NONE")).orElse(new ArrayList<>(0));
|
List<ApiScenarioReportStepDTO> steps = Optional.ofNullable(scenarioReportStepMap.get("NONE")).orElse(new ArrayList<>(0));
|
||||||
steps.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
steps.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
||||||
|
|
||||||
getStepTree(steps, scenarioReportStepMap);
|
getStepTree(steps, scenarioReportStepMap);
|
||||||
|
|
||||||
scenarioReportDTO.setStepTotal(steps.size());
|
scenarioReportDTO.setStepTotal(steps.size());
|
||||||
|
|
|
@ -24,10 +24,10 @@ public class OperationLogModule {
|
||||||
public static final String API_TEST_MANAGEMENT_MOCK = "API_TEST_MANAGEMENT_MOCK";
|
public static final String API_TEST_MANAGEMENT_MOCK = "API_TEST_MANAGEMENT_MOCK";
|
||||||
public static final String API_TEST_MANAGEMENT_CASE = "API_TEST_MANAGEMENT_CASE";
|
public static final String API_TEST_MANAGEMENT_CASE = "API_TEST_MANAGEMENT_CASE";
|
||||||
// 场景管理
|
// 场景管理
|
||||||
public static final String API_SCENARIO_MANAGEMENT_SCENARIO = "API_SCENARIO_MANAGEMENT_SCENARIO";
|
public static final String API_SCENARIO_MANAGEMENT_SCENARIO = "API_TEST_SCENARIO";
|
||||||
public static final String API_SCENARIO_MANAGEMENT_MODULE = "API_SCENARIO_MANAGEMENT_MODULE";
|
public static final String API_SCENARIO_MANAGEMENT_MODULE = "API_SCENARIO_MANAGEMENT_MODULE";
|
||||||
|
|
||||||
public static final String API_REPORT = "API_REPORT";
|
public static final String API_REPORT = "API_TEST_REPORT";
|
||||||
public static final String AUTH_TITLE = "AUTH_TITLE";
|
public static final String AUTH_TITLE = "AUTH_TITLE";
|
||||||
public static final String PROJECT_ENVIRONMENT_SETTING = "PROJECT_ENVIRONMENT_SETTING";
|
public static final String PROJECT_ENVIRONMENT_SETTING = "PROJECT_ENVIRONMENT_SETTING";
|
||||||
public static final String PROJECT_PROJECT_MANAGER = "PROJECT_PROJECT_MANAGER";
|
public static final String PROJECT_PROJECT_MANAGER = "PROJECT_PROJECT_MANAGER";
|
||||||
|
|
|
@ -95,7 +95,7 @@ export const pathMap: PathMapItem[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'API_TEST_MANAGEMENT_RECYCLE', // 接口测试-回收站
|
key: 'API_TEST_MANAGEMENT_RECYCLE', // 接口测试-回收站
|
||||||
locale: 'menu.apiTest.management.bugRecycle',
|
locale: 'menu.bugManagement.bugRecycle',
|
||||||
route: RouteEnum.API_TEST_MANAGEMENT_RECYCLE,
|
route: RouteEnum.API_TEST_MANAGEMENT_RECYCLE,
|
||||||
permission: [],
|
permission: [],
|
||||||
level: MENU_LEVEL[2],
|
level: MENU_LEVEL[2],
|
||||||
|
@ -103,7 +103,7 @@ export const pathMap: PathMapItem[] = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'API_TEST_SCENARIO', // 接口测试-场景
|
key: 'API_SCENARIO_MANAGEMENT_SCENARIO', // 接口测试-场景
|
||||||
locale: 'menu.apiTest.scenario',
|
locale: 'menu.apiTest.scenario',
|
||||||
route: RouteEnum.API_TEST_SCENARIO,
|
route: RouteEnum.API_TEST_SCENARIO,
|
||||||
permission: [],
|
permission: [],
|
||||||
|
@ -111,7 +111,7 @@ export const pathMap: PathMapItem[] = [
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
key: 'API_TEST_SCENARIO_RECYCLE', // 接口测试-回收站
|
key: 'API_TEST_SCENARIO_RECYCLE', // 接口测试-回收站
|
||||||
locale: 'menu.apiTest.scenario.bugRecycle',
|
locale: 'menu.bugManagement.bugRecycle',
|
||||||
route: RouteEnum.API_TEST_SCENARIO_RECYCLE,
|
route: RouteEnum.API_TEST_SCENARIO_RECYCLE,
|
||||||
permission: [],
|
permission: [],
|
||||||
level: MENU_LEVEL[2],
|
level: MENU_LEVEL[2],
|
||||||
|
|
Loading…
Reference in New Issue