From 5a67c18bda79b006e6db2a8e5dc2139f8863d0c3 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 22 Feb 2024 14:11:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=9C=BA=E6=99=AF=E5=A2=9E=E5=8A=A0=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/sdk/file/MinioRepository.java | 3 +- .../definition/ApiTestCaseController.java | 2 +- .../scenario/ApiScenarioController.java | 23 +++ ...geRequest.java => ExecutePageRequest.java} | 4 +- ...seReportDTO.java => ExecuteReportDTO.java} | 2 +- .../api/listener/DebugListener.java | 4 +- .../api/mapper/ExtApiScenarioMapper.java | 3 + .../api/mapper/ExtApiScenarioMapper.xml | 43 ++++++ .../api/mapper/ExtApiTestCaseMapper.java | 4 +- .../api/mapper/ExtApiTestCaseMapper.xml | 2 +- .../service/definition/ApiReportService.java | 23 +-- .../definition/ApiTestCaseService.java | 4 +- .../scenario/ApiScenarioReportService.java | 23 +-- .../service/scenario/ApiScenarioService.java | 37 ++++- .../controller/ApiReportControllerTests.java | 15 +- .../controller/ApiReportSendNoticeTests.java | 19 ++- .../ApiScenarioControllerTests.java | 138 +++++++++++++++++- .../ApiScenarioReportControllerTests.java | 23 +-- .../ApiTaskCenterControllerTests.java | 16 +- .../ApiTestCaseControllerTests.java | 8 +- .../api/controller/CleanupApiTests.java | 14 +- 21 files changed, 344 insertions(+), 66 deletions(-) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/{ApiCaseExecutePageRequest.java => ExecutePageRequest.java} (82%) rename backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/{ApiCaseReportDTO.java => ExecuteReportDTO.java} (93%) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java index ac3ee0499e..89ac380945 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/file/MinioRepository.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.file; -import io.metersphere.plugin.sdk.util.PluginUtils; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.LogUtils; import io.minio.*; @@ -50,7 +49,7 @@ public class MinioRepository implements FileRepository { try { Object serverUrl = minioConfig.get(ENDPOINT).toString(); if (ObjectUtils.isNotEmpty(serverUrl)) { - LogUtils.info("开始初始化MinIO插件。配置:{}", PluginUtils.toJSONString(minioConfig)); + LogUtils.info("开始初始化MinIO插件"); // 创建 MinioClient 客户端 client = MinioClient.builder() .endpoint(minioConfig.get(ENDPOINT).toString()) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index 5716aa701b..b3070fdc4f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -206,7 +206,7 @@ public class ApiTestCaseController { @Operation(summary = "接口测试-接口管理-接口用例-获取执行历史") @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}) @CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case") - public Pager> getExecuteList(@Validated @RequestBody ApiCaseExecutePageRequest request) { + public Pager> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request)); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index 8d86cfcc6b..9e5c8ae340 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -4,12 +4,16 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.constants.ApiResource; import io.metersphere.api.domain.ApiScenario; +import io.metersphere.api.dto.definition.ExecutePageRequest; +import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.scenario.*; import io.metersphere.api.service.ApiValidateService; import io.metersphere.api.service.scenario.ApiScenarioLogService; import io.metersphere.api.service.scenario.ApiScenarioNoticeService; import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.OperationHistoryDTO; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -208,5 +212,24 @@ public class ApiScenarioController { apiScenarioService.editPos(request); } + @PostMapping("/execute/page") + @Operation(summary = "接口测试-接口场景管理-场景-获取执行历史") + @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_UPDATE}) + @CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario") + public Pager> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); + return PageUtils.setPageInfo(page, apiScenarioService.getExecuteList(request)); + } + + @PostMapping("/operation-history/page") + @Operation(summary = "接口测试-接口场景管理-场景-接口变更历史") + @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_UPDATE}) + @CheckOwner(resourceId = "#request.getSourceId()", resourceType = "api_scenario") + public Pager> operationHistoryList(@Validated @RequestBody OperationHistoryRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + return PageUtils.setPageInfo(page, apiScenarioService.operationHistoryList(request)); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseExecutePageRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecutePageRequest.java similarity index 82% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseExecutePageRequest.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecutePageRequest.java index 443471f3a9..8d312e20d4 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseExecutePageRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecutePageRequest.java @@ -12,12 +12,12 @@ import java.io.Serializable; @Data @EqualsAndHashCode(callSuper = false) -public class ApiCaseExecutePageRequest extends BasePageRequest implements Serializable { +public class ExecutePageRequest extends BasePageRequest implements Serializable { @Serial private static final long serialVersionUID = 1L; - @Schema(description = "用例pk") + @Schema(description = "用例id/场景id") @NotBlank(message = "{api_test_case.id.not_blank}") @Size(min = 1, max = 50, message = "{api_test_case.id.length_range}") private String id; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseReportDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java similarity index 93% rename from backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseReportDTO.java rename to backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java index d903e5488d..7b6c013744 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseReportDTO.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java @@ -6,7 +6,7 @@ import lombok.Data; import java.io.Serializable; @Data -public class ApiCaseReportDTO implements Serializable { +public class ExecuteReportDTO implements Serializable { @Schema(description = "接口报告pk") private String id; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/listener/DebugListener.java b/backend/services/api-test/src/main/java/io/metersphere/api/listener/DebugListener.java index b25c622204..a3336b1134 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/listener/DebugListener.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/listener/DebugListener.java @@ -23,10 +23,12 @@ public class DebugListener { LogUtils.info("接收到执行结果:{}", record.key()); if (ObjectUtils.isNotEmpty(record.value()) && WebSocketUtils.has(record.key().toString())) { SocketMsgDTO dto = JSON.parseObject(record.value(), SocketMsgDTO.class); + + LogUtils.info("{} 推送执行结果类型【 {} 】", record.key(), dto.getMsgType()); WebSocketUtils.sendMessageSingle(dto); } } catch (Exception e) { - LogUtils.error("调试消息推送失败:{}", e); + LogUtils.error("{} 调试消息推送失败:{}", record.key(), e); } } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java index f0c4f9d795..40eb6964af 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java @@ -1,6 +1,8 @@ package io.metersphere.api.mapper; import io.metersphere.api.domain.ApiScenario; +import io.metersphere.api.dto.definition.ExecutePageRequest; +import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.scenario.*; import io.metersphere.dto.TestCaseProviderDTO; import io.metersphere.project.dto.ModuleCountDTO; @@ -40,4 +42,5 @@ public interface ExtApiScenarioMapper { Long getLastPosEdit(@Param("projectId") String projectId, @Param("basePos") Long basePos); + List getExecuteList(@Param("request") ExecutePageRequest request); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 276ceba6c9..e7bfaa7c6d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -444,4 +444,47 @@ order by `pos` desc limit 1; + + + + + + + + + + and api_scenario_report.integrated in + + + + and api_scenario_report.status in + + + + and api_scenario_report.trigger_mode in + + + + + + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java index 0bf4bac2ef..42b2e2de5b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.java @@ -10,12 +10,10 @@ import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.TestCasePageProviderRequest; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.OptionDTO; -import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; -import java.util.Map; /** * @author jianxing @@ -59,7 +57,7 @@ public interface ExtApiTestCaseMapper { List getTagsByIds(@Param("ids") List ids, @Param("deleted") boolean deleted); - List getExecuteList(@Param("request") ApiCaseExecutePageRequest request); + List getExecuteList(@Param("request") ExecutePageRequest request); List selectVersionOptionByIds(@Param("ids") List ids); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml index 428cb7bf6e..03c80ab6b3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml @@ -229,7 +229,7 @@ #{id} - select api_report.id, api_report.name, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index b5f58dceb6..bd58c72ded 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -2,10 +2,7 @@ package io.metersphere.api.service.definition; import io.metersphere.api.domain.*; import io.metersphere.api.dto.definition.*; -import io.metersphere.api.mapper.ApiReportDetailMapper; -import io.metersphere.api.mapper.ApiReportMapper; -import io.metersphere.api.mapper.ApiReportStepMapper; -import io.metersphere.api.mapper.ExtApiReportMapper; +import io.metersphere.api.mapper.*; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.sdk.dto.api.result.RequestResult; import io.metersphere.sdk.exception.MSException; @@ -47,17 +44,23 @@ public class ApiReportService { @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) - public void insertApiReport(List reports) { + public void insertApiReport(List reports, List records) { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); if (CollectionUtils.isNotEmpty(reports)) { - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiReportMapper reportMapper = sqlSession.getMapper(ApiReportMapper.class); SubListUtils.dealForSubList(reports, 1000, subList -> { subList.forEach(reportMapper::insertSelective); }); - sqlSession.flushStatements(); - if (sqlSessionFactory != null) { - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } + } + if (CollectionUtils.isNotEmpty(records)) { + ApiTestCaseRecordMapper detailMapper = sqlSession.getMapper(ApiTestCaseRecordMapper.class); + SubListUtils.dealForSubList(records, 1000, subList -> { + subList.forEach(detailMapper::insertSelective); + }); + } + sqlSession.flushStatements(); + if (sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index adbdacbdaa..e9c01c4ac6 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -560,8 +560,8 @@ public class ApiTestCaseService { return apiTestCaseBlobMapper.selectByExampleWithBLOBs(example); } - public List getExecuteList(ApiCaseExecutePageRequest request) { - List executeList = extApiTestCaseMapper.getExecuteList(request); + public List getExecuteList(ExecutePageRequest request) { + List executeList = extApiTestCaseMapper.getExecuteList(request); if (CollectionUtils.isEmpty(executeList)) { return new ArrayList<>(); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index 4d3a14ea7b..bdfcc48055 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -6,10 +6,7 @@ import io.metersphere.api.dto.definition.ApiReportPageRequest; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO; -import io.metersphere.api.mapper.ApiScenarioReportDetailMapper; -import io.metersphere.api.mapper.ApiScenarioReportMapper; -import io.metersphere.api.mapper.ApiScenarioReportStepMapper; -import io.metersphere.api.mapper.ExtApiScenarioReportMapper; +import io.metersphere.api.mapper.*; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.sdk.dto.api.result.RequestResult; import io.metersphere.sdk.exception.MSException; @@ -50,17 +47,23 @@ public class ApiScenarioReportService { private ApiScenarioReportDetailMapper apiScenarioReportDetailMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) - public void insertApiScenarioReport(List reports) { + public void insertApiScenarioReport(List reports, List records) { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); if (CollectionUtils.isNotEmpty(reports)) { - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiScenarioReportMapper reportMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); SubListUtils.dealForSubList(reports, 1000, subList -> { subList.forEach(reportMapper::insertSelective); }); - sqlSession.flushStatements(); - if (sqlSessionFactory != null) { - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } + } + if (CollectionUtils.isNotEmpty(records)) { + ApiScenarioRecordMapper detailMapper = sqlSession.getMapper(ApiScenarioRecordMapper.class); + SubListUtils.dealForSubList(records, 1000, subList -> { + subList.forEach(detailMapper::insertSelective); + }); + } + sqlSession.flushStatements(); + if (sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 24dd813f07..5dd7ef32f0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -7,6 +7,8 @@ import io.metersphere.api.domain.*; import io.metersphere.api.dto.*; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; import io.metersphere.api.dto.debug.ApiResourceRunRequest; +import io.metersphere.api.dto.definition.ExecutePageRequest; +import io.metersphere.api.dto.definition.ExecuteReportDTO; import io.metersphere.api.dto.request.MsScenario; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.response.ApiScenarioBatchOperationResponse; @@ -54,6 +56,8 @@ import io.metersphere.sdk.util.*; import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.dto.LogInsertModule; +import io.metersphere.system.dto.OperationHistoryDTO; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.ScheduleConfig; import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.constants.OperationLogModule; @@ -61,6 +65,7 @@ import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.schedule.ScheduleService; import io.metersphere.system.service.ApiPluginService; +import io.metersphere.system.service.OperationHistoryService; import io.metersphere.system.service.UserLoginService; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.NumGenerator; @@ -86,11 +91,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; - import static io.metersphere.api.controller.result.ApiResultCode.API_SCENARIO_EXIST; @Service @@ -169,12 +174,16 @@ public class ApiScenarioService { @Resource private ApiDefinitionModuleService apiDefinitionModuleService; @Resource + private OperationHistoryService operationHistoryService; + @Resource private ApiCommonService apiCommonService; - + + public static final String PRIORITY = "Priority"; public static final String STATUS = "Status"; public static final String TAGS = "Tags"; public static final String ENVIRONMENT = "Environment"; + private static final String SCENARIO_TABLE = "api_scenario"; public List getScenarioPage(ApiScenarioPageRequest request) { @@ -2057,6 +2066,28 @@ public class ApiScenarioService { apiScenarioMapper::updateByPrimaryKeySelective); } + public List getExecuteList(ExecutePageRequest request) { + List executeList = extApiScenarioMapper.getExecuteList(request); + if (CollectionUtils.isEmpty(executeList)) { + return new ArrayList<>(); + } + Set userSet = executeList.stream() + .flatMap(apiReport -> Stream.of(apiReport.getCreateUser())) + .collect(Collectors.toSet()); + Map userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet)); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + executeList.forEach(apiReport -> { + apiReport.setOperationUser(userMap.get(apiReport.getCreateUser())); + Date date = new Date(apiReport.getStartTime()); + apiReport.setNum(sdf.format(date)); + }); + return executeList; + } + + public List operationHistoryList(OperationHistoryRequest request) { + return operationHistoryService.listWidthTable(request, SCENARIO_TABLE); + } + public void handleFileAssociationUpgrade(FileAssociation originFileAssociation, FileMetadata newFileMetadata) { // 查询有步骤详情的请求类型的步骤 List stepIds = extApiScenarioStepMapper.getHasBlobRequestStepIds(originFileAssociation.getSourceId()); @@ -2085,4 +2116,4 @@ public class ApiScenarioService { } } } -} \ No newline at end of file +} diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java index 2fc7902cb2..a5e5fa1b3e 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java @@ -4,6 +4,7 @@ import io.metersphere.api.constants.ShareInfoType; import io.metersphere.api.domain.ApiReport; import io.metersphere.api.domain.ApiReportDetail; import io.metersphere.api.domain.ApiReportStep; +import io.metersphere.api.domain.ApiTestCaseRecord; import io.metersphere.api.dto.definition.ApiReportBatchRequest; import io.metersphere.api.dto.definition.ApiReportDTO; import io.metersphere.api.dto.definition.ApiReportDetailDTO; @@ -72,6 +73,7 @@ public class ApiReportControllerTests extends BaseTest { @Order(1) public void testInsert() { List reports = new ArrayList<>(); + List records = new ArrayList<>(); for (int i = 0; i < 2515; i++) { ApiReport apiReport = new ApiReport(); apiReport.setId("api-report-id" + i); @@ -92,8 +94,12 @@ public class ApiReportControllerTests extends BaseTest { apiReport.setTriggerMode("api-trigger-mode" + i); apiReport.setVersionId("api-version-id" + i); reports.add(apiReport); + ApiTestCaseRecord record = new ApiTestCaseRecord(); + record.setApiTestCaseId("api-resource-id" + i); + record.setApiReportId(apiReport.getId()); + records.add(record); } - apiReportService.insertApiReport(reports); + apiReportService.insertApiReport(reports, records); List steps = new ArrayList<>(); for (int i = 0; i < 1515; i++) { @@ -240,7 +246,10 @@ public class ApiReportControllerTests extends BaseTest { apiReport.setTriggerMode("api-trigger-mode"); apiReport.setVersionId("api-version-id"); reports.add(apiReport); - apiReportService.insertApiReport(reports); + ApiTestCaseRecord record = new ApiTestCaseRecord(); + record.setApiTestCaseId("api-resource-id"); + record.setApiReportId(apiReport.getId()); + apiReportService.insertApiReport(reports, List.of(record)); List steps = new ArrayList<>(); for (int i = 0; i < 5; i++) { ApiReportStep apiReportStep = new ApiReportStep(); @@ -294,7 +303,7 @@ public class ApiReportControllerTests extends BaseTest { List data = ApiDataUtils.parseArray(JSON.toJSONString(parseResponse(mvcResult).get("data")), ApiReportDetailDTO.class); Assertions.assertNotNull(data); - mockMvc.perform(getRequestBuilder(DETAIL + "test")) + mockMvc.perform(getRequestBuilder(DETAIL + "test" + "/test")) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is5xxServerError()); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java index 1321a89e0e..56376a6548 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java @@ -1,9 +1,6 @@ package io.metersphere.api.controller; -import io.metersphere.api.domain.ApiReport; -import io.metersphere.api.domain.ApiScenario; -import io.metersphere.api.domain.ApiScenarioReport; -import io.metersphere.api.domain.ApiTestCase; +import io.metersphere.api.domain.*; import io.metersphere.api.mapper.ApiScenarioMapper; import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.service.ApiReportSendNoticeService; @@ -78,6 +75,7 @@ public class ApiReportSendNoticeTests extends BaseTest { apiTestCaseMapper.insert(apiTestCase); List reports = new ArrayList<>(); + List records = new ArrayList<>(); for (int i = 0; i < 3; i++) { ApiReport apiReport = new ApiReport(); apiReport.setId("send-api-case-report-id" + i); @@ -100,8 +98,12 @@ public class ApiReportSendNoticeTests extends BaseTest { apiReport.setTriggerMode("api-trigger-mode" + i); apiReport.setVersionId("api-version-id" + i); reports.add(apiReport); + ApiTestCaseRecord record = new ApiTestCaseRecord(); + record.setApiTestCaseId("send-api-resource-id" + i); + record.setApiReportId(apiReport.getId()); + records.add(record); } - apiReportService.insertApiReport(reports); + apiReportService.insertApiReport(reports, records); ApiNoticeDTO noticeDTO = new ApiNoticeDTO(); noticeDTO.setReportId("send-api-case-report-id0"); noticeDTO.setReportStatus(ApiReportStatus.SUCCESS.name()); @@ -140,6 +142,7 @@ public class ApiReportSendNoticeTests extends BaseTest { apiScenarioMapper.insertSelective(apiScenario); List scenarioReports = new ArrayList<>(); + List scenarioRecords = new ArrayList<>(); for (int i = 0; i < 3; i++) { ApiScenarioReport scenarioReport = new ApiScenarioReport(); scenarioReport.setId("send-scenario-report-id" + i); @@ -162,8 +165,12 @@ public class ApiReportSendNoticeTests extends BaseTest { scenarioReport.setTriggerMode("api-trigger-mode" + i); scenarioReport.setVersionId("api-version-id" + i); scenarioReports.add(scenarioReport); + ApiScenarioRecord record = new ApiScenarioRecord(); + record.setApiScenarioId("send-scenario-id" + i); + record.setApiScenarioReportId(scenarioReport.getId()); + scenarioRecords.add(record); } - apiScenarioReportService.insertApiScenarioReport(scenarioReports); + apiScenarioReportService.insertApiScenarioReport(scenarioReports, scenarioRecords); noticeDTO = new ApiNoticeDTO(); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index 6d072ed4ee..4561d04886 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -5,9 +5,7 @@ import io.metersphere.api.domain.*; import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.assertion.MsAssertionConfig; import io.metersphere.api.dto.debug.ModuleCreateRequest; -import io.metersphere.api.dto.definition.ApiDefinitionAddRequest; -import io.metersphere.api.dto.definition.ApiTestCaseAddRequest; -import io.metersphere.api.dto.definition.HttpResponse; +import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.http.Header; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.QueryParam; @@ -23,6 +21,7 @@ import io.metersphere.api.service.BaseResourcePoolTestService; import io.metersphere.api.service.definition.ApiDefinitionModuleService; import io.metersphere.api.service.definition.ApiDefinitionService; import io.metersphere.api.service.definition.ApiTestCaseService; +import io.metersphere.api.service.scenario.ApiScenarioReportService; import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; @@ -31,6 +30,7 @@ import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.assertion.MsScriptAssertion; import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.SQLProcessor; +import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.dto.environment.EnvironmentConfig; import io.metersphere.project.dto.environment.EnvironmentGroupProjectDTO; import io.metersphere.project.dto.environment.EnvironmentGroupRequest; @@ -43,6 +43,7 @@ import io.metersphere.project.dto.environment.processors.EnvRequestScriptProcess import io.metersphere.project.dto.environment.processors.EnvScenarioScriptProcessor; import io.metersphere.project.dto.filemanagement.request.FileUploadRequest; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; +import io.metersphere.project.mapper.ProjectVersionMapper; import io.metersphere.project.service.EnvironmentGroupService; import io.metersphere.project.service.EnvironmentService; import io.metersphere.project.service.FileMetadataService; @@ -61,10 +62,13 @@ import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.Plugin; import io.metersphere.system.domain.Schedule; +import io.metersphere.system.dto.OperationHistoryDTO; +import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.PluginUpdateRequest; import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.ScheduleMapper; +import io.metersphere.system.service.OperationHistoryService; import io.metersphere.system.service.PluginService; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.NumGenerator; @@ -80,6 +84,7 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultMatcher; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.io.File; import java.io.FileInputStream; @@ -90,6 +95,7 @@ import java.util.stream.Collectors; import static io.metersphere.api.controller.result.ApiResultCode.API_SCENARIO_EXIST; import static io.metersphere.sdk.constants.InternalUserRole.ADMIN; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -162,9 +168,16 @@ public class ApiScenarioControllerTests extends BaseTest { @Resource private ApiDefinitionModuleService apiDefinitionModuleService; @Resource + private ApiScenarioReportService apiScenarioReportService; + @Resource + private ProjectVersionMapper projectVersionMapper; + @Resource + private OperationHistoryService operationHistoryService; + @Resource private BaseFileManagementTestService baseFileManagementTestService; @Resource private ApiCommonService apiCommonService; + private static String fileMetadataId; private static String localFileId; private static ApiScenario addApiScenario; @@ -2194,6 +2207,125 @@ public class ApiScenarioControllerTests extends BaseTest { } + @Test + @Order(10) + public void testExecuteList() throws Exception { + ApiScenario first = apiScenarioMapper.selectByExample(new ApiScenarioExample()).getFirst(); + List reports = new ArrayList<>(); + List records = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + ApiScenarioReport apiReport = new ApiScenarioReport(); + apiReport.setId(IDGenerator.nextStr()); + apiReport.setProjectId(DEFAULT_PROJECT_ID); + apiReport.setName("api-scenario-name" + i); + apiReport.setStartTime(System.currentTimeMillis()); + apiReport.setCreateUser("admin"); + apiReport.setUpdateUser("admin"); + apiReport.setUpdateTime(System.currentTimeMillis()); + apiReport.setPoolId("api-pool-id" + i); + apiReport.setEnvironmentId("api-environment-id" + i); + apiReport.setRunMode("api-run-mode" + i); + if (i % 2 == 0) { + apiReport.setStatus(ApiReportStatus.SUCCESS.name()); + } else { + apiReport.setStatus(ApiReportStatus.ERROR.name()); + } + apiReport.setTriggerMode("api-trigger-mode" + i); + apiReport.setVersionId("api-version-id" + i); + reports.add(apiReport); + ApiScenarioRecord record = new ApiScenarioRecord(); + record.setApiScenarioId(first.getId()); + record.setApiScenarioReportId(apiReport.getId()); + records.add(record); + } + apiScenarioReportService.insertApiScenarioReport(reports, records); + ExecutePageRequest request = new ExecutePageRequest(); + request.setId(first.getId()); + request.setPageSize(10); + request.setCurrent(1); + MvcResult mvcResult = responsePost(BASE_PATH + "execute/page", request); + Pager returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //返回值不为空 + Assertions.assertNotNull(returnPager); + request.setFilter(new HashMap<>() {{ + put("status", List.of(ApiReportStatus.SUCCESS.name())); + }}); + request.setSort(new HashMap<>() {{ + put("startTime", "desc"); + }}); + mvcResult = responsePost(BASE_PATH + "execute/page", request); + returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //返回值不为空 + Assertions.assertNotNull(returnPager); + Assertions.assertTrue(((List) returnPager.getList()).size() <= request.getPageSize()); + List reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ExecuteReportDTO.class); + reportDTOS.forEach(apiReport -> { + Assertions.assertEquals(apiReport.getStatus(), ApiReportStatus.SUCCESS.name()); + }); + request.setId("data-is-null"); + responsePost(BASE_PATH + "execute/page", request); + } + + public static T parseObjectFromMvcResult(MvcResult mvcResult, Class parseClass) { + try { + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + //返回请求正常 + Assertions.assertNotNull(resultHolder); + return JSON.parseObject(JSON.toJSONString(resultHolder.getData()), parseClass); + } catch (Exception ignore) { + } + return null; + } + + private MvcResult responsePost(String url, Object param) throws Exception { + return mockMvc.perform(MockMvcRequestBuilders.post(url) + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .content(JSON.toJSONString(param)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + } + + @Test + @Order(11) + public void testGetHistory() throws Exception { + ApiScenario first = apiScenarioMapper.selectByExample(new ApiScenarioExample()).getFirst(); + OperationHistoryRequest request = new OperationHistoryRequest(); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setSourceId(first.getId()); + request.setPageSize(10); + request.setCurrent(1); + + projectVersionMapper.deleteByPrimaryKey("1.0"); + ProjectVersion version = new ProjectVersion(); + version.setId("1.0"); + version.setName("1.0"); + version.setProjectId(DEFAULT_PROJECT_ID); + version.setCreateTime(System.currentTimeMillis()); + version.setLatest(true); + version.setCreateUser("admin"); + projectVersionMapper.insertSelective(version); + + MvcResult mvcResult = responsePost(BASE_PATH + "operation-history/page", request); + Pager returnPager = parseObjectFromMvcResult(mvcResult, Pager.class); + //返回值不为空 + Assertions.assertNotNull(returnPager); + List reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), OperationHistoryDTO.class); + reportDTOS.forEach(reportDTO -> Assertions.assertEquals(reportDTO.getSourceId(), first.getId())); + + request = new OperationHistoryRequest(); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setSourceId("data-is-null"); + request.setPageSize(10); + request.setCurrent(1); + request.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + responsePost(BASE_PATH + "operation-history/page", request); + } + @Test @Order(35) public void testGetSystemRequest() throws Exception { diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java index 512a3125b1..f88980e479 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java @@ -1,10 +1,7 @@ package io.metersphere.api.controller; import io.metersphere.api.constants.ShareInfoType; -import io.metersphere.api.domain.ApiReport; -import io.metersphere.api.domain.ApiScenarioReport; -import io.metersphere.api.domain.ApiScenarioReportDetail; -import io.metersphere.api.domain.ApiScenarioReportStep; +import io.metersphere.api.domain.*; import io.metersphere.api.dto.definition.ApiReportBatchRequest; import io.metersphere.api.dto.definition.ApiReportPageRequest; import io.metersphere.api.dto.scenario.ApiScenarioDTO; @@ -71,6 +68,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { @Order(1) public void testInsert() { List reports = new ArrayList<>(); + List records = new ArrayList<>(); for (int i = 0; i < 2515; i++) { ApiScenarioReport scenarioReport = new ApiScenarioReport(); scenarioReport.setId("scenario-report-id" + i); @@ -91,8 +89,12 @@ public class ApiScenarioReportControllerTests extends BaseTest { scenarioReport.setTriggerMode("api-trigger-mode" + i); scenarioReport.setVersionId("api-version-id" + i); reports.add(scenarioReport); + ApiScenarioRecord apiScenarioRecord = new ApiScenarioRecord(); + apiScenarioRecord.setApiScenarioId("scenario-record-id" + i); + apiScenarioRecord.setApiScenarioReportId(scenarioReport.getId()); + records.add(apiScenarioRecord); } - apiScenarioReportService.insertApiScenarioReport(reports); + apiScenarioReportService.insertApiScenarioReport(reports, records); List steps = new ArrayList<>(); for (int i = 0; i < 1515; i++) { @@ -239,7 +241,10 @@ public class ApiScenarioReportControllerTests extends BaseTest { scenarioReport.setTriggerMode("api-trigger-mode"); scenarioReport.setVersionId("api-version-id"); reports.add(scenarioReport); - apiScenarioReportService.insertApiScenarioReport(reports); + ApiScenarioRecord apiScenarioRecord = new ApiScenarioRecord(); + apiScenarioRecord.setApiScenarioId("test-scenario-record-id"); + apiScenarioRecord.setApiScenarioReportId(scenarioReport.getId()); + apiScenarioReportService.insertApiScenarioReport(reports, List.of(apiScenarioRecord)); List steps = new ArrayList<>(); for (int i = 0; i < 20; i++) { ApiScenarioReportStep apiScenarioReportStep = new ApiScenarioReportStep(); @@ -299,7 +304,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { List data = ApiDataUtils.parseArray(JSON.toJSONString(parseResponse(mvcResult).get("data")), ApiScenarioReportDTO.class); Assertions.assertNotNull(data); - mockMvc.perform(getRequestBuilder(DETAIL + "test")) + mockMvc.perform(getRequestBuilder(DETAIL + "test" + "/" + "test")) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is5xxServerError()); @@ -349,9 +354,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { mockMvc.perform(getRequestBuilder(GET + shareId + "/" + "test-scenario-report-id")) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is5xxServerError()); - - //TODO 过期的校验 未完成 需要补充 - //项目当前设置了分享时间 并且没有过期 + shareInfo = new ShareInfo(); shareInfo.setCustomData("test-scenario-report-id".getBytes()); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTaskCenterControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTaskCenterControllerTests.java index 49b1324c0d..e5f98f5888 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTaskCenterControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTaskCenterControllerTests.java @@ -1,7 +1,9 @@ package io.metersphere.api.controller; import io.metersphere.api.domain.ApiReport; +import io.metersphere.api.domain.ApiScenarioRecord; import io.metersphere.api.domain.ApiScenarioReport; +import io.metersphere.api.domain.ApiTestCaseRecord; import io.metersphere.api.service.BaseResourcePoolTestService; import io.metersphere.api.service.definition.ApiReportService; import io.metersphere.api.service.scenario.ApiScenarioReportService; @@ -226,6 +228,7 @@ public class ApiTaskCenterControllerTests extends BaseTest { public void testInsertData() { List reports = new ArrayList<>(); + List records = new ArrayList<>(); for (int i = 0; i < 10; i++) { ApiReport apiReport = new ApiReport(); apiReport.setId("task-report-id" + i); @@ -246,10 +249,15 @@ public class ApiTaskCenterControllerTests extends BaseTest { apiReport.setTriggerMode("task-MANUAL"); apiReport.setVersionId("api-version-id" + i); reports.add(apiReport); + ApiTestCaseRecord record = new ApiTestCaseRecord(); + record.setApiTestCaseId("task-api-resource-id" + i); + record.setApiReportId(apiReport.getId()); + records.add(record); } - apiReportService.insertApiReport(reports); + apiReportService.insertApiReport(reports, records); List scenarioReports = new ArrayList<>(); + List scenarioRecords = new ArrayList<>(); for (int i = 0; i < 10; i++) { ApiScenarioReport scenarioReport = new ApiScenarioReport(); scenarioReport.setId("task-report-id" + i); @@ -270,8 +278,12 @@ public class ApiTaskCenterControllerTests extends BaseTest { scenarioReport.setTriggerMode("task-MANUAL"); scenarioReport.setVersionId("api-version-id" + i); scenarioReports.add(scenarioReport); + ApiScenarioRecord scenarioRecord = new ApiScenarioRecord(); + scenarioRecord.setApiScenarioId("task-api-resource-id" + i); + scenarioRecord.setApiScenarioReportId(scenarioReport.getId()); + scenarioRecords.add(scenarioRecord); } - apiScenarioReportService.insertApiScenarioReport(scenarioReports); + apiScenarioReportService.insertApiScenarioReport(scenarioReports, scenarioRecords); TestResourcePoolDTO testResourcePool = new TestResourcePoolDTO(); testResourcePool.setId("api-pool-id"); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java index 54716ccdc1..180674fb50 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java @@ -624,9 +624,8 @@ public class ApiTestCaseControllerTests extends BaseTest { record.setApiReportId(apiReport.getId()); records.add(record); } - apiTestCaseRecordMapper.batchInsert(records); - apiReportService.insertApiReport(reports); - ApiCaseExecutePageRequest request = new ApiCaseExecutePageRequest(); + apiReportService.insertApiReport(reports, records); + ExecutePageRequest request = new ExecutePageRequest(); request.setId(first.getId()); request.setPageSize(10); request.setCurrent(1); @@ -642,7 +641,7 @@ public class ApiTestCaseControllerTests extends BaseTest { //返回值不为空 Assertions.assertNotNull(returnPager); Assertions.assertTrue(((List) returnPager.getList()).size() <= request.getPageSize()); - List reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ApiCaseReportDTO.class); + List reportDTOS = JSON.parseArray(JSON.toJSONString(returnPager.getList()), ExecuteReportDTO.class); reportDTOS.forEach(apiReport -> { Assertions.assertEquals(apiReport.getStatus(), ApiReportStatus.SUCCESS.name()); }); @@ -849,6 +848,7 @@ public class ApiTestCaseControllerTests extends BaseTest { request.setSourceId(first.getId()); request.setPageSize(10); request.setCurrent(1); + projectVersionMapper.deleteByPrimaryKey("1.0"); ProjectVersion version = new ProjectVersion(); version.setId("1.0"); version.setName("1.0"); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupApiTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupApiTests.java index cc237463ee..fda799babc 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupApiTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupApiTests.java @@ -235,6 +235,7 @@ public class CleanupApiTests { private void initReportData(String projectId) { List reports = new ArrayList<>(); + List records = new ArrayList<>(); for (int i = 0; i < 2515; i++) { ApiReport apiReport = new ApiReport(); apiReport.setId("clean-report-id" + projectId + i); @@ -255,8 +256,12 @@ public class CleanupApiTests { apiReport.setTriggerMode("api-trigger-mode" + i); apiReport.setVersionId("api-version-id" + i); reports.add(apiReport); + ApiTestCaseRecord record = new ApiTestCaseRecord(); + record.setApiTestCaseId("clean-resource-id" + i); + record.setApiReportId(apiReport.getId()); + records.add(record); } - apiReportService.insertApiReport(reports); + apiReportService.insertApiReport(reports, records); List steps = new ArrayList<>(); for (int i = 0; i < 1515; i++) { ApiReportStep apiReportStep = new ApiReportStep(); @@ -269,6 +274,7 @@ public class CleanupApiTests { apiReportService.insertApiReportStep(steps); List scenarioReports = new ArrayList<>(); + List scenarioRecords = new ArrayList<>(); for (int i = 0; i < 2515; i++) { ApiScenarioReport scenarioReport = new ApiScenarioReport(); scenarioReport.setId("clean-scenario-report-id" + projectId + i); @@ -289,8 +295,12 @@ public class CleanupApiTests { scenarioReport.setTriggerMode("api-trigger-mode" + i); scenarioReport.setVersionId("api-version-id" + i); scenarioReports.add(scenarioReport); + ApiScenarioRecord record = new ApiScenarioRecord(); + record.setApiScenarioId("clean-scenario-id" + i); + record.setApiScenarioReportId(scenarioReport.getId()); + scenarioRecords.add(record); } - apiScenarioReportService.insertApiScenarioReport(scenarioReports); + apiScenarioReportService.insertApiScenarioReport(scenarioReports, scenarioRecords); List scenarioReportSteps = new ArrayList<>(); for (int i = 0; i < 1515; i++) {