From 45afe7b8fb0645102d5b0dc15996ea484d82ae20 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 7 Sep 2023 10:07:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86-=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE-=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/constants/PermissionConstants.java | 2 + .../sdk/constants/ProjectApplicationType.java | 32 +++++ .../resources/i18n/project_en_US.properties | 2 + .../resources/i18n/project_zh_CN.properties | 2 + .../resources/i18n/project_zh_TW.properties | 2 + .../ProjectApplicationController.java | 42 ++++++- .../ExtProjectTestResourcePoolMapper.java | 19 +++ .../ExtProjectTestResourcePoolMapper.xml | 28 +++++ .../service/ProjectApplicationService.java | 38 +++++- .../src/main/resources/permission.json | 8 ++ .../ProjectApplicationControllerTests.java | 112 +++++++++++++++++- 11 files changed, 275 insertions(+), 12 deletions(-) create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.java create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.xml diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java index 7bf3801b83..f6a8d1c7fa 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java @@ -147,6 +147,8 @@ public class PermissionConstants { public static final String PROJECT_APPLICATION_UI_UPDATE = "PROJECT_APPLICATION_UI:UPDATE"; public static final String PROJECT_APPLICATION_PERFORMANCE_TEST_READ = "PROJECT_APPLICATION_PERFORMANCE_TEST:READ"; public static final String PROJECT_APPLICATION_PERFORMANCE_TEST_UPDATE = "PROJECT_APPLICATION_PERFORMANCE_TEST:UPDATE"; + public static final String PROJECT_APPLICATION_API_READ = "PROJECT_APPLICATION_API:READ"; + public static final String PROJECT_APPLICATION_API_UPDATE = "PROJECT_APPLICATION_API:UPDATE"; /*------ end: PROJECT_APPLICATION ------*/ public static final String PROJECT_BASE_INFO_READ = "PROJECT_BASE_INFO:READ"; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java index 12d8624efc..170475b53f 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java @@ -47,6 +47,38 @@ public enum ProjectApplicationType { APPLICATION_PERFORMANCE_TEST_SCRIPT_REVIEWER, + //接口测试 + /** + * 接口定义 URL可重复 + */ + APPLICATION_API_URL_REPEATABLE, + /** + * 接口测试 报告保留范围 + */ + APPLICATION_CLEAN_API_REPORT, + /** + * 接口测试 报告有效期 + */ + APPLICATION_SHARE_API_REPORT, + /** + * 接口测试 执行资源池 + */ + APPLICATION_API_RESOURCE_POOL, + /** + * 接口测试 脚本审核人 + */ + APPLICATION_API_SCRIPT_REVIEWER, + /** + * 接口测试 自定义误报规则 + */ + APPLICATION_API_ERROR_REPORT_RULE, + /** + * 接口测试 接口变更同步case + */ + APPLICATION_API_SYNC_CASE, + + + //缺陷管理 /** * 同步缺陷 标识 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index d6197ad787..0b20333a5f 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -111,5 +111,7 @@ permission.project_application_ui.read=UI test read permission.project_application_ui.update=UI test update permission.project_application_performance_test.read=Performance test read permission.project_application_performance_test.update=Performance test update +permission.project_application_api.read=API test read +permission.project_application_api.update=API test update permission.project_base_info.name=Project base info permission.project_log.name=Operation log diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index cce9f49d39..07b87c29d4 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -111,5 +111,7 @@ permission.project_application_ui.read=UI测试-查询 permission.project_application_ui.update=UI测试-编辑 permission.project_application_performance_test.read=性能测试-查询 permission.project_application_performance_test.update=性能测试-编辑 +permission.project_application_api.read=接口测试-查询 +permission.project_application_api.update=接口测试-编辑 permission.project_base_info.name=基本信息 permission.project_log.name=日志 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index d56d0550e6..345b0648a7 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -111,5 +111,7 @@ permission.project_application_ui.read=UI測試-查詢 permission.project_application_ui.update=UI測試-編輯 permission.project_application_performance_test.read=性能測試-查詢 permission.project_application_performance_test.update=性能測試-編輯 +permission.project_application_api.read=接口測試-查詢 +permission.project_application_api.update=接口測試-編輯 permission.project_base_info.name=基本信息 permission.project_log.name=日誌 \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java index 27b4c46eb4..ebfdbb0d05 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java @@ -4,11 +4,11 @@ import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.request.ProjectApplicationRequest; import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.log.annotation.Log; import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.SessionUtils; import io.metersphere.system.domain.User; -import io.metersphere.system.service.UserService; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -27,8 +27,7 @@ import java.util.List; public class ProjectApplicationController { @Resource private ProjectApplicationService projectApplicationService; - @Resource - private UserService userService; + /** * ==========测试计划========== @@ -92,7 +91,42 @@ public class ProjectApplicationController { @GetMapping("/performance-test/user/{projectId}") @Operation(summary = "应用设置-性能测试-获取审核人") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_READ) - public List getCheckUser(@PathVariable String projectId) { + public List getReviewerUser(@PathVariable String projectId) { return projectApplicationService.getProjectUserList(StringUtils.defaultIfBlank(projectId, SessionUtils.getCurrentProjectId())); } + + + /** + * ==========接口测试========== + */ + + @PostMapping("/update/api") + @Operation(summary = "应用设置-接口测试-配置") + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_UPDATE) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateApiLog(#application)", msClass = ProjectApplicationService.class) + public ProjectApplication updateApi(@Validated({Updated.class}) @RequestBody ProjectApplication application) { + return projectApplicationService.update(application); + } + + @PostMapping("/api") + @Operation(summary = "应用设置-接口测试-获取配置") + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ) + public List getApi(@Validated @RequestBody ProjectApplicationRequest request) { + return projectApplicationService.get(request); + } + + @GetMapping("/api/user/{projectId}") + @Operation(summary = "应用设置-接口测试-获取审核人") + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ) + public List getApiReviewerUser(@PathVariable String projectId) { + return projectApplicationService.getProjectUserList(StringUtils.defaultIfBlank(projectId, SessionUtils.getCurrentProjectId())); + } + + + @GetMapping("/api/resource/pool/{organizationId}") + @Operation(summary = "应用设置-接口测试-获取资源池列表") + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ) + public List getResourcePoolList(@PathVariable String organizationId) { + return projectApplicationService.getResourcePoolList(StringUtils.defaultIfBlank(organizationId, SessionUtils.getCurrentOrganizationId())); + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.java new file mode 100644 index 0000000000..5a304374d2 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.java @@ -0,0 +1,19 @@ +package io.metersphere.project.mapper; + +import io.metersphere.sdk.dto.OptionDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author wx + */ +public interface ExtProjectTestResourcePoolMapper { + + /** + * 获取当前项目资源池列表 + * @param orgId + * @return + */ + List getResourcePoolList(@Param("orgId") String orgId); +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.xml new file mode 100644 index 0000000000..9249c5cf55 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectTestResourcePoolMapper.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java index ec43242d7d..fd22a3b134 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java @@ -3,6 +3,7 @@ package io.metersphere.project.service; import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.job.CleanUpReportJob; +import io.metersphere.project.mapper.ExtProjectTestResourcePoolMapper; import io.metersphere.project.mapper.ExtProjectUserRoleMapper; import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.request.ProjectApplicationRequest; @@ -10,6 +11,7 @@ import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ScheduleType; import io.metersphere.sdk.dto.LogDTO; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.log.constants.OperationLogModule; import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.sechedule.BaseScheduleService; @@ -17,7 +19,6 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.SessionUtils; import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.User; -import io.metersphere.system.mapper.ExtUserMapper; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; @@ -41,9 +42,12 @@ public class ProjectApplicationService { @Resource private ExtProjectUserRoleMapper extProjectUserRoleMapper; + @Resource + private ExtProjectTestResourcePoolMapper extProjectTestResourcePoolMapper; /** * 更新配置信息 + * * @param application * @return */ @@ -74,8 +78,9 @@ public class ProjectApplicationService { //TODO 自定义id配置 &其他配置 if (StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_TEST_PLAN_REPORT.name()) || StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_UI_REPORT.name()) - || StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_PERFORMANCE_TEST_REPORT.name())) { - //清除 测试计划/UI测试/性能测试 报告 定时任务 + || StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_PERFORMANCE_TEST_REPORT.name()) + || StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_API_REPORT.name())) { + //清除 测试计划/UI测试/性能测试/接口测试 报告 定时任务 this.doHandleSchedule(application); } } @@ -132,11 +137,28 @@ public class ProjectApplicationService { } + /** + * 获取 项目成员(脚本审核人) + * + * @param projectId + * @return + */ public List getProjectUserList(String projectId) { return extProjectUserRoleMapper.getProjectUserList(projectId); } + /** + * 获取当前项目 可用资源池 + * + * @param organizationId + * @return + */ + public List getResourcePoolList(String organizationId) { + return extProjectTestResourcePoolMapper.getResourcePoolList(organizationId); + } + + /** * 测试计划 日志 * @@ -168,6 +190,16 @@ public class ProjectApplicationService { return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "性能测试配置"); } + /** + * 接口测试 日志 + * + * @param application + * @return + */ + public LogDTO updateApiLog(ProjectApplication application) { + return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置"); + } + private LogDTO delLog(ProjectApplication application, String module, String content) { ProjectApplicationExample example = new ProjectApplicationExample(); example.createCriteria().andTypeEqualTo(application.getType()).andProjectIdEqualTo(application.getProjectId()); diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json index 10e85232bc..14cf015f5d 100644 --- a/backend/services/project-management/src/main/resources/permission.json +++ b/backend/services/project-management/src/main/resources/permission.json @@ -151,6 +151,14 @@ { "id": "PROJECT_APPLICATION_PERFORMANCE_TEST:UPDATE", "name": "permission.project_application_performance_test.update" + }, + { + "id": "PROJECT_APPLICATION_API:READ", + "name": "permission.project_application_api.read" + }, + { + "id": "PROJECT_APPLICATION_API:UPDATE", + "name": "permission.project_application_api.update" } ] }, diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java index cf4a77e4f8..67371818e2 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java @@ -123,7 +123,6 @@ public class ProjectApplicationControllerTests extends BaseTest { // @@异常参数校验 updatedGroupParamValidateTest(ProjectApplicationRequestDefinition.class, GET_UI_URL); } - /** * ==========UI测试 end========== */ @@ -139,7 +138,7 @@ public class ProjectApplicationControllerTests extends BaseTest { //获取脚本审核人 public static final String GET_USER_URL = "/project/application/performance-test/user"; - //应用配置 - UI测试 - 清理报告配置 + //应用配置 - 性能测试 - 清理报告配置 @Test @Order(7) public void testPerformanceClean() throws Exception { @@ -154,7 +153,7 @@ public class ProjectApplicationControllerTests extends BaseTest { } - //应用管理 - UI测试 - 分享报告配置 + //应用管理 - 性能测试 - 分享报告配置 @Test @Order(8) public void testPerformanceShare() throws Exception { @@ -166,7 +165,7 @@ public class ProjectApplicationControllerTests extends BaseTest { this.requestPost(PERFORMANCE_UPDATE_URL, request); } - //应用管理 - UI测试 - 脚本审核 + //应用管理 - 性能测试 - 脚本审核 @Test @Order(9) public void testPerformanceReviewer() throws Exception { @@ -175,7 +174,7 @@ public class ProjectApplicationControllerTests extends BaseTest { this.requestPost(PERFORMANCE_UPDATE_URL, request); } - //应用管理 - UI测试 - 获取配置 + //应用管理 - 性能测试 - 获取配置 @Test @Order(10) public void testGetPerformance() throws Exception { @@ -187,11 +186,114 @@ public class ProjectApplicationControllerTests extends BaseTest { updatedGroupParamValidateTest(ProjectApplicationRequestDefinition.class, GET_PERFORMANCE_URL); } + //应用管理 - 性能测试 - 获取项目成员 @Test @Order(11) public void testGetUser() throws Exception { this.requestGetWithOkAndReturn(GET_USER_URL + "/default-project-2"); } + /** + * ==========性能测试 end========== + */ + + + /** + * ==========接口测试 start========== + */ + // 接口测试 + public static final String API_UPDATE_URL = "/project/application/update/api"; + //获取配置 + public static final String GET_API_URL = "/project/application/api"; + //获取脚本审核人 + public static final String GET_API_USER_URL = "/project/application/api/user"; + //获取资源池 + public static final String GET_API_RESOURCE_POOL_URL = "/project/application/api/resource/pool"; + + //应用配置 - 接口测试 - URL可重复 + @Test + @Order(12) + public void testUrlRepeatable() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_URL_REPEATABLE.name(), "true"); + this.requestPost(API_UPDATE_URL, request); + + } + + //应用配置 - 接口测试 - 清理报告配置 + @Test + @Order(13) + public void testApiClean() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_CLEAN_API_REPORT.name(), TIME_TYPE_VALUE); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 分享报告配置 + @Test + @Order(14) + public void testApiShare() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_SHARE_API_REPORT.name(), TIME_TYPE_VALUE); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 执行资源池 + @Test + @Order(15) + public void testApiResourcePool() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_RESOURCE_POOL.name(), "local"); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 脚本审核 + @Test + @Order(16) + public void testApiReviewer() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_SCRIPT_REVIEWER.name(), "admin"); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 自定义误报规则 + @Test + @Order(17) + public void testApiErrorReportRule() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_ERROR_REPORT_RULE.name(), "true"); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 接口变更同步case + @Test + @Order(18) + public void testApiSyncCase() throws Exception { + ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_SYNC_CASE.name(), "true"); + this.requestPost(API_UPDATE_URL, request); + } + + //应用管理 - 接口测试 - 获取配置 + @Test + @Order(19) + public void testGetApi() throws Exception { + List types = Arrays.asList(ProjectApplicationType.APPLICATION_API_URL_REPEATABLE.name(), ProjectApplicationType.APPLICATION_CLEAN_API_REPORT.name(), ProjectApplicationType.APPLICATION_SHARE_API_REPORT.name(), + ProjectApplicationType.APPLICATION_API_RESOURCE_POOL.name(), ProjectApplicationType.APPLICATION_API_SCRIPT_REVIEWER.name(), ProjectApplicationType.APPLICATION_API_ERROR_REPORT_RULE.name(), + ProjectApplicationType.APPLICATION_API_SYNC_CASE.name()); + ProjectApplicationRequest request = this.getRequest(types); + this.requestPostWithOkAndReturn(GET_API_URL, request); + } + + //应用管理 - 接口测试 - 获取项目成员 + @Test + @Order(20) + public void testGetApiUser() throws Exception { + this.requestGetWithOkAndReturn(GET_API_USER_URL + "/default-project-2"); + } + + + //应用管理 - 接口测试 - 获取资源池 + @Test + @Order(21) + public void testGetApiResourcePool() throws Exception { + this.requestGetWithOkAndReturn(GET_API_RESOURCE_POOL_URL + "/default_organization"); + } + /** + * ==========接口测试 end========== + */ private ProjectApplicationRequest getRequest(List types) {