refactor(接口测试): 优化场景报告显示环境名称和资源池名称
This commit is contained in:
parent
cc2c6ed67c
commit
c6b19923dc
|
@ -10,5 +10,7 @@ import java.util.List;
|
|||
public class ApiReportDTO extends ApiReport {
|
||||
@Schema(description = "子节点")
|
||||
private List<ApiReportStepDTO> children;
|
||||
@Schema(description = "控制台信息")
|
||||
private String console;
|
||||
|
||||
}
|
||||
|
|
|
@ -72,11 +72,6 @@ public class ApiReportDetailDTO {
|
|||
*/
|
||||
@Schema(description = "结果内容详情")
|
||||
private RequestResult content;
|
||||
/**
|
||||
* 结果内容详情
|
||||
*/
|
||||
@Schema(description = "控制台")
|
||||
private String console;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,4 +12,11 @@ public class ApiScenarioReportDTO extends ApiScenarioReport {
|
|||
private List<ApiScenarioReportStepDTO> children;
|
||||
@Schema(description = "步骤总数")
|
||||
private Integer stepTotal;
|
||||
@Schema(description = "控制台信息")
|
||||
private String console;
|
||||
@Schema(description = "资源池名称")
|
||||
private String poolName;
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
|
||||
}
|
||||
|
|
|
@ -163,6 +163,13 @@ public class ApiReportService {
|
|||
ApiReportDTO apiReportDTO = new ApiReportDTO();
|
||||
ApiReport apiReport = checkResource(id);
|
||||
BeanUtils.copyBean(apiReportDTO, apiReport);
|
||||
//查询console
|
||||
ApiReportLogExample consoleExample = new ApiReportLogExample();
|
||||
consoleExample.createCriteria().andReportIdEqualTo(id);
|
||||
List<ApiReportLog> apiReportLogs = apiReportLogMapper.selectByExampleWithBLOBs(consoleExample);
|
||||
if (CollectionUtils.isNotEmpty(apiReportLogs)) {
|
||||
apiReportDTO.setConsole(new String(apiReportLogs.getFirst().getConsole()));
|
||||
}
|
||||
//需要查询出所有的步骤
|
||||
if (BooleanUtils.isTrue(apiReport.getIntegrated())) {
|
||||
List<ApiReportStepDTO> apiReportSteps = extApiReportMapper.selectStepsByReportId(id);
|
||||
|
@ -190,17 +197,10 @@ public class ApiReportService {
|
|||
public List<ApiReportDetailDTO> getDetail(String stepId, String reportId) {
|
||||
List<ApiReportDetail> apiReportDetails = checkResourceStep(stepId, reportId);
|
||||
List<ApiReportDetailDTO> results = new ArrayList<>();
|
||||
//查询console
|
||||
ApiReportLogExample example = new ApiReportLogExample();
|
||||
example.createCriteria().andReportIdEqualTo(reportId);
|
||||
List<ApiReportLog> apiReportLogs = apiReportLogMapper.selectByExampleWithBLOBs(example);
|
||||
apiReportDetails.forEach(apiReportDetail -> {
|
||||
ApiReportDetailDTO apiReportDetailDTO = new ApiReportDetailDTO();
|
||||
BeanUtils.copyBean(apiReportDetailDTO, apiReportDetail);
|
||||
apiReportDetailDTO.setContent(ApiDataUtils.parseObject(new String(apiReportDetail.getContent()), RequestResult.class));
|
||||
if (CollectionUtils.isNotEmpty(apiReportLogs)) {
|
||||
apiReportDetailDTO.setConsole(new String(apiReportLogs.getFirst().getConsole()));
|
||||
}
|
||||
results.add(apiReportDetailDTO);
|
||||
});
|
||||
return results;
|
||||
|
|
|
@ -12,9 +12,11 @@ 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.service.UserLoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -47,6 +49,12 @@ public class ApiScenarioReportService {
|
|||
private ApiScenarioReportLogService apiScenarioReportLogService;
|
||||
@Resource
|
||||
private ApiScenarioReportDetailMapper apiScenarioReportDetailMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportLogMapper apiScenarioReportLogMapper;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertApiScenarioReport(List<ApiScenarioReport> reports, List<ApiScenarioRecord> records) {
|
||||
|
@ -174,6 +182,17 @@ public class ApiScenarioReportService {
|
|||
getStepTree(steps, scenarioReportStepMap);
|
||||
scenarioReportDTO.setStepTotal(steps.size());
|
||||
scenarioReportDTO.setChildren(steps);
|
||||
//控制台信息 console
|
||||
ApiScenarioReportLogExample example = new ApiScenarioReportLogExample();
|
||||
example.createCriteria().andReportIdEqualTo(id);
|
||||
List<ApiScenarioReportLog> apiScenarioReportLogs = apiScenarioReportLogMapper.selectByExampleWithBLOBs(example);
|
||||
if (CollectionUtils.isNotEmpty(apiScenarioReportLogs)) {
|
||||
scenarioReportDTO.setConsole(new String(apiScenarioReportLogs.getFirst().getConsole()));
|
||||
}
|
||||
//查询资源池名称
|
||||
scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName());
|
||||
//查询环境名称
|
||||
scenarioReportDTO.setEnvironmentName(environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId()).getName());
|
||||
return scenarioReportDTO;
|
||||
}
|
||||
|
||||
|
|
|
@ -268,6 +268,12 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
apiReportService.insertApiReportStep(steps);
|
||||
ApiReportLog apiReportLog = new ApiReportLog();
|
||||
apiReportLog.setReportId("test-report-id");
|
||||
apiReportLog.setId(IDGenerator.nextStr());
|
||||
apiReportLog.setConsole("test-console".getBytes());
|
||||
apiReportLogMapper.insert(apiReportLog);
|
||||
|
||||
MvcResult mvcResult = this.requestGetWithOk(GET + "test-report-id")
|
||||
.andReturn();
|
||||
ApiReportDTO apiReportDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResult).get("data")), ApiReportDTO.class);
|
||||
|
@ -371,11 +377,6 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
reports.add(apiReportDetail);
|
||||
}
|
||||
apiReportDetailMapper.batchInsert(reports);
|
||||
ApiReportLog apiReportLog = new ApiReportLog();
|
||||
apiReportLog.setReportId("test-report-id");
|
||||
apiReportLog.setId(IDGenerator.nextStr());
|
||||
apiReportLog.setConsole("test-console".getBytes());
|
||||
apiReportLogMapper.insert(apiReportLog);
|
||||
|
||||
MvcResult mvcResult = this.requestGetWithOk(DETAIL + "test-report-id" + "/" + "test-report-step-id1")
|
||||
.andReturn();
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
|||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportDetailMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportLogMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportMapper;
|
||||
import io.metersphere.api.service.scenario.ApiScenarioReportService;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
|
@ -18,11 +19,18 @@ import io.metersphere.project.mapper.ProjectApplicationMapper;
|
|||
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;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
@ -56,6 +64,13 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
private ShareInfoMapper shareInfoMapper;
|
||||
@Resource
|
||||
private ProjectApplicationMapper projectApplicationMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportLogMapper apiScenarioReportLogMapper;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private EnvironmentMapper environmentMapper;
|
||||
|
||||
private static final String BASIC = "/api/report/scenario";
|
||||
private static final String PAGE = BASIC + "/page";
|
||||
private static final String RENAME = BASIC + "/rename/";
|
||||
|
@ -226,6 +241,14 @@ public class ApiScenarioReportControllerTests 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<ApiScenarioReport> reports = new ArrayList<>();
|
||||
ApiScenarioReport scenarioReport = new ApiScenarioReport();
|
||||
scenarioReport.setId("test-scenario-report-id");
|
||||
|
@ -235,8 +258,8 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
scenarioReport.setCreateUser("admin");
|
||||
scenarioReport.setUpdateUser("admin");
|
||||
scenarioReport.setUpdateTime(System.currentTimeMillis());
|
||||
scenarioReport.setPoolId("api-pool-id");
|
||||
scenarioReport.setEnvironmentId("api-environment-id");
|
||||
scenarioReport.setPoolId(testResourcePools.getFirst().getId());
|
||||
scenarioReport.setEnvironmentId(environments.getFirst().getId());
|
||||
scenarioReport.setRunMode("api-run-mode");
|
||||
scenarioReport.setTriggerMode("api-trigger-mode");
|
||||
scenarioReport.setVersionId("api-version-id");
|
||||
|
@ -262,6 +285,15 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
steps.add(apiScenarioReportStep);
|
||||
}
|
||||
apiScenarioReportService.insertApiScenarioReportStep(steps);
|
||||
|
||||
//插入console 资源池 环境
|
||||
ApiScenarioReportLog apiScenarioReportLog = new ApiScenarioReportLog();
|
||||
apiScenarioReportLog.setId(IDGenerator.nextStr());
|
||||
apiScenarioReportLog.setReportId("test-scenario-report-id");
|
||||
apiScenarioReportLog.setConsole("console".getBytes());
|
||||
apiScenarioReportLogMapper.insert(apiScenarioReportLog);
|
||||
|
||||
|
||||
MvcResult mvcResult = this.requestGetWithOk(GET + "test-scenario-report-id")
|
||||
.andReturn();
|
||||
ApiScenarioReportDTO apiReportDTO = ApiDataUtils.parseObject(JSON.toJSONString(parseResponse(mvcResult).get("data")), ApiScenarioReportDTO.class);
|
||||
|
@ -278,7 +310,7 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
.andExpect(status().is5xxServerError());
|
||||
|
||||
// @@校验权限
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_REPORT_READ, GET + "scenario-report-id0");
|
||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_REPORT_READ, GET + "test-scenario-report-id");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue