refactor(接口测试): 优化报告
This commit is contained in:
parent
95f2ff2312
commit
96d5c279c7
|
@ -12,5 +12,11 @@ public class ApiReportDTO extends ApiReport {
|
|||
private List<ApiReportStepDTO> children;
|
||||
@Schema(description = "控制台信息")
|
||||
private String console;
|
||||
@Schema(description = "资源池名称")
|
||||
private String poolName;
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
@Schema(description = "创建人")
|
||||
private String creatUserName;
|
||||
|
||||
}
|
||||
|
|
|
@ -18,5 +18,7 @@ public class ApiScenarioReportDTO extends ApiScenarioReport {
|
|||
private String poolName;
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
@Schema(description = "创建人")
|
||||
private String creatUserName;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,12 +5,14 @@ import io.metersphere.api.dto.definition.*;
|
|||
import io.metersphere.api.dto.report.ApiReportListDTO;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.sdk.constants.ApiReportStatus;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -48,6 +50,12 @@ public class ApiReportService {
|
|||
private ApiTestCaseRecordMapper apiTestCaseRecordMapper;
|
||||
@Resource
|
||||
private ApiReportLogMapper apiReportLogMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
|
@ -172,6 +180,11 @@ public class ApiReportService {
|
|||
if (CollectionUtils.isNotEmpty(apiReportLogs)) {
|
||||
apiReportDTO.setConsole(new String(apiReportLogs.getFirst().getConsole()));
|
||||
}
|
||||
//查询资源池名称
|
||||
apiReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(apiReportDTO.getPoolId()).getName());
|
||||
//查询环境名称
|
||||
apiReportDTO.setEnvironmentName(environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId()).getName());
|
||||
apiReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(apiReportDTO.getCreateUser()).getName());
|
||||
//需要查询出所有的步骤
|
||||
if (BooleanUtils.isTrue(apiReport.getIntegrated())) {
|
||||
List<ApiReportStepDTO> apiReportSteps = extApiReportMapper.selectStepsByReportId(id);
|
||||
|
@ -189,6 +202,7 @@ public class ApiReportService {
|
|||
throw new MSException(Translator.get("api_case_report_not_exist"));
|
||||
}
|
||||
ApiReportStepDTO apiReportStepDTO = new ApiReportStepDTO();
|
||||
BeanUtils.copyBean(apiReportStepDTO, apiReportDTO);
|
||||
apiReportStepDTO.setStepId(apiTestCaseRecords.getFirst().getApiTestCaseId());
|
||||
List<ApiReportStepDTO> apiReportSteps = new ArrayList<>();
|
||||
apiReportSteps.add(apiReportStepDTO);
|
||||
|
|
|
@ -9,7 +9,6 @@ import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
|||
import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.sdk.constants.ApiReportStatus;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
|
@ -17,6 +16,7 @@ import io.metersphere.sdk.util.BeanUtils;
|
|||
import io.metersphere.sdk.util.SubListUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -55,6 +55,8 @@ public class ApiScenarioReportService {
|
|||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertApiScenarioReport(List<ApiScenarioReport> reports, List<ApiScenarioRecord> records) {
|
||||
|
@ -141,7 +143,7 @@ public class ApiScenarioReportService {
|
|||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
SubListUtils.dealForSubList(ids, 2000, subList -> {
|
||||
SubListUtils.dealForSubList(ids, 500, subList -> {
|
||||
ApiScenarioReportExample example = new ApiScenarioReportExample();
|
||||
example.createCriteria().andIdIn(subList);
|
||||
ApiScenarioReport scenarioReport = new ApiScenarioReport();
|
||||
|
@ -195,6 +197,7 @@ public class ApiScenarioReportService {
|
|||
scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName());
|
||||
//查询环境名称
|
||||
scenarioReportDTO.setEnvironmentName(environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId()).getName());
|
||||
scenarioReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(scenarioReport.getCreateUser()).getName());
|
||||
return scenarioReportDTO;
|
||||
}
|
||||
|
||||
|
@ -202,6 +205,8 @@ public class ApiScenarioReportService {
|
|||
steps.forEach(step -> {
|
||||
List<ApiScenarioReportStepDTO> children = scenarioReportStepMap.get(step.getStepId());
|
||||
if (CollectionUtils.isNotEmpty(children)) {
|
||||
//如果是父级的报告,需要计算请求时间 请求时间是所有子级的请求时间之和 还需要计算请求的大小 还有请求的数量 以及请求成功的状态
|
||||
|
||||
children.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
||||
step.setChildren(children);
|
||||
getStepTree(children, scenarioReportStepMap);
|
||||
|
|
|
@ -20,11 +20,17 @@ import io.metersphere.sdk.constants.ApiExecuteResourceType;
|
|||
import io.metersphere.sdk.constants.ApiReportStatus;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentExample;
|
||||
import io.metersphere.sdk.domain.ShareInfo;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.mapper.ShareInfoMapper;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
import io.metersphere.system.domain.TestResourcePool;
|
||||
import io.metersphere.system.domain.TestResourcePoolExample;
|
||||
import io.metersphere.system.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -61,6 +67,10 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
private ProjectApplicationMapper projectApplicationMapper;
|
||||
@Resource
|
||||
private ApiReportLogMapper apiReportLogMapper;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
|
||||
private static final String BASIC = "/api/report/case";
|
||||
private static final String PAGE = BASIC + "/page";
|
||||
|
@ -237,6 +247,13 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
@Order(6)
|
||||
public void testGet() throws Exception {
|
||||
// @@请求成功
|
||||
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||
environmentExample.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andMockEqualTo(true);
|
||||
List<Environment> environments = environmentMapper.selectByExample(environmentExample);
|
||||
|
||||
TestResourcePoolExample example = new TestResourcePoolExample();
|
||||
example.createCriteria().andNameEqualTo("默认资源池");
|
||||
List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
|
||||
List<ApiReport> reports = new ArrayList<>();
|
||||
ApiReport apiReport = new ApiReport();
|
||||
apiReport.setId("test-report-id");
|
||||
|
@ -246,8 +263,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
apiReport.setCreateUser("admin");
|
||||
apiReport.setUpdateUser("admin");
|
||||
apiReport.setUpdateTime(System.currentTimeMillis());
|
||||
apiReport.setPoolId("api-pool-id");
|
||||
apiReport.setEnvironmentId("api-environment-id");
|
||||
apiReport.setPoolId(testResourcePools.getFirst().getId());
|
||||
apiReport.setEnvironmentId(environments.getFirst().getId());
|
||||
apiReport.setRunMode("api-run-mode");
|
||||
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
apiReport.setTriggerMode("api-trigger-mode");
|
||||
|
@ -290,8 +307,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
apiReport.setCreateUser("admin");
|
||||
apiReport.setUpdateUser("admin");
|
||||
apiReport.setUpdateTime(System.currentTimeMillis());
|
||||
apiReport.setPoolId("api-pool-id");
|
||||
apiReport.setEnvironmentId("api-environment-id");
|
||||
apiReport.setPoolId(testResourcePools.getFirst().getId());
|
||||
apiReport.setEnvironmentId(environments.getFirst().getId());
|
||||
apiReport.setRunMode("api-run-mode");
|
||||
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
apiReport.setTriggerMode("api-trigger-mode");
|
||||
|
@ -316,8 +333,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
apiReport.setCreateUser("admin");
|
||||
apiReport.setUpdateUser("admin");
|
||||
apiReport.setUpdateTime(System.currentTimeMillis());
|
||||
apiReport.setPoolId("api-pool-id");
|
||||
apiReport.setEnvironmentId("api-environment-id");
|
||||
apiReport.setPoolId(testResourcePools.getFirst().getId());
|
||||
apiReport.setEnvironmentId(environments.getFirst().getId());
|
||||
apiReport.setRunMode("api-run-mode");
|
||||
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
apiReport.setTriggerMode("api-trigger-mode");
|
||||
|
@ -341,8 +358,8 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
apiReport.setCreateUser("admin");
|
||||
apiReport.setUpdateUser("admin");
|
||||
apiReport.setUpdateTime(System.currentTimeMillis());
|
||||
apiReport.setPoolId("api-pool-id");
|
||||
apiReport.setEnvironmentId("api-environment-id");
|
||||
apiReport.setPoolId(testResourcePools.getFirst().getId());
|
||||
apiReport.setEnvironmentId(environments.getFirst().getId());
|
||||
apiReport.setRunMode("api-run-mode");
|
||||
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
|
||||
apiReport.setTriggerMode("api-trigger-mode");
|
||||
|
|
Loading…
Reference in New Issue