refactor(项目管理): 项目与权限-菜单管理-功能优化

This commit is contained in:
WangXu10 2023-09-18 17:02:02 +08:00 committed by 刘瑞斌
parent e8a4b1d3f5
commit 71c4ba10f8
12 changed files with 577 additions and 263 deletions

View File

@ -105,7 +105,20 @@ INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_FAKE_ERROR:READ+DELETE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_TEST_PLAN:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_TEST_PLAN:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_UI:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_UI:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_PERFORMANCE_TEST:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_PERFORMANCE_TEST:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_API:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_API:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:UPDATE');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_LOG:READ');
INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_LOG:UPDATE');
-- 项目成员权限

View File

@ -153,6 +153,10 @@ public class PermissionConstants {
public static final String PROJECT_APPLICATION_API_UPDATE = "PROJECT_APPLICATION_API:UPDATE";
public static final String PROJECT_APPLICATION_CASE_READ = "PROJECT_APPLICATION_CASE:READ";
public static final String PROJECT_APPLICATION_CASE_UPDATE = "PROJECT_APPLICATION_CASE:UPDATE";
public static final String PROJECT_APPLICATION_ISSUE_READ = "PROJECT_APPLICATION_ISSUE:READ";
public static final String PROJECT_APPLICATION_ISSUE_UPDATE = "PROJECT_APPLICATION_ISSUE:UPDATE";
public static final String PROJECT_APPLICATION_WORKSTATION_READ = "PROJECT_APPLICATION_WORKSTATION:READ";
public static final String PROJECT_APPLICATION_WORKSTATION_UPDATE = "PROJECT_APPLICATION_WORKSTATION:UPDATE";
/*------ end: PROJECT_APPLICATION ------*/
public static final String PROJECT_BASE_INFO_READ = "PROJECT_BASE_INFO:READ";

View File

@ -3,105 +3,64 @@ package io.metersphere.sdk.constants;
/**
* 应用设置 -相关配置
*/
public enum ProjectApplicationType {
/**
* 工作台 我的待办
*/
APPLICATION_WORKSTATION,
public class ProjectApplicationType {
//工作台
public enum WORKSTATION {
WORKSTATION
}
//测试计划
/**
* 测试计划报告保留范围 value
*/
APPLICATION_CLEAN_TEST_PLAN_REPORT,
/**
* 测试报告有效期 value
*/
APPLICATION_SHARE_TEST_PLAN_REPORT,
public enum TEST_PLAN {
TEST_PLAN_CLEAN_REPORT,
TEST_PLAN_SHARE_REPORT
}
//UI测试
/**
* UI报告保留范围 value
*/
APPLICATION_CLEAN_UI_REPORT,
/**
* UI报告有效期 value
*/
APPLICATION_SHARE_UI_REPORT,
public enum UI{
UI_CLEAN_REPORT,
UI_SHARE_REPORT,
UI_RESOURCE_POOL,
}
//性能测试
/**
* 性能测试报告保留范围 value
*/
APPLICATION_CLEAN_PERFORMANCE_TEST_REPORT,
/**
* 性能测试报告有效期 value
*/
APPLICATION_SHARE_PERFORMANCE_TEST_REPORT,
/**
* 性能测试脚本审核人
*/
APPLICATION_PERFORMANCE_TEST_SCRIPT_REVIEWER,
public enum PERFORMANCE_TEST{
PERFORMANCE_TEST_CLEAN_REPORT,
PERFORMANCE_TEST_SHARE_REPORT,
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,
public enum API{
API_URL_REPEATABLE,
API_CLEAN_REPORT,
API_SHARE_REPORT,
API_RESOURCE_POOL,
API_SCRIPT_REVIEWER,
API_ERROR_REPORT_RULE,
API_SYNC_CASE
}
//用例管理
/**
* 公共用例库
*/
APPLICATION_CASE_PUBLIC,
/**
* 测试用例关联需求
*/
APPLICATION_CASE_ASSOCIATION_REQUIREMENTS,
/**
* 重新提审
*/
APPLICATION_RE_REVIEW,
public enum CASE{
CASE_PUBLIC,
CASE_ASSOCIATION_REQUIREMENTS,
CASE_RE_REVIEW,
}
//缺陷管理
/**
* 同步缺陷 标识
*/
APPLICATION_ISSUE,
public enum ISSUE{
ISSUE_SYNC
}
/**
* 缺陷模板
*/
APPLICATION_ISSUE_TEMPLATE,

View File

@ -127,6 +127,12 @@ 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_application_case.read=Case read
permission.project_application_case.update=Case update
permission.project_application_issue.read=Issue read
permission.project_application_issue.update=Issue update
permission.project_application_workstation.reda=Workstation read
permission.project_application_workstation.update=Workstation update
permission.project_base_info.name=Project base info
permission.project_log.name=Operation log
# project version

View File

@ -127,6 +127,12 @@ permission.project_application_performance_test.read=性能测试-查询
permission.project_application_performance_test.update=性能测试-编辑
permission.project_application_api.read=接口测试-查询
permission.project_application_api.update=接口测试-编辑
permission.project_application_case.read=用例管理-查询
permission.project_application_case.update=用例管理-编辑
permission.project_application_issue.read=缺陷管理-查询
permission.project_application_issue.update=缺陷管理-编辑
permission.project_application_workstation.reda=工作台-查询
permission.project_application_workstation.update=工作台-编辑
permission.project_base_info.name=基本信息
permission.project_log.name=日志
# project version

View File

@ -127,6 +127,12 @@ permission.project_application_performance_test.read=性能測試-查詢
permission.project_application_performance_test.update=性能測試-編輯
permission.project_application_api.read=接口測試-查詢
permission.project_application_api.update=接口測試-編輯
permission.project_application_case.read=用例管理-查詢
permission.project_application_case.update=用例管理-編輯
permission.project_application_issue.read=缺陷管理-查詢
permission.project_application_issue.update=缺陷管理-編輯
permission.project_application_workstation.reda=工作台-查詢
permission.project_application_workstation.update=工作台-編輯
permission.project_base_info.name=基本信息
permission.project_log.name=日誌
# project version

View File

@ -4,11 +4,13 @@ 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.constants.ProjectApplicationType;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.sdk.dto.SessionUser;
import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.domain.User;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -18,10 +20,13 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Tag(name = "项目管理-应用设置")
@Tag(name = "项目管理-项目与权限-菜单管理")
@RestController
@RequestMapping("/project/application")
public class ProjectApplicationController {
@ -34,18 +39,19 @@ public class ProjectApplicationController {
*/
@PostMapping("/update/test-plan")
@Operation(summary = "应用设置-测试计划-配置")
@Operation(summary = "测试计划-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_TEST_PLAN_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateTestPlanLog(#application)", msClass = ProjectApplicationService.class)
public ProjectApplication updateTestPlan(@Validated({Updated.class}) @RequestBody ProjectApplication application) {
return projectApplicationService.update(application);
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateTestPlanLog(#applications)", msClass = ProjectApplicationService.class)
public void updateTestPlan(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/test-plan")
@Operation(summary = "应用设置-测试计划-获取配置")
@Operation(summary = "测试计划-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_TEST_PLAN_READ)
public List<ProjectApplication> getTestPlan(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
List<String> types = Arrays.asList(ProjectApplicationType.TEST_PLAN.values()).stream().map(ProjectApplicationType.TEST_PLAN::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@ -54,22 +60,23 @@ public class ProjectApplicationController {
*/
@PostMapping("/update/ui")
@Operation(summary = "应用设置-UI测试-配置")
@Operation(summary = "UI测试-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_UI_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateUiLog(#application)", msClass = ProjectApplicationService.class)
public ProjectApplication updateUI(@Validated({Updated.class}) @RequestBody ProjectApplication application) {
return projectApplicationService.update(application);
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateUiLog(#applications)", msClass = ProjectApplicationService.class)
public void updateUI(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/ui")
@Operation(summary = "应用设置-UI测试-获取配置")
@Operation(summary = "UI测试-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_UI_READ)
public List<ProjectApplication> getUI(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
List<String> types = Arrays.asList(ProjectApplicationType.UI.values()).stream().map(ProjectApplicationType.UI::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@GetMapping("/ui/resource/pool/{organizationId}")
@Operation(summary = "应用设置-UI测试-获取资源池列表")
@Operation(summary = "UI测试-获取资源池列表")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_UI_READ)
public List<OptionDTO> getUiResourcePoolList(@PathVariable String organizationId) {
return projectApplicationService.getResourcePoolList(StringUtils.defaultIfBlank(organizationId, SessionUtils.getCurrentOrganizationId()));
@ -81,22 +88,23 @@ public class ProjectApplicationController {
*/
@PostMapping("/update/performance-test")
@Operation(summary = "应用设置-性能测试-配置")
@Operation(summary = "性能测试-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePerformanceLog(#application)", msClass = ProjectApplicationService.class)
public ProjectApplication updatePerformanceTest(@Validated({Updated.class}) @RequestBody ProjectApplication application) {
return projectApplicationService.update(application);
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePerformanceLog(#applications)", msClass = ProjectApplicationService.class)
public void updatePerformanceTest(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/performance-test")
@Operation(summary = "应用设置-性能测试-获取配置")
@Operation(summary = "性能测试-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_READ)
public List<ProjectApplication> getPerformanceTest(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
List<String> types = Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.values()).stream().map(ProjectApplicationType.PERFORMANCE_TEST::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@GetMapping("/performance-test/user/{projectId}")
@Operation(summary = "应用设置-性能测试-获取审核人")
@Operation(summary = "性能测试-获取审核人")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_READ)
public List<User> getReviewerUser(@PathVariable String projectId) {
return projectApplicationService.getProjectUserList(StringUtils.defaultIfBlank(projectId, SessionUtils.getCurrentProjectId()));
@ -108,22 +116,23 @@ public class ProjectApplicationController {
*/
@PostMapping("/update/api")
@Operation(summary = "应用设置-接口测试-配置")
@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);
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateApiLog(#applications)", msClass = ProjectApplicationService.class)
public void updateApi(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/api")
@Operation(summary = "应用设置-接口测试-获取配置")
@Operation(summary = "接口测试-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ)
public List<ProjectApplication> getApi(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
List<String> types = Arrays.asList(ProjectApplicationType.API.values()).stream().map(ProjectApplicationType.API::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@GetMapping("/api/user/{projectId}")
@Operation(summary = "应用设置-接口测试-获取审核人")
@Operation(summary = "接口测试-获取审核人")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ)
public List<User> getApiReviewerUser(@PathVariable String projectId) {
return projectApplicationService.getProjectUserList(StringUtils.defaultIfBlank(projectId, SessionUtils.getCurrentProjectId()));
@ -131,48 +140,116 @@ public class ProjectApplicationController {
@GetMapping("/api/resource/pool/{organizationId}")
@Operation(summary = "应用设置-接口测试-获取资源池列表")
@Operation(summary = "接口测试-获取资源池列表")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_API_READ)
public List<OptionDTO> getResourcePoolList(@PathVariable String organizationId) {
return projectApplicationService.getResourcePoolList(StringUtils.defaultIfBlank(organizationId, SessionUtils.getCurrentOrganizationId()));
}
/**
* ==========用例管理==========
*/
@PostMapping("/update/case")
@Operation(summary = "应用设置-用例管理-配置")
@Operation(summary = "用例管理-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateCaseLog(#application)", msClass = ProjectApplicationService.class)
public ProjectApplication updateCase(@Validated({Updated.class}) @RequestBody ProjectApplication application) {
return projectApplicationService.update(application);
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateCaseLog(#applications)", msClass = ProjectApplicationService.class)
public void updateCase(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/case")
@Operation(summary = "应用设置-用例管理-获取配置")
@Operation(summary = "用例管理-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public List<ProjectApplication> getCase(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
List<String> types = Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@GetMapping("/case/platform/{organizationId}")
@Operation(summary = "应用设置-用例管理-获取平台下拉框列表")
@Operation(summary = "用例管理-获取平台下拉框列表")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public List<OptionDTO> getCasePlatformOptions(@PathVariable String organizationId) {
return projectApplicationService.getPlatformOptions(organizationId);
}
@GetMapping("case/platform/info/{pluginId}")
@Operation(summary = "应用设置-用例管理-选择平台获取平台信息")
@GetMapping("/case/platform/info/{pluginId}")
@Operation(summary = "用例管理-选择平台获取平台信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public Object getCasePlatformInfo(@PathVariable String pluginId) {
return projectApplicationService.getPluginScript(pluginId);
}
/**
* ==========工作台==========
*/
@PostMapping("/update/workstation")
@Operation(summary = "工作台-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_WORKSTATION_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class)
public void updateWorkstation(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/workstation")
@Operation(summary = "工作台-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_WORKSTATION_READ)
public List<ProjectApplication> getWorkstation(@Validated @RequestBody ProjectApplicationRequest request) {
List<String> types = Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
/**
* ==========缺陷管理==========
*/
@PostMapping("/update/issue")
@Operation(summary = "缺陷管理-配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_UPDATE)
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class)
public void updateIssue(@Validated({Updated.class}) @RequestBody List<ProjectApplication> applications) {
projectApplicationService.update(applications);
}
@PostMapping("/issue")
@Operation(summary = "缺陷管理-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ)
public List<ProjectApplication> getIssue(@Validated @RequestBody ProjectApplicationRequest request) {
List<String> types = Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList());
return projectApplicationService.get(request, types);
}
@GetMapping("/issue/platform/{organizationId}")
@Operation(summary = "缺陷管理-获取平台下拉框列表")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ)
public List<OptionDTO> getIssuePlatformOptions(@PathVariable String organizationId) {
return projectApplicationService.getPlatformOptions(organizationId);
}
@GetMapping("/issue/platform/info/{pluginId}")
@Operation(summary = "缺陷管理-选择平台获取平台信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ)
public Object getIssuePlatformInfo(@PathVariable String pluginId) {
return projectApplicationService.getPluginScript(pluginId);
}
/**
* ==========全部==========
*/
@GetMapping("/all/{projectId}")
@Operation(summary = "全部-获取配置")
public List<ProjectApplication> getAll(@PathVariable String projectId) {
SessionUser user = Objects.requireNonNull(SessionUtils.getUser());
return projectApplicationService.getAllConfigs(user, projectId);
}
}

View File

@ -7,7 +7,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.List;
/**
* @author wx
@ -22,7 +21,7 @@ public class ProjectApplicationRequest implements Serializable {
@NotBlank(message = "{project_application.project_id.not_blank}")
private String projectId;
@Schema(description = "配置类型列表", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(description = "配置类型列表", allowableValues = {"WORKSTATION", "TEST_PLAN", "UI", "PERFORMANCE_TEST", "API", "CASE", "ISSUE"}, requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "{project_application.type.not_blank}")
private List<String> types;
private String type;
}

View File

@ -8,22 +8,21 @@ import io.metersphere.project.mapper.ExtProjectTestResourcePoolMapper;
import io.metersphere.project.mapper.ExtProjectUserRoleMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.ScheduleType;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.dto.LogDTO;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.sechedule.BaseScheduleService;
import io.metersphere.system.service.PluginLoadService;
import io.metersphere.sdk.dto.SessionUser;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.utils.ServiceUtils;
import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.domain.*;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.ExtPluginMapper;
import io.metersphere.system.mapper.PluginMapper;
import io.metersphere.system.mapper.ServiceIntegrationMapper;
import io.metersphere.system.sechedule.BaseScheduleService;
import io.metersphere.system.service.PluginLoadService;
import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
@ -32,6 +31,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@ -65,15 +65,16 @@ public class ProjectApplicationService {
/**
* 更新配置信息
*
* @param application
* @param applications
* @return
*/
public ProjectApplication update(ProjectApplication application) {
public void update(List<ProjectApplication> applications) {
applications.forEach(application -> {
//定时任务配置检查是否存在定时任务配置存在则更新不存在则新增
this.doBeforeUpdate(application);
//配置信息入库
this.createOrUpdateConfig(application);
return application;
});
}
private void createOrUpdateConfig(ProjectApplication application) {
@ -93,10 +94,10 @@ public class ProjectApplicationService {
private void doBeforeUpdate(ProjectApplication application) {
String type = application.getType();
//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())
|| StringUtils.equals(type, ProjectApplicationType.APPLICATION_CLEAN_API_REPORT.name())) {
if (StringUtils.equals(type, ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name())
|| StringUtils.equals(type, ProjectApplicationType.UI.UI_CLEAN_REPORT.name())
|| StringUtils.equals(type, ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_CLEAN_REPORT.name())
|| StringUtils.equals(type, ProjectApplicationType.API.API_CLEAN_REPORT.name())) {
//清除 测试计划/UI测试/性能测试/接口测试 报告 定时任务
this.doHandleSchedule(application);
}
@ -143,9 +144,9 @@ public class ProjectApplicationService {
* @param request
* @return
*/
public List<ProjectApplication> get(ProjectApplicationRequest request) {
public List<ProjectApplication> get(ProjectApplicationRequest request, List<String> types) {
ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample();
projectApplicationExample.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeIn(request.getTypes());
projectApplicationExample.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeIn(types);
List<ProjectApplication> applicationList = projectApplicationMapper.selectByExample(projectApplicationExample);
if (CollectionUtils.isNotEmpty(applicationList)) {
return applicationList;
@ -186,7 +187,7 @@ public class ProjectApplicationService {
example.createCriteria().andOrganizationIdEqualTo(organizationId).andEnableEqualTo(true);
List<ServiceIntegration> serviceIntegrations = serviceIntegrationMapper.selectByExample(example);
List<OptionDTO> options = new ArrayList<>();
if(CollectionUtils.isNotEmpty(serviceIntegrations)){
if (CollectionUtils.isNotEmpty(serviceIntegrations)) {
List<String> pluginIds = serviceIntegrations.stream().map(ServiceIntegration::getPluginId).collect(Collectors.toList());
options = extPluginMapper.selectPluginOptions(pluginIds);
return options;
@ -206,58 +207,137 @@ public class ProjectApplicationService {
/**
* 测试计划 日志
* 获取所有配置信息
*
* @param application
* @param user
* @return
*/
public LogDTO updateTestPlanLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "测试计划配置");
public List<ProjectApplication> getAllConfigs(SessionUser user, String projectId) {
List<ProjectApplication> list = new ArrayList<>();
Boolean flag = checkAdmin(user);
ProjectApplicationExample example = new ProjectApplicationExample();
ProjectApplicationExample.Criteria criteria = example.createCriteria();
criteria.andProjectIdEqualTo(projectId);
if (flag) {
list = projectApplicationMapper.selectByExample(example);
}
List<String> types = checkPermission(user);
if (CollectionUtils.isNotEmpty(types)) {
criteria.andTypeIn(types);
list = projectApplicationMapper.selectByExample(example);
}
return list;
}
private List<String> checkPermission(SessionUser user) {
List<UserRolePermission> permissions = new ArrayList<>();
user.getUserRolePermissions().forEach(g -> {
permissions.addAll(g.getUserRolePermissions());
});
List<String> permissionIds = permissions.stream().map(UserRolePermission::getPermissionId).collect(Collectors.toList());
List<String> types = new ArrayList<>();
permissionIds.forEach(permissionId -> {
switch (permissionId) {
case PermissionConstants.PROJECT_APPLICATION_WORKSTATION_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_TEST_PLAN_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.TEST_PLAN.values()).stream().map(ProjectApplicationType.TEST_PLAN::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_ISSUE_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.ISSUE.values()).stream().map(ProjectApplicationType.ISSUE::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_CASE_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_API_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.API.values()).stream().map(ProjectApplicationType.API::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_UI_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.UI.values()).stream().map(ProjectApplicationType.UI::name).collect(Collectors.toList()));
case PermissionConstants.PROJECT_APPLICATION_PERFORMANCE_TEST_READ ->
types.addAll(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.values()).stream().map(ProjectApplicationType.PERFORMANCE_TEST::name).collect(Collectors.toList()));
default -> {
}
}
});
return types;
}
private Boolean checkAdmin(SessionUser user) {
long count = user.getUserRoles()
.stream()
.filter(g -> StringUtils.equalsIgnoreCase(g.getId(), InternalUserRole.ADMIN.getValue()))
.count();
if (count > 0) {
return true;
}
return false;
}
/**
* 测试计划 日志
*
* @param applications
* @return
*/
public List<LogDTO> updateTestPlanLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "测试计划配置");
}
/**
* UI 日志
*
* @param application
* @param applications
* @return
*/
public LogDTO updateUiLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "UI配置");
public List<LogDTO> updateUiLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "UI配置");
}
/**
* 性能测试 日志
*
* @param application
* @param applications
* @return
*/
public LogDTO updatePerformanceLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "性能测试配置");
public List<LogDTO> updatePerformanceLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "性能测试配置");
}
/**
* 接口测试 日志
*
* @param application
* @param applications
* @return
*/
public LogDTO updateApiLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置");
public List<LogDTO> updateApiLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置");
}
/**
* 用例管理 日志
*
* @param application
* @param applications
* @return
*/
public LogDTO updateCaseLog(ProjectApplication application) {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "用例管理配置");
public List<LogDTO> updateCaseLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "用例管理配置");
}
private LogDTO delLog(ProjectApplication application, String module, String content) {
/**
* 工作台 日志
*
* @param applications
* @return
*/
public List<LogDTO> updateWorkstationLog(List<ProjectApplication> applications) {
return delLog(applications, OperationLogModule.PROJECT_PROJECT_MANAGER, "工作台配置");
}
private List<LogDTO> delLog(List<ProjectApplication> applications, String module, String content) {
List<LogDTO> logs = new ArrayList<>();
applications.forEach(application -> {
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andTypeEqualTo(application.getType()).andProjectIdEqualTo(application.getProjectId());
List<ProjectApplication> list = projectApplicationMapper.selectByExample(example);
@ -270,7 +350,9 @@ public class ProjectApplicationService {
module,
content);
dto.setOriginalValue(JSON.toJSONBytes(list));
return dto;
logs.add(dto);
});
return logs;
}
}

View File

@ -177,6 +177,30 @@
{
"id": "PROJECT_APPLICATION_API:UPDATE",
"name": "permission.project_application_api.update"
},
{
"id": "PROJECT_APPLICATION_CASE:READ",
"name": "permission.project_application_case.read"
},
{
"id": "PROJECT_APPLICATION_CASE:UPDATE",
"name": "permission.project_application_case.update"
},
{
"id": "PROJECT_APPLICATION_ISSUE:READ",
"name": "permission.project_application_issue.read"
},
{
"id": "PROJECT_APPLICATION_ISSUE:UPDATE",
"name": "permission.project_application_issue.update"
},
{
"id": "PROJECT_APPLICATION_WORKSTATION:READ",
"name": "permission.project_application_workstation.reda"
},
{
"id": "PROJECT_APPLICATION_WORKSTATION:UPDATE",
"name": "permission.project_application_workstation.update"
}
]
},

View File

@ -1,10 +1,12 @@
package io.metersphere.project.controller;
import com.jayway.jsonpath.JsonPath;
import io.metersphere.project.controller.param.ProjectApplicationDefinition;
import io.metersphere.project.controller.param.ProjectApplicationRequestDefinition;
import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
@ -15,18 +17,24 @@ import jakarta.annotation.Resource;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@ -45,47 +53,45 @@ public class ProjectApplicationControllerTests extends BaseTest {
/**
* ==========测试计划配置 start==========
*/
// 测试计划
public static final String TEST_PLAN_UPDATE_URL = "/project/application/update/test-plan";
//获取配置
public static final String GET_TEST_PLAN_URL = "/project/application/test-plan";
//应用配置 - 测试计划 - 清理报告配置
//测试计划 - 清理报告配置
@Test
@Order(1)
@Sql(scripts = {"/dml/init_project_application_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void testTestPlanClean() throws Exception {
this.testGetTestPlan();
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_CLEAN_TEST_PLAN_REPORT.name(), TIME_TYPE_VALUE);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(TEST_PLAN_UPDATE_URL, request);
//更新
request.setTypeValue("4M");
request.get(0).setTypeValue("4M");
this.requestPost(TEST_PLAN_UPDATE_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationDefinition.class, TEST_PLAN_UPDATE_URL);
}
//应用管理 - 测试计划 - 分享报告配置
//测试计划 - 分享报告配置
@Test
@Order(2)
public void testTestPlanShare() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_SHARE_TEST_PLAN_REPORT.name(), TIME_TYPE_VALUE);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.TEST_PLAN.TEST_PLAN_SHARE_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(TEST_PLAN_UPDATE_URL, request);
//更新
request.setTypeValue("5M");
request.get(0).setTypeValue("5M");
this.requestPost(TEST_PLAN_UPDATE_URL, request);
}
//应用管理 - 测试计划 - 获取配置
//测试计划 - 获取配置
@Test
@Order(3)
public void testGetTestPlan() throws Exception {
//清理报告 + 分享报告
List<String> types = Arrays.asList(ProjectApplicationType.APPLICATION_CLEAN_TEST_PLAN_REPORT.name(), ProjectApplicationType.APPLICATION_SHARE_TEST_PLAN_REPORT.name());
ProjectApplicationRequest request = this.getRequest(types);
ProjectApplicationRequest request = this.getRequest("TEST_PLAN");
this.requestPostWithOkAndReturn(GET_TEST_PLAN_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationRequestDefinition.class, GET_TEST_PLAN_URL);
@ -98,53 +104,54 @@ public class ProjectApplicationControllerTests extends BaseTest {
/**
* ==========UI测试 start==========
*/
// UI
public static final String UI_UPDATE_URL = "/project/application/update/ui";
//获取配置
public static final String GET_UI_URL = "/project/application/ui";
//获取资源池
public static final String GET_UI_RESOURCE_POOL_URL = "/project/application/ui/resource/pool";
//应用配置 - UI测试 - 清理报告配置
//UI测试 - 清理报告配置
@Test
@Order(4)
public void testUiClean() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_CLEAN_UI_REPORT.name(), TIME_TYPE_VALUE);
this.requestPost(UI_UPDATE_URL, request);
//更新
request.setTypeValue("4M");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.UI.UI_CLEAN_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(UI_UPDATE_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationDefinition.class, UI_UPDATE_URL);
}
//应用管理 - UI测试 - 分享报告配置
//UI测试 - 分享报告配置
@Test
@Order(5)
public void testUiShare() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_SHARE_UI_REPORT.name(), TIME_TYPE_VALUE);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.UI.UI_SHARE_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(UI_UPDATE_URL, request);
//更新
request.setTypeValue("5M");
request.get(0).setTypeValue("5M");
this.requestPost(UI_UPDATE_URL, request);
}
//应用管理 - UI测试 - 获取配置
//UI测试 - 执行资源池
@Test
@Order(5)
public void testUiResourcePool() throws Exception {
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.UI.UI_RESOURCE_POOL.name()), "local");
this.requestPost(UI_UPDATE_URL, request);
}
//UI测试 - 获取配置
@Test
@Order(6)
public void testGetUi() throws Exception {
//清理报告 + 分享报告
List<String> types = Arrays.asList(ProjectApplicationType.APPLICATION_CLEAN_UI_REPORT.name(), ProjectApplicationType.APPLICATION_SHARE_UI_REPORT.name());
ProjectApplicationRequest request = this.getRequest(types);
ProjectApplicationRequest request = this.getRequest("UI");
this.requestPostWithOkAndReturn(GET_UI_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationRequestDefinition.class, GET_UI_URL);
}
//应用管理 - UI测试 - 获取资源池
//UI测试 - 获取资源池
@Test
@Order(6)
public void testGetUiResourcePool() throws Exception {
@ -158,62 +165,58 @@ public class ProjectApplicationControllerTests extends BaseTest {
/**
* ==========性能测试 start==========
*/
// 性能测试
public static final String PERFORMANCE_UPDATE_URL = "/project/application/update/performance-test";
//获取配置
public static final String GET_PERFORMANCE_URL = "/project/application/performance-test";
//获取脚本审核人
public static final String GET_USER_URL = "/project/application/performance-test/user";
//应用配置 - 性能测试 - 清理报告配置
//性能测试 - 清理报告配置
@Test
@Order(7)
public void testPerformanceClean() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_CLEAN_PERFORMANCE_TEST_REPORT.name(), TIME_TYPE_VALUE);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_CLEAN_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(PERFORMANCE_UPDATE_URL, request);
//更新
request.setTypeValue("4M");
request.get(0).setTypeValue("4M");
this.requestPost(PERFORMANCE_UPDATE_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationDefinition.class, PERFORMANCE_UPDATE_URL);
}
//应用管理 - 性能测试 - 分享报告配置
//性能测试 - 分享报告配置
@Test
@Order(8)
public void testPerformanceShare() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_SHARE_PERFORMANCE_TEST_REPORT.name(), TIME_TYPE_VALUE);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_SHARE_REPORT.name()), TIME_TYPE_VALUE);
this.requestPost(PERFORMANCE_UPDATE_URL, request);
//更新
request.setTypeValue("5M");
request.get(0).setTypeValue("5M");
this.requestPost(PERFORMANCE_UPDATE_URL, request);
}
//应用管理 - 性能测试 - 脚本审核
//性能测试 - 脚本审核
@Test
@Order(9)
public void testPerformanceReviewer() throws Exception {
//新增
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_PERFORMANCE_TEST_SCRIPT_REVIEWER.name(), "admin");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.PERFORMANCE_TEST.PERFORMANCE_TEST_SCRIPT_REVIEWER.name()), "admin");
this.requestPost(PERFORMANCE_UPDATE_URL, request);
}
//应用管理 - 性能测试 - 获取配置
//性能测试 - 获取配置
@Test
@Order(10)
public void testGetPerformance() throws Exception {
//清理报告 + 分享报告
List<String> types = Arrays.asList(ProjectApplicationType.APPLICATION_CLEAN_PERFORMANCE_TEST_REPORT.name(), ProjectApplicationType.APPLICATION_SHARE_PERFORMANCE_TEST_REPORT.name(), ProjectApplicationType.APPLICATION_PERFORMANCE_TEST_SCRIPT_REVIEWER.name());
ProjectApplicationRequest request = this.getRequest(types);
ProjectApplicationRequest request = this.getRequest("PERFORMANCE_TEST");
this.requestPostWithOkAndReturn(GET_PERFORMANCE_URL, request);
// @@异常参数校验
updatedGroupParamValidateTest(ProjectApplicationRequestDefinition.class, GET_PERFORMANCE_URL);
}
//应用管理 - 性能测试 - 获取项目成员
//性能测试 - 获取项目成员
@Test
@Order(11)
public void testGetUser() throws Exception {
@ -227,84 +230,77 @@ public class ProjectApplicationControllerTests extends BaseTest {
/**
* ==========接口测试 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可重复
//接口测试 - URL可重复
@Test
@Order(12)
public void testUrlRepeatable() throws Exception {
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_URL_REPEATABLE.name(), "true");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.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);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_CLEAN_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);
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_SHARE_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");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.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");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.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");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_ERROR_REPORT_RULE.name()), "true");
this.requestPost(API_UPDATE_URL, request);
}
//应用管理 - 接口测试 - 接口变更同步case
//接口测试 - 接口变更同步case
@Test
@Order(18)
public void testApiSyncCase() throws Exception {
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_API_SYNC_CASE.name(), "true");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.API.API_SYNC_CASE.name()), "true");
this.requestPost(API_UPDATE_URL, request);
}
//应用管理 - 接口测试 - 获取配置
//接口测试 - 获取配置
@Test
@Order(19)
public void testGetApi() throws Exception {
List<String> 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);
ProjectApplicationRequest request = this.getRequest("API");
this.requestPostWithOkAndReturn(GET_API_URL, request);
}
//应用管理 - 接口测试 - 获取项目成员
//接口测试 - 获取项目成员
@Test
@Order(20)
public void testGetApiUser() throws Exception {
@ -312,7 +308,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
}
//应用管理 - 接口测试 - 获取资源池
//接口测试 - 获取资源池
@Test
@Order(21)
public void testGetApiResourcePool() throws Exception {
@ -332,32 +328,31 @@ public class ProjectApplicationControllerTests extends BaseTest {
public static final String GET_PLATFORM_INFO_URL = "/project/application/case/platform/info";
//应用配置 - 用例管理 - 公共用例库
//用例管理 - 公共用例库
@Test
@Order(22)
public void testCasePublic() throws Exception {
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_CASE_PUBLIC.name(), "true");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.CASE.CASE_PUBLIC.name()), "true");
this.requestPost(CASE_UPDATE_URL, request);
}
//应用配置 - 用例管理 - 重新提审
//用例管理 - 重新提审
@Test
@Order(23)
public void testReview() throws Exception {
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_RE_REVIEW.name(), "true");
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.CASE.CASE_RE_REVIEW.name()), "true");
this.requestPost(CASE_UPDATE_URL, request);
}
//应用管理 - 用例管理 - 获取配置
//用例管理 - 获取配置
@Test
@Order(24)
public void testGetCase() throws Exception {
List<String> types = Arrays.asList(ProjectApplicationType.APPLICATION_CASE_PUBLIC.name(), ProjectApplicationType.APPLICATION_RE_REVIEW.name());
ProjectApplicationRequest request = this.getRequest(types);
ProjectApplicationRequest request = this.getRequest("CASE");
this.requestPostWithOkAndReturn(GET_CASE_URL, request);
}
//应用管理 - 用例管理 - 获取平台下拉列表
//用例管理 - 获取平台下拉列表
@Test
@Order(25)
public void testGetPlatform() throws Exception {
@ -371,7 +366,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
}
//应用管理 - 用例管理 - 获取平台信息
//用例管理 - 获取平台信息
@Test
@Order(26)
public void testGetPlatformInfo() throws Exception {
@ -385,9 +380,141 @@ public class ProjectApplicationControllerTests extends BaseTest {
}
/**
* ==========用例管理 start==========
* ==========用例管理 end==========
*/
/**
* ==========工作台 start==========
*/
public static final String WORKSTATION_UPDATE_URL = "/project/application/update/workstation";
public static final String GET_WORKSTATION_URL = "/project/application/workstation";
//工作台
@Test
@Order(27)
public void testWorkstation() throws Exception {
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.WORKSTATION.WORKSTATION.name()), "true");
this.requestPost(WORKSTATION_UPDATE_URL, request);
}
@Test
@Order(28)
public void testGetWorkstation() throws Exception {
ProjectApplicationRequest request = this.getRequest("WORKSTATION");
this.requestPostWithOkAndReturn(GET_WORKSTATION_URL, request);
}
/**
* ==========工作台 end==========
*/
/**
* ==========缺陷管理 start==========
*/
public static final String ISSUE_UPDATE_URL = "/project/application/update/issue";
public static final String GET_ISSUE_URL = "/project/application/issue";
public static final String GET_ISSUE_PLATFORM_URL = "/project/application/issue/platform";
public static final String GET_ISSUE_PLATFORM_INFO_URL = "/project/application/issue/platform/info";
//工作台
@Test
@Order(29)
public void testIssue() throws Exception {
List<ProjectApplication> request = creatRequest(Arrays.asList(ProjectApplicationType.ISSUE.ISSUE_SYNC.name()), "true");
this.requestPost(ISSUE_UPDATE_URL, request);
}
@Test
@Order(30)
public void testGetIssue() throws Exception {
ProjectApplicationRequest request = this.getRequest("ISSUE");
this.requestPostWithOkAndReturn(GET_ISSUE_URL, request);
}
//缺陷管理 - 获取平台下拉列表
@Test
@Order(31)
public void testGetIssuePlatform() throws Exception {
this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100002");
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100001");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
//缺陷管理 - 获取平台信息
@Test
@Order(32)
public void testGetIssuePlatformInfo() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_INFO_URL + "/" + plugin.getId());
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* ==========缺陷管理 end==========
*/
/**
* 全部
*
* @return
* @throws Exception
*/
public static final String GET_ALL_URL = "/project/application/all";
@Test
@Order(33)
public void testGetAll() throws Exception {
this.loginTest();
this.requestGetTest();
this.requestGetWithOkAndReturn(GET_ALL_URL + "/" + PROJECT_ID);
this.adminlogin();
this.requestGetWithOkAndReturn(GET_ALL_URL + "/" + PROJECT_ID);
}
private void adminlogin() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
.content("{\"username\":\"admin\",\"password\":\"metersphere\"}")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
}
private void requestGetTest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(GET_ALL_URL + "/" + PROJECT_ID)
.header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken))
.andExpect(status().isOk())
.andDo(print());
}
public void loginTest() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login")
.content("{\"username\":\"wx-test\",\"password\":\"metersphere\"}")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
sessionId = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.sessionId");
csrfToken = JsonPath.read(mvcResult.getResponse().getContentAsString(), "$.data.csrfToken");
}
public Plugin addPlugin() throws Exception {
PluginUpdateRequest request = new PluginUpdateRequest();
File jarFile = new File(
@ -404,19 +531,23 @@ public class ProjectApplicationControllerTests extends BaseTest {
}
private ProjectApplicationRequest getRequest(List<String> types) {
private ProjectApplicationRequest getRequest(String type) {
ProjectApplicationRequest request = new ProjectApplicationRequest();
request.setProjectId(PROJECT_ID);
request.setTypes(types);
request.setType(type);
return request;
}
private ProjectApplication creatRequest(String type, String typeValue) {
private List<ProjectApplication> creatRequest(List<String> type, String typeValue) {
List<ProjectApplication> list = new ArrayList<>();
type.forEach(t -> {
ProjectApplication projectApplication = new ProjectApplication();
projectApplication.setProjectId(PROJECT_ID);
projectApplication.setType(type);
projectApplication.setType(t);
projectApplication.setTypeValue(typeValue);
return projectApplication;
list.add(projectApplication);
});
return list;
}
}

View File

@ -2,6 +2,13 @@
INSERT INTO `service_integration`(`id`, `plugin_id`, `enable`, `configuration`, `organization_id`) VALUES ('1', '952262969139212', b'1', '1111', '100001');
-- 模拟用户
replace INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source,
last_project_id, create_user, update_user) VALUE
('wx-test', 'wx-test-1', 'wx-test-user@metersphere.io', MD5('metersphere'),
UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin');
replace INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUES (UUID_SHORT(), 'wx-test', 'project_admin', '100001100001', '100001', 1684747668375, 'admin');