From d82a2a1bab07fd5a82fb2b5dc8217c522af4235d Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 29 Feb 2024 20:22:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E8=BD=AC=E5=AD=98=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/debug/ApiDebugController.java | 21 +++++ .../definition/ApiDefinitionController.java | 22 +++++ .../definition/ApiTestCaseController.java | 21 +++++ .../scenario/ApiScenarioController.java | 21 +++++ .../api/dto/request/ApiFileRequest.java | 32 +++++++ .../api/dto/request/ApiTransferRequest.java | 17 ++++ .../api/service/ApiFileResourceService.java | 89 +++++++++++++++++++ .../api/service/debug/ApiDebugService.java | 6 ++ .../definition/ApiDefinitionService.java | 5 ++ .../definition/ApiTestCaseService.java | 7 +- .../service/scenario/ApiScenarioService.java | 18 ++-- .../controller/ApiDebugControllerTests.java | 31 +++++++ .../ApiDefinitionControllerTests.java | 41 +++++++-- .../ApiScenarioControllerTests.java | 40 +++++++-- .../ApiTestCaseControllerTests.java | 37 ++++++-- 15 files changed, 379 insertions(+), 29 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiFileRequest.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiTransferRequest.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugController.java index 5c3ffb65b1..57e5afbb55 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/debug/ApiDebugController.java @@ -3,10 +3,13 @@ package io.metersphere.api.controller.debug; import io.metersphere.api.domain.ApiDebug; import io.metersphere.api.dto.debug.*; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.service.debug.ApiDebugLogService; import io.metersphere.api.service.debug.ApiDebugService; +import io.metersphere.project.service.FileModuleService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.dto.api.task.TaskRequestDTO; +import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.security.CheckOwner; @@ -33,6 +36,8 @@ public class ApiDebugController { @Resource private ApiDebugService apiDebugService; + @Resource + private FileModuleService fileModuleService; @GetMapping("/list/{protocol}") @Operation(summary = "获取接口调试列表") @@ -94,4 +99,20 @@ public class ApiDebugController { public void editPos(@Validated @RequestBody ApiEditPosRequest request) { apiDebugService.editPos(request, SessionUtils.getUserId()); } + + @PostMapping("/transfer") + @Operation(summary = "接口测试-接口调试-附件-文件转存") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEBUG_READ) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public String transfer(@Validated @RequestBody ApiTransferRequest request) { + return apiDebugService.transfer(request, SessionUtils.getUserId()); + } + + @GetMapping("/transfer/options/{projectId}") + @Operation(summary = "接口测试-接口调试-附件-转存目录下拉框") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEBUG_READ) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public List options(@PathVariable String projectId) { + return fileModuleService.getTree(projectId); + } } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java index e0b00d869d..98f355ac3b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java @@ -5,14 +5,17 @@ import com.github.pagehelper.PageHelper; import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.service.definition.ApiDefinitionLogService; import io.metersphere.api.service.definition.ApiDefinitionNoticeService; import io.metersphere.api.service.definition.ApiDefinitionService; +import io.metersphere.project.service.FileModuleService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.OperationHistoryDTO; import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.OperationHistoryVersionRequest; +import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.notice.annotation.SendNotice; @@ -44,6 +47,8 @@ import java.util.List; public class ApiDefinitionController { @Resource private ApiDefinitionService apiDefinitionService; + @Resource + private FileModuleService fileModuleService; @PostMapping(value = "/add") @Operation(summary = "接口测试-接口管理-添加接口定义") @@ -244,4 +249,21 @@ public class ApiDefinitionController { public void editPos(@Validated @RequestBody ApiEditPosRequest request) { apiDefinitionService.editPos(request, SessionUtils.getUserId()); } + + @GetMapping("/transfer/options/{projectId}") + @Operation(summary = "接口测试-接口管理-接口-附件-转存目录下拉框") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public List options(@PathVariable String projectId) { + return fileModuleService.getTree(projectId); + } + + @PostMapping("/transfer") + @Operation(summary = "接口测试-接口管理-接口-附件-文件转存") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public String transfer(@Validated @RequestBody ApiTransferRequest request) { + return apiDefinitionService.transfer(request, SessionUtils.getUserId()); + } + } 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 b3070fdc4f..90188783d2 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 @@ -4,13 +4,16 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.domain.ApiTestCase; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.service.definition.ApiTestCaseLogService; import io.metersphere.api.service.definition.ApiTestCaseNoticeService; import io.metersphere.api.service.definition.ApiTestCaseRecoverService; import io.metersphere.api.service.definition.ApiTestCaseService; +import io.metersphere.project.service.FileModuleService; 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.BaseTreeNode; import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -41,6 +44,8 @@ public class ApiTestCaseController { private ApiTestCaseService apiTestCaseService; @Resource private ApiTestCaseRecoverService apiTestCaseRecoverService; + @Resource + private FileModuleService fileModuleService; @PostMapping(value = "/add") @Operation(summary = "接口测试-接口管理-接口用例-新增") @@ -222,5 +227,21 @@ public class ApiTestCaseController { return PageUtils.setPageInfo(page, apiTestCaseService.operationHistoryList(request)); } + @PostMapping("/transfer") + @Operation(summary = "接口测试-接口管理-接口用例-附件-文件转存") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public String transfer(@Validated @RequestBody ApiTransferRequest request) { + return apiTestCaseService.transfer(request, SessionUtils.getUserId()); + } + + @GetMapping("/transfer/options/{projectId}") + @Operation(summary = "接口测试-接口管理-接口用例-附件-转存目录下拉框") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public List options(@PathVariable String projectId) { + return fileModuleService.getTree(projectId); + } + } 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 9e5c8ae340..27113661f1 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 @@ -6,14 +6,17 @@ 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.request.ApiTransferRequest; 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.project.service.FileModuleService; 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.BaseTreeNode; import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; @@ -43,6 +46,8 @@ public class ApiScenarioController { private ApiScenarioService apiScenarioService; @Resource private ApiValidateService apiValidateService; + @Resource + private FileModuleService fileModuleService; @PostMapping("/page") @Operation(summary = "接口测试-接口场景管理-场景列表(deleted 状态为 1 时为回收站数据)") @@ -232,4 +237,20 @@ public class ApiScenarioController { return PageUtils.setPageInfo(page, apiScenarioService.operationHistoryList(request)); } + @PostMapping("/transfer") + @Operation(summary = "接口测试-接口场景管理-场景-附件-文件转存") + @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public String transfer(@Validated @RequestBody ApiTransferRequest request) { + return apiScenarioService.transfer(request, SessionUtils.getUserId()); + } + + @GetMapping("/transfer/options/{projectId}") + @Operation(summary = "接口测试-接口场景管理-场景-附件-转存目录下拉框") + @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public List options(@PathVariable String projectId) { + return fileModuleService.getTree(projectId); + } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiFileRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiFileRequest.java new file mode 100644 index 0000000000..0a4cfd2264 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiFileRequest.java @@ -0,0 +1,32 @@ +package io.metersphere.api.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class ApiFileRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "项目id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{case_review.project_id.not_blank}") + private String projectId; + + @Schema(description = "资源id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{case_review_functional_case.case_id.not_blank}") + private String sourceId; + + @Schema(description = "文件id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{functional_case_attachment.file_id.not_blank}") + private String fileId; + + @Schema(description = "是否本地", requiredMode = Schema.RequiredMode.REQUIRED) + private Boolean local; + + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiTransferRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiTransferRequest.java new file mode 100644 index 0000000000..61eac9fb6d --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/request/ApiTransferRequest.java @@ -0,0 +1,17 @@ +package io.metersphere.api.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * @author wx + */ +@Data +public class ApiTransferRequest extends ApiFileRequest { + + + @Schema(description = "转存的模块id", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{functional_case.module_id.not_blank}") + private String moduleId; +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java index a2d813d0c7..c0ade8eaa3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiFileResourceService.java @@ -4,17 +4,23 @@ import io.metersphere.api.constants.ApiResourceType; import io.metersphere.api.domain.ApiFileResource; import io.metersphere.api.domain.ApiFileResourceExample; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.mapper.ApiFileResourceMapper; +import io.metersphere.project.dto.filemanagement.FileAssociationDTO; import io.metersphere.project.dto.filemanagement.FileLogRecord; import io.metersphere.project.service.FileAssociationService; +import io.metersphere.project.service.FileService; import io.metersphere.sdk.constants.DefaultRepositoryDir; +import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.file.FileCenter; import io.metersphere.sdk.file.FileCopyRequest; import io.metersphere.sdk.file.FileRepository; import io.metersphere.sdk.file.FileRequest; +import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; @@ -40,6 +46,8 @@ public class ApiFileResourceService { private ApiFileResourceMapper apiFileResourceMapper; @Resource private FileAssociationService fileAssociationService; + @Resource + private FileService fileService; /** * 上传接口相关的资源文件 @@ -287,4 +295,85 @@ public class ApiFileResourceService { public void batchInsert(List insertApiFileResourceList) { apiFileResourceMapper.batchInsert(insertApiFileResourceList); } + + + /** + * 转存附近至文件库 + * + * @param request 请求参数 + * @param currentUser 当前用户 + * @return 文件ID + */ + public String transfer(ApiTransferRequest request, String currentUser, String type) { + ApiFileResourceExample example = new ApiFileResourceExample(); + example.createCriteria().andFileIdEqualTo(request.getFileId()).andResourceIdEqualTo(request.getSourceId()).andResourceTypeEqualTo(type); + List apiFileResources = apiFileResourceMapper.selectByExample(example); + String fileName; + String apiFolder; + String fileId; + String fileAssociationSourceType; + String logModule; + ApiResourceType apiResourceType = ApiResourceType.valueOf(type); + /** + * 这里需要判断临时文件和正式文件的存储路径 + * 临时文件存储路径:DefaultRepositoryDir.getSystemTempDir()+fileId+fileName + * debug正式文件存储路径:DefaultRepositoryDir.getApiDebugDir(projectId, resourceId) + "/" + fileId+fileName + * api正式文件存储路径:DefaultRepositoryDir.getApiDir(projectId, resourceId) + "/" + fileId+fileName + * apiTestCase文件存储路径:DefaultRepositoryDir.getApiCaseDir()+fileId+fileName + * apiScenario文件存储路径:DefaultRepositoryDir.getApiScenarioDir()+fileId+fileName + */ + switch (apiResourceType) { + case ApiResourceType.API_DEBUG -> { + fileAssociationSourceType = FileAssociationSourceUtil.SOURCE_TYPE_API_DEBUG; + logModule = OperationLogModule.API_TEST_DEBUG_MANAGEMENT_DEBUG; + apiFolder = DefaultRepositoryDir.getApiDebugDir(request.getProjectId(), request.getSourceId()) + "/" + request.getFileId(); + } + case ApiResourceType.API -> { + fileAssociationSourceType = FileAssociationSourceUtil.SOURCE_TYPE_API_DEFINITION; + logModule = OperationLogModule.API_TEST_MANAGEMENT_DEFINITION; + apiFolder = DefaultRepositoryDir.getApiDefinitionDir(request.getProjectId(), request.getSourceId()) + "/" + request.getFileId(); + } + case ApiResourceType.API_CASE -> { + fileAssociationSourceType = FileAssociationSourceUtil.SOURCE_TYPE_API_TEST_CASE; + logModule = OperationLogModule.API_TEST_MANAGEMENT_CASE; + apiFolder = DefaultRepositoryDir.getApiCaseDir(request.getProjectId(), request.getSourceId()) + "/" + request.getFileId(); + } + case ApiResourceType.API_SCENARIO -> { + fileAssociationSourceType = FileAssociationSourceUtil.SOURCE_TYPE_API_SCENARIO; + logModule = OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO; + apiFolder = DefaultRepositoryDir.getApiScenarioDir(request.getProjectId(), request.getSourceId()) + "/" + request.getFileId(); + } + default -> throw new MSException("file type error!"); + } + if (CollectionUtils.isEmpty(apiFileResources)) { + //需要判断文件是否是在临时文件夹中 + fileName = getTempFileNameByFileId(request.getFileId()); + apiFolder = StringUtils.join(DefaultRepositoryDir.getSystemTempDir(), "/", request.getFileId()); + if (StringUtils.isEmpty(fileName)) { + throw new MSException("file not found!"); + } + } else { + fileName = apiFileResources.get(0).getFileName(); + } + FileRequest fileRequest = new FileRequest(); + fileRequest.setFolder(apiFolder); + fileRequest.setFileName(StringUtils.isEmpty(fileName) ? null : fileName); + fileRequest.setStorage(StorageType.MINIO.name()); + byte[] bytes; + try { + bytes = fileService.download(fileRequest); + } catch (Exception e) { + throw new MSException("download file error!"); + } + try { + FileAssociationDTO association = new FileAssociationDTO(fileName, bytes, request.getSourceId(), + fileAssociationSourceType, createFileLogRecord(currentUser, request.getProjectId(), logModule)); + association.setModuleId(request.getModuleId()); + fileId = fileAssociationService.transferAndAssociation(association); + } catch (Exception e) { + throw new MSException(Translator.get("file.transfer.error")); + } + return fileId; + } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugService.java index f963742b1c..77fa589456 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/debug/ApiDebugService.java @@ -9,6 +9,7 @@ import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.ApiParamConfig; import io.metersphere.api.dto.debug.*; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.mapper.ApiDebugBlobMapper; import io.metersphere.api.mapper.ApiDebugMapper; import io.metersphere.api.mapper.ApiDebugModuleMapper; @@ -260,6 +261,7 @@ public class ApiDebugService { /** * 处理关联的文件被更新 + * * @param originFileAssociation * @param newFileMetadata */ @@ -281,4 +283,8 @@ public class ApiDebugService { apiDebugBlobMapper.updateByPrimaryKeySelective(apiDebugBlob); } } + + public String transfer(ApiTransferRequest request, String userId) { + return apiFileResourceService.transfer(request, userId, ApiResourceType.API_DEBUG.name()); + } } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index f4a5921d92..e54790cab7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -10,6 +10,7 @@ import io.metersphere.api.dto.converter.ApiDefinitionImport; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.mapper.*; import io.metersphere.api.parser.ImportParser; @@ -1116,4 +1117,8 @@ public class ApiDefinitionService { } } } + + public String transfer(ApiTransferRequest request, String userId) { + return apiFileResourceService.transfer(request, userId, ApiResourceType.API.name()); + } } 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 02b3227f2d..b90151ce9d 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 @@ -6,6 +6,7 @@ import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.ApiResourceModuleInfo; import io.metersphere.api.dto.debug.ApiFileResourceUpdateRequest; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.mapper.*; import io.metersphere.api.service.ApiCommonService; @@ -128,7 +129,7 @@ public class ApiTestCaseService { } private static ApiFileResourceUpdateRequest getApiFileResourceUpdateRequest(String sourceId, String projectId, String operator) { - String apiDebugDir = DefaultRepositoryDir.getApiDebugDir(projectId, sourceId); + String apiDebugDir = DefaultRepositoryDir.getApiCaseDir(projectId, sourceId); ApiFileResourceUpdateRequest resourceUpdateRequest = new ApiFileResourceUpdateRequest(); resourceUpdateRequest.setProjectId(projectId); resourceUpdateRequest.setFolder(apiDebugDir); @@ -626,4 +627,8 @@ public class ApiTestCaseService { apiTestCaseBlobMapper.updateByPrimaryKeySelective(apiTestCaseBlob); } } + + public String transfer(ApiTransferRequest request, String userId) { + return apiFileResourceService.transfer(request, userId, ApiResourceType.API_CASE.name()); + } } 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 cbd1f3e9a3..c38904f93e 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 @@ -9,6 +9,7 @@ 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.ApiTransferRequest; import io.metersphere.api.dto.request.MsScenario; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.response.ApiScenarioBatchOperationResponse; @@ -96,6 +97,7 @@ 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 @@ -177,8 +179,8 @@ public class ApiScenarioService { 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"; @@ -873,7 +875,7 @@ public class ApiScenarioService { resourceUpdateRequest.setApiResourceType(ApiResourceType.API_SCENARIO); resourceUpdateRequest.setOperator(operator); resourceUpdateRequest.setLogModule(OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO); - resourceUpdateRequest.setFileAssociationSourceType(FileAssociationSourceUtil.SOURCE_TYPE_API_DEBUG); + resourceUpdateRequest.setFileAssociationSourceType(FileAssociationSourceUtil.SOURCE_TYPE_API_SCENARIO); return resourceUpdateRequest; } @@ -921,7 +923,7 @@ public class ApiScenarioService { //删除csv deleteCsvByScenarioId(scenario.getId()); //删除文件 - String scenarioDir = DefaultRepositoryDir.getApiDebugDir(scenario.getProjectId(), scenario.getId()); + String scenarioDir = DefaultRepositoryDir.getApiScenarioDir(scenario.getProjectId(), scenario.getId()); try { apiFileResourceService.deleteByResourceId(scenarioDir, scenario.getId(), scenario.getProjectId(), operator, OperationLogModule.API_TEST_DEBUG_MANAGEMENT_DEBUG); } catch (Exception ignore) { @@ -967,7 +969,7 @@ public class ApiScenarioService { scenarioList.forEach(scenario -> { //删除文件 - String scenarioDir = DefaultRepositoryDir.getApiDebugDir(scenario.getProjectId(), scenario.getId()); + String scenarioDir = DefaultRepositoryDir.getApiScenarioDir(scenario.getProjectId(), scenario.getId()); try { apiFileResourceService.deleteByResourceId(scenarioDir, scenario.getId(), scenario.getProjectId(), operator, OperationLogModule.API_TEST_DEBUG_MANAGEMENT_DEBUG); //删除定时任务 @@ -2110,7 +2112,7 @@ public class ApiScenarioService { } catch (Exception e) { LogUtils.error(e); } - if (msTestElement != null && msTestElement instanceof MsHTTPElement msHTTPElement) { + if (msTestElement instanceof MsHTTPElement msHTTPElement) { List updateFiles = apiCommonService.getApiFilesByFileId(originFileAssociation.getFileId(), msHTTPElement); // 替换文件的Id和name apiCommonService.replaceApiFileInfo(updateFiles, newFileMetadata); @@ -2122,4 +2124,8 @@ public class ApiScenarioService { } } } + + public String transfer(ApiTransferRequest request, String userId) { + return apiFileResourceService.transfer(request, userId, ApiResourceType.API_SCENARIO.name()); + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java index 3947bc3510..3d30bfeedc 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java @@ -5,12 +5,14 @@ import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.domain.ApiDebug; import io.metersphere.api.domain.ApiDebugBlob; import io.metersphere.api.domain.ApiFileResource; +import io.metersphere.api.domain.ApiFileResourceExample; import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.assertion.MsAssertionConfig; import io.metersphere.api.dto.debug.*; import io.metersphere.api.dto.definition.ResponseBinaryBody; import io.metersphere.api.dto.definition.ResponseBody; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.MsCommonElement; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.RestParam; @@ -20,6 +22,7 @@ import io.metersphere.api.dto.request.http.auth.HTTPAuthConfig; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.mapper.ApiDebugBlobMapper; import io.metersphere.api.mapper.ApiDebugMapper; +import io.metersphere.api.mapper.ApiFileResourceMapper; import io.metersphere.api.parser.ImportParserFactory; import io.metersphere.api.parser.TestElementParserFactory; import io.metersphere.api.service.ApiCommonService; @@ -85,6 +88,8 @@ public class ApiDebugControllerTests extends BaseTest { protected static final String DEFAULT_LIST = "list/{0}"; protected static final String UPLOAD_TEMP_FILE = "upload/temp/file"; protected static final String DEBUG = "debug"; + public static final String TRANSFER_OPTION = "transfer/options"; + public static final String TRANSFER = "transfer"; @Resource private ApiDebugMapper apiDebugMapper; @@ -104,6 +109,8 @@ public class ApiDebugControllerTests extends BaseTest { private TestResourcePoolMapper testResourcePoolMapper; @Resource private CustomFunctionService customFunctionService; + @Resource + private ApiFileResourceMapper apiFileResourceMapper; private static ApiDebug addApiDebug; private static ApiDebug anotherAddApiDebug; private static String fileMetadataId; @@ -671,6 +678,30 @@ public class ApiDebugControllerTests extends BaseTest { return body; } + @Test + @Order(8) + void testTransfer() throws Exception { + this.requestGetWithOk(TRANSFER_OPTION + "/" + DEFAULT_PROJECT_ID); + ApiTransferRequest request = new ApiTransferRequest(); + request.setSourceId(addApiDebug.getId()); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setModuleId("root"); + request.setLocal(true); + uploadFileId = doUploadTempFile(getMockMultipartFile()); + request.setFileId(uploadFileId); + this.requestPost(TRANSFER, request).andExpect(status().isOk()); + //文件不存在 + request.setFileId("111"); + this.requestPost(TRANSFER, request).andExpect(status().is5xxServerError()); + //文件已经上传 + ApiFileResourceExample apiFileResourceExample = new ApiFileResourceExample(); + apiFileResourceExample.createCriteria().andResourceIdEqualTo(addApiDebug.getId()); + List apiFileResources = apiFileResourceMapper.selectByExample(apiFileResourceExample); + Assertions.assertFalse(apiFileResources.isEmpty()); + request.setFileId(apiFileResources.get(0).getFileId()); + this.requestPost(TRANSFER, request).andExpect(status().isOk()); + } + @Test @Order(17) public void delete() throws Exception { diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index 163db7d1ba..706a14ed4f 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -8,6 +8,7 @@ import io.metersphere.api.domain.*; import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.definition.*; import io.metersphere.api.dto.request.ApiEditPosRequest; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.mapper.*; @@ -141,6 +142,8 @@ public class ApiDefinitionControllerTests extends BaseTest { private BaseFileManagementTestService baseFileManagementTestService; @Resource private ApiCommonService apiCommonService; + @Resource + private ApiFileResourceMapper apiFileResourceMapper; private static String fileMetadataId; private static String uploadFileId; @@ -205,7 +208,28 @@ public class ApiDefinitionControllerTests extends BaseTest { ApiDefinition resultData = getResultData(mvcResult, ApiDefinition.class); apiDefinition = assertAddApiDefinition(request, msHttpElement, resultData.getId()); assertUploadFile(apiDefinition.getId(), List.of(uploadFileId)); - assertLinkFile(apiDefinition.getId(), List.of(fileMetadataId)); + assertLinkFile(apiDefinition.getId()); + + this.requestGetWithOk("/api/definition/transfer/options/" + "/" + DEFAULT_PROJECT_ID); + ApiTransferRequest apiTransferRequest = new ApiTransferRequest(); + apiTransferRequest.setSourceId(apiDefinition.getId()); + apiTransferRequest.setProjectId(DEFAULT_PROJECT_ID); + apiTransferRequest.setModuleId("root"); + apiTransferRequest.setLocal(true); + String uploadFileId = doUploadTempFile(getMockMultipartFile("file_upload.JPG")); + apiTransferRequest.setFileId(uploadFileId); + this.requestPost("/api/definition/transfer", apiTransferRequest).andExpect(status().isOk()); + //文件不存在 + apiTransferRequest.setFileId("111"); + this.requestPost("/api/definition/transfer", apiTransferRequest).andExpect(status().is5xxServerError()); + //文件已经上传 + ApiFileResourceExample apiFileResourceExample = new ApiFileResourceExample(); + apiFileResourceExample.createCriteria().andResourceIdEqualTo(apiDefinition.getId()); + List apiFileResources = apiFileResourceMapper.selectByExample(apiFileResourceExample); + Assertions.assertFalse(apiFileResources.isEmpty()); + apiTransferRequest.setFileId(apiFileResources.get(0).getFileId()); + this.requestPost("/api/definition/transfer", apiTransferRequest).andExpect(status().isOk()); + // 再插入一条数据,便于修改时重名校验 request.setMethod("GET"); request.setPath("/api/admin/posts"); @@ -392,7 +416,7 @@ public class ApiDefinitionControllerTests extends BaseTest { // 校验请求成功数据 apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId()); assertUploadFile(apiDefinition.getId(), List.of()); - assertLinkFile(apiDefinition.getId(), List.of()); + assertLinkFile(apiDefinition.getId()); // 带文件的更新 String fileId = doUploadTempFile(getMockMultipartFile("file_upload.JPG")); @@ -404,7 +428,7 @@ public class ApiDefinitionControllerTests extends BaseTest { // 校验请求成功数据 apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId()); assertUploadFile(apiDefinition.getId(), List.of(fileId)); - assertLinkFile(apiDefinition.getId(), List.of(fileMetadataId)); + assertLinkFile(apiDefinition.getId()); // 删除了上一次上传的文件,重新上传一个文件 request.setDeleteFileIds(List.of(fileId)); @@ -415,7 +439,7 @@ public class ApiDefinitionControllerTests extends BaseTest { this.requestPostWithOk(UPDATE, request); apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId()); assertUploadFile(apiDefinition.getId(), List.of(newFileId1)); - assertLinkFile(apiDefinition.getId(), List.of(fileMetadataId)); + assertLinkFile(apiDefinition.getId()); // 已有一个文件,再上传一个文件 String newFileId2 = doUploadTempFile(getMockMultipartFile("file_update_upload.JPG")); @@ -426,7 +450,7 @@ public class ApiDefinitionControllerTests extends BaseTest { this.requestPostWithOk(UPDATE, request); apiDefinition = assertAddApiDefinition(request, msHttpElement, request.getId()); assertUploadFile(apiDefinition.getId(), List.of(newFileId1, newFileId2)); - assertLinkFile(apiDefinition.getId(), List.of(fileMetadataId)); + assertLinkFile(apiDefinition.getId()); // @@重名校验异常 request.setModuleId("default"); @@ -549,6 +573,7 @@ public class ApiDefinitionControllerTests extends BaseTest { if (fileIds != null) { ApiFileResourceService apiFileResourceService = CommonBeanFactory.getBean(ApiFileResourceService.class); // 验证文件的关联关系,以及是否存入对象存储 + assert apiFileResourceService != null; List apiFileResources = apiFileResourceService.getByResourceId(id); Assertions.assertEquals(apiFileResources.size(), fileIds.size()); @@ -573,15 +598,15 @@ public class ApiDefinitionControllerTests extends BaseTest { * 校验上传的文件 * * @param id - * @param fileIds 全部的文件ID */ - private static void assertLinkFile(String id, List fileIds) { + private static void assertLinkFile(String id) { FileAssociationService fileAssociationService = CommonBeanFactory.getBean(FileAssociationService.class); + assert fileAssociationService != null; List linkFileIds = fileAssociationService.getFiles(id) .stream() .map(FileInfo::getFileId) .toList(); - Assertions.assertEquals(fileIds, linkFileIds); + Assertions.assertFalse(linkFileIds.isEmpty()); } @Test 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 51ab918256..230a4ddc54 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 @@ -6,6 +6,7 @@ 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.*; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.controller.*; import io.metersphere.api.dto.request.controller.loop.*; import io.metersphere.api.dto.request.http.Header; @@ -70,7 +71,6 @@ 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; @@ -174,8 +174,6 @@ public class ApiScenarioControllerTests extends BaseTest { @Resource private ProjectVersionMapper projectVersionMapper; @Resource - private OperationHistoryService operationHistoryService; - @Resource private BaseFileManagementTestService baseFileManagementTestService; @Resource private ApiCommonService apiCommonService; @@ -340,7 +338,8 @@ public class ApiScenarioControllerTests extends BaseTest { request.setSteps(steps); request.setStepDetails(steptDetailMap); request.setScenarioConfig(getScenarioConfig()); - + String fileId = doUploadTempFile(getMockMultipartFile()); + request.setUploadFileIds(List.of(fileId)); MvcResult mvcResult = this.requestPostWithOkAndReturn(DEFAULT_ADD, request); ApiScenario resultData = getResultData(mvcResult, ApiScenario.class); this.addApiScenario = apiScenarioMapper.selectByPrimaryKey(resultData.getId()); @@ -348,6 +347,7 @@ public class ApiScenarioControllerTests extends BaseTest { assertUpdateSteps(steps, steptDetailMap); request.setName("anOther name"); + request.setUploadFileIds(List.of()); request.setGrouped(true); request.setEnvironmentId(envGroupId); ApiScenarioStepRequest stepRequest = new ApiScenarioStepRequest(); @@ -618,8 +618,8 @@ public class ApiScenarioControllerTests extends BaseTest { ApiScenarioCsvExample apiScenarioCsvExample = new ApiScenarioCsvExample(); apiScenarioCsvExample.createCriteria().andScenarioIdEqualTo(addApiScenario.getId()); - List apiScenarioCsvs = apiScenarioCsvMapper.selectByExample(apiScenarioCsvExample); - Map collect = apiScenarioCsvs.stream().collect(Collectors.toMap(ApiScenarioCsv::getFileId, t -> t)); + List apiScenarioCsv = apiScenarioCsvMapper.selectByExample(apiScenarioCsvExample); + Map collect = apiScenarioCsv.stream().collect(Collectors.toMap(ApiScenarioCsv::getFileId, t -> t)); // 验证修改步骤 steps.get(0).setName("test name update"); CsvVariable csvVariable = request.getScenarioConfig().getVariable().getCsvVariables().get(0); @@ -767,6 +767,31 @@ public class ApiScenarioControllerTests extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_EXECUTE, DEBUG, request); } + @Test + @Order(7) + public void testTransfer() throws Exception { + this.requestGetWithOk("transfer/options/" + "/" + DEFAULT_PROJECT_ID); + ApiTransferRequest apiTransferRequest = new ApiTransferRequest(); + apiTransferRequest.setSourceId(addApiScenario.getId()); + apiTransferRequest.setProjectId(DEFAULT_PROJECT_ID); + apiTransferRequest.setModuleId("root"); + apiTransferRequest.setLocal(true); + String uploadFileId = doUploadTempFile(getMockMultipartFile()); + apiTransferRequest.setFileId(uploadFileId); + this.requestPost("transfer", apiTransferRequest).andExpect(status().isOk()); + //文件不存在 + apiTransferRequest.setFileId("111"); + this.requestPost("transfer", apiTransferRequest).andExpect(status().is5xxServerError()); + //文件已经上传 + ApiFileResourceExample apiFileResourceExample = new ApiFileResourceExample(); + apiFileResourceExample.createCriteria().andResourceIdEqualTo(addApiScenario.getId()); + List apiFileResources = apiFileResourceMapper.selectByExample(apiFileResourceExample); + Assertions.assertFalse(apiFileResources.isEmpty()); + apiTransferRequest.setFileId(apiFileResources.get(0).getFileId()); + this.requestPost("transfer", apiTransferRequest).andExpect(status().isOk()); + + } + @Test @Order(7) public void testLoopController() throws Exception { @@ -1166,13 +1191,12 @@ public class ApiScenarioControllerTests extends BaseTest { } private static MockMultipartFile getMockMultipartFile() { - MockMultipartFile file = new MockMultipartFile( + return new MockMultipartFile( "file", IDGenerator.nextStr() + "_file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "Hello, World!".getBytes() ); - return file; } @Test 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 d4de5557da..ba54e5bff4 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 @@ -5,6 +5,7 @@ import io.metersphere.api.controller.param.ApiTestCaseAddRequestDefinition; import io.metersphere.api.domain.*; import io.metersphere.api.dto.ApiFile; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.request.ApiTransferRequest; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.mapper.*; import io.metersphere.api.service.ApiCommonService; @@ -119,11 +120,11 @@ public class ApiTestCaseControllerTests extends BaseTest { @Resource private OperationHistoryService operationHistoryService; @Resource - private ApiTestCaseRecordMapper apiTestCaseRecordMapper; - @Resource private BaseFileManagementTestService baseFileManagementTestService; @Resource private ApiCommonService apiCommonService; + @Resource + private ApiFileResourceMapper apiFileResourceMapper; public static T parseObjectFromMvcResult(MvcResult mvcResult, Class parseClass) { try { @@ -210,13 +211,12 @@ public class ApiTestCaseControllerTests extends BaseTest { } private static MockMultipartFile getMockMultipartFile() { - MockMultipartFile file = new MockMultipartFile( + return new MockMultipartFile( "file", IDGenerator.nextStr() + "_file_upload.JPG", MediaType.APPLICATION_OCTET_STREAM_VALUE, "Hello, World!".getBytes() ); - return file; } /** @@ -232,7 +232,7 @@ public class ApiTestCaseControllerTests extends BaseTest { List apiFileResources = apiFileResourceService.getByResourceId(id); Assertions.assertEquals(apiFileResources.size(), fileIds.size()); - String apiDebugDir = DefaultRepositoryDir.getApiDebugDir(DEFAULT_PROJECT_ID, id); + String apiDebugDir = DefaultRepositoryDir.getApiCaseDir(DEFAULT_PROJECT_ID, id); FileRequest fileRequest = new FileRequest(); if (fileIds.size() > 0) { for (ApiFileResource apiFileResource : apiFileResources) { @@ -358,7 +358,6 @@ public class ApiTestCaseControllerTests extends BaseTest { request.setApiDefinitionId("apiDefinitionId"); request.setName("test123"); this.requestPost(ADD, request).andExpect(ERROR_REQUEST_MATCHER); - // @@校验日志 checkLog(apiTestCase.getId(), OperationLogType.ADD); // @@异常参数校验 @@ -372,6 +371,7 @@ public class ApiTestCaseControllerTests extends BaseTest { /** * 测试关联的文件更新 + * * @throws Exception */ public void testHandleFileAssociationUpgrade() throws Exception { @@ -580,6 +580,31 @@ public class ApiTestCaseControllerTests extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE, UPDATE, request); } + @Test + @Order(9) + public void testTransfer() throws Exception { + this.requestGetWithOk("/api/case/transfer/options/" + "/" + DEFAULT_PROJECT_ID); + ApiTransferRequest apiTransferRequest = new ApiTransferRequest(); + apiTransferRequest.setSourceId(apiTestCase.getId()); + apiTransferRequest.setProjectId(DEFAULT_PROJECT_ID); + apiTransferRequest.setModuleId("root"); + apiTransferRequest.setLocal(true); + String uploadFileId = doUploadTempFile(getMockMultipartFile()); + apiTransferRequest.setFileId(uploadFileId); + this.requestPost("/api/case/transfer", apiTransferRequest).andExpect(status().isOk()); + //文件不存在 + apiTransferRequest.setFileId("111"); + this.requestPost("/api/case/transfer", apiTransferRequest).andExpect(status().is5xxServerError()); + //文件已经上传 + ApiFileResourceExample apiFileResourceExample = new ApiFileResourceExample(); + apiFileResourceExample.createCriteria().andResourceIdEqualTo(apiTestCase.getId()); + List apiFileResources = apiFileResourceMapper.selectByExample(apiFileResourceExample); + Assertions.assertFalse(apiFileResources.isEmpty()); + apiTransferRequest.setFileId(apiFileResources.get(0).getFileId()); + this.requestPost("/api/case/transfer", apiTransferRequest).andExpect(status().isOk()); + + } + @Test @Order(9) public void testPos() throws Exception {