refactor(接口测试): 优化报告
This commit is contained in:
parent
5f7fa0fd6f
commit
82752b5bf7
|
@ -94,9 +94,9 @@ public class ApiReportController {
|
|||
@Operation(summary = "接口测试-接口报告-报告详情获取")
|
||||
@CheckOwner(resourceId = "#reportId", resourceType = "api_report")
|
||||
@RequiresPermissions(value = {PermissionConstants.PROJECT_API_REPORT_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}, logical = Logical.OR)
|
||||
public List<ApiReportDetailDTO> getDetail(@PathVariable String stepId,
|
||||
@PathVariable String reportId) {
|
||||
return apiReportService.getDetail(stepId, reportId);
|
||||
public List<ApiReportDetailDTO> getDetail(@PathVariable String reportId,
|
||||
@PathVariable String stepId) {
|
||||
return apiReportService.getDetail(reportId, stepId);
|
||||
}
|
||||
|
||||
@GetMapping("/share/detail/{shareId}/{reportId}/{stepId}")
|
||||
|
@ -105,7 +105,7 @@ public class ApiReportController {
|
|||
@PathVariable String stepId) {
|
||||
ShareInfo shareInfo = apiReportShareService.checkResource(shareId);
|
||||
apiReportShareService.validateExpired(shareInfo);
|
||||
return apiReportService.getDetail(stepId, reportId);
|
||||
return apiReportService.getDetail(reportId, stepId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.api.dto.report.ApiReportListDTO;
|
|||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.sdk.constants.ApiExecuteResourceType;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
|
@ -185,7 +186,12 @@ public class ApiReportService {
|
|||
//查询资源池名称
|
||||
apiReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(apiReportDTO.getPoolId()).getName());
|
||||
//查询环境名称
|
||||
apiReportDTO.setEnvironmentName(StringUtils.isNoneBlank(apiReportDTO.getEnvironmentId()) ? environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId()).getName() : null);
|
||||
if (StringUtils.isNoneBlank(apiReportDTO.getEnvironmentId())) {
|
||||
Environment environment = environmentMapper.selectByPrimaryKey(apiReportDTO.getEnvironmentId());
|
||||
if (environment != null) {
|
||||
apiReportDTO.setEnvironmentName(environment.getName());
|
||||
}
|
||||
}
|
||||
apiReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(apiReportDTO.getCreateUser()).getName());
|
||||
//需要查询出所有的步骤
|
||||
if (BooleanUtils.isTrue(apiReport.getIntegrated())) {
|
||||
|
@ -206,6 +212,8 @@ public class ApiReportService {
|
|||
ApiReportStepDTO apiReportStepDTO = new ApiReportStepDTO();
|
||||
BeanUtils.copyBean(apiReportStepDTO, apiReportDTO);
|
||||
apiReportStepDTO.setStepId(apiTestCaseRecords.getFirst().getApiTestCaseId());
|
||||
apiReportStepDTO.setReportId(id);
|
||||
apiReportStepDTO.setSort(1L);
|
||||
apiReportStepDTO.setStepType(ApiExecuteResourceType.API_CASE.name());
|
||||
List<ApiReportStepDTO> apiReportSteps = new ArrayList<>();
|
||||
apiReportSteps.add(apiReportStepDTO);
|
||||
|
@ -213,7 +221,7 @@ public class ApiReportService {
|
|||
return apiReportDTO;
|
||||
}
|
||||
|
||||
public List<ApiReportDetailDTO> getDetail(String stepId, String reportId) {
|
||||
public List<ApiReportDetailDTO> getDetail(String reportId, String stepId) {
|
||||
List<ApiReportDetail> apiReportDetails = checkResourceStep(stepId, reportId);
|
||||
List<ApiReportDetailDTO> results = new ArrayList<>();
|
||||
apiReportDetails.forEach(apiReportDetail -> {
|
||||
|
|
|
@ -11,6 +11,7 @@ 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.domain.Environment;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
|
@ -199,7 +200,12 @@ public class ApiScenarioReportService {
|
|||
//查询资源池名称
|
||||
scenarioReportDTO.setPoolName(testResourcePoolMapper.selectByPrimaryKey(scenarioReport.getPoolId()).getName());
|
||||
//查询环境名称
|
||||
scenarioReportDTO.setEnvironmentName(StringUtils.isNotBlank(scenarioReport.getEnvironmentId()) ? environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId()).getName(): null);
|
||||
if (StringUtils.isNotBlank(scenarioReport.getEnvironmentId())) {
|
||||
Environment environment = environmentMapper.selectByPrimaryKey(scenarioReport.getEnvironmentId());
|
||||
if (environment != null) {
|
||||
scenarioReportDTO.setEnvironmentName(environment.getName());
|
||||
}
|
||||
}
|
||||
scenarioReportDTO.setCreatUserName(userMapper.selectByPrimaryKey(scenarioReport.getCreateUser()).getName());
|
||||
return scenarioReportDTO;
|
||||
}
|
||||
|
|
|
@ -298,6 +298,14 @@ public class ApiReportControllerTests extends BaseTest {
|
|||
|
||||
Assertions.assertNotNull(apiReportDTO);
|
||||
Assertions.assertEquals(apiReportDTO.getId(), "test-report-id");
|
||||
ApiReport apiReport1 = apiReportMapper.selectByPrimaryKey("test-report-id");
|
||||
apiReport1.setEnvironmentId(null);
|
||||
apiReport1.setPoolId(null);
|
||||
apiReportMapper.updateByPrimaryKeySelective(apiReport1);
|
||||
this.requestGetWithOk(GET + "test-report-id");
|
||||
apiReport1.setEnvironmentId("env_id");
|
||||
apiReportMapper.updateByPrimaryKeySelective(apiReport1);
|
||||
this.requestGetWithOk(GET + "test-report-id");
|
||||
|
||||
reports = new ArrayList<>();
|
||||
apiReport = new ApiReport();
|
||||
|
|
|
@ -327,6 +327,15 @@ public class ApiScenarioReportControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(apiReportDTO);
|
||||
Assertions.assertEquals(apiReportDTO.getId(), "test-scenario-report-id");
|
||||
|
||||
ApiScenarioReport scenarioReport1 = apiScenarioReportMapper.selectByPrimaryKey("test-scenario-report-id");
|
||||
scenarioReport1.setEnvironmentId(null);
|
||||
scenarioReport1.setPoolId(null);
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(scenarioReport1);
|
||||
this.requestGetWithOk(GET + "test-scenario-report-id");
|
||||
scenarioReport1.setEnvironmentId("env_id");
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(scenarioReport1);
|
||||
this.requestGetWithOk(GET + "test-scenario-report-id");
|
||||
|
||||
mockMvc.perform(getRequestBuilder(GET + "test"))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().is5xxServerError());
|
||||
|
|
Loading…
Reference in New Issue