feat(项目管理): 应用设置-用例管理配置部分功能接口

This commit is contained in:
WangXu10 2023-09-12 13:46:04 +08:00 committed by 刘瑞斌
parent 6db5bbe95d
commit 0a95c89998
9 changed files with 239 additions and 6 deletions

View File

@ -149,6 +149,8 @@ public class PermissionConstants {
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";
public static final String PROJECT_APPLICATION_CASE_READ = "PROJECT_APPLICATION_CASE:READ";
public static final String PROJECT_APPLICATION_CASE_UPDATE = "PROJECT_APPLICATION_CASE:UPDATE";
/*------ end: PROJECT_APPLICATION ------*/
public static final String PROJECT_BASE_INFO_READ = "PROJECT_BASE_INFO:READ";

View File

@ -78,6 +78,19 @@ public enum ProjectApplicationType {
APPLICATION_API_SYNC_CASE,
//用例管理
/**
* 公共用例库
*/
APPLICATION_CASE_PUBLIC,
/**
* 测试用例关联需求
*/
APPLICATION_CASE_ASSOCIATION_REQUIREMENTS,
/**
* 重新提审
*/
APPLICATION_RE_REVIEW,
//缺陷管理
/**

View File

@ -136,4 +136,43 @@ public class ProjectApplicationController {
public List<OptionDTO> getResourcePoolList(@PathVariable String organizationId) {
return projectApplicationService.getResourcePoolList(StringUtils.defaultIfBlank(organizationId, SessionUtils.getCurrentOrganizationId()));
}
/**
* ==========用例管理==========
*/
@PostMapping("/update/case")
@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);
}
@PostMapping("/case")
@Operation(summary = "应用设置-用例管理-获取配置")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public List<ProjectApplication> getCase(@Validated @RequestBody ProjectApplicationRequest request) {
return projectApplicationService.get(request);
}
@GetMapping("/case/platform/{organizationId}")
@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 = "应用设置-用例管理-选择平台获取平台信息")
@RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ)
public Object getCasePlatformInfo(@PathVariable String pluginId) {
return projectApplicationService.getPluginScript(pluginId);
}
}

View File

@ -1,5 +1,6 @@
package io.metersphere.project.service;
import io.metersphere.plugin.platform.api.AbstractPlatformPlugin;
import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.job.CleanUpReportJob;
@ -15,10 +16,14 @@ 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;
import io.metersphere.sdk.service.PluginLoadService;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.ServiceUtils;
import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.domain.Schedule;
import io.metersphere.system.domain.User;
import io.metersphere.system.domain.*;
import io.metersphere.system.mapper.ExtPluginMapper;
import io.metersphere.system.mapper.PluginMapper;
import io.metersphere.system.mapper.ServiceIntegrationMapper;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
@ -29,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@Transactional
@ -45,6 +51,17 @@ public class ProjectApplicationService {
@Resource
private ExtProjectTestResourcePoolMapper extProjectTestResourcePoolMapper;
@Resource
private ServiceIntegrationMapper serviceIntegrationMapper;
@Resource
private ExtPluginMapper extPluginMapper;
@Resource
private PluginMapper pluginMapper;
@Resource
private PluginLoadService pluginLoadService;
/**
* 更新配置信息
*
@ -159,6 +176,37 @@ public class ProjectApplicationService {
}
/**
* 获取平台列表
*
* @return
*/
public List<OptionDTO> getPlatformOptions(String organizationId) {
ServiceIntegrationExample example = new ServiceIntegrationExample();
example.createCriteria().andOrganizationIdEqualTo(organizationId).andEnableEqualTo(true);
List<ServiceIntegration> serviceIntegrations = serviceIntegrationMapper.selectByExample(example);
List<OptionDTO> options = new ArrayList<>();
if(CollectionUtils.isNotEmpty(serviceIntegrations)){
List<String> pluginIds = serviceIntegrations.stream().map(ServiceIntegration::getPluginId).collect(Collectors.toList());
options = extPluginMapper.selectPluginOptions(pluginIds);
return options;
}
return options;
}
public Object getPluginScript(String pluginId) {
this.checkResourceExist(pluginId);
AbstractPlatformPlugin platformPlugin = pluginLoadService.getImplInstance(pluginId, AbstractPlatformPlugin.class);
return pluginLoadService.getPluginScriptContent(pluginId, platformPlugin.getProjectScriptId());
}
private Plugin checkResourceExist(String id) {
return ServiceUtils.checkResourceExist(pluginMapper.selectByPrimaryKey(id), "permission.system_plugin.name");
}
/**
* 测试计划 日志
*
@ -200,6 +248,17 @@ public class ProjectApplicationService {
return delLog(application, OperationLogModule.PROJECT_PROJECT_MANAGER, "接口测试配置");
}
/**
* 用例管理 日志
*
* @param application
* @return
*/
public LogDTO updateCaseLog(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());

View File

@ -6,21 +6,38 @@ import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.sdk.base.BaseTest;
import io.metersphere.sdk.constants.ProjectApplicationType;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import io.metersphere.sdk.controller.handler.ResultHolder;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.domain.Plugin;
import io.metersphere.system.request.PluginUpdateRequest;
import io.metersphere.system.service.PluginService;
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.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 java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
@SpringBootTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class ProjectApplicationControllerTests extends BaseTest {
private static Plugin plugin;
@Resource
private PluginService pluginService;
public static final String PROJECT_ID = "project_application_test_id";
public static final String TIME_TYPE_VALUE = "3M";
@ -36,6 +53,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
//应用配置 - 测试计划 - 清理报告配置
@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();
//新增
@ -305,6 +323,87 @@ public class ProjectApplicationControllerTests extends BaseTest {
*/
/**
* ==========用例管理 start==========
*/
public static final String CASE_UPDATE_URL = "/project/application/update/case";
public static final String GET_CASE_URL = "/project/application/case";
public static final String GET_PLATFORM_URL = "/project/application/case/platform";
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");
this.requestPost(CASE_UPDATE_URL, request);
}
//应用配置 - 用例管理 - 重新提审
@Test
@Order(23)
public void testReview() throws Exception {
ProjectApplication request = creatRequest(ProjectApplicationType.APPLICATION_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);
this.requestPostWithOkAndReturn(GET_CASE_URL, request);
}
//应用管理 - 用例管理 - 获取平台下拉列表
@Test
@Order(25)
public void testGetPlatform() throws Exception {
this.requestGetWithOkAndReturn(GET_PLATFORM_URL + "/100002");
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_PLATFORM_URL + "/100001");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
//应用管理 - 用例管理 - 获取平台信息
@Test
@Order(26)
public void testGetPlatformInfo() throws Exception {
plugin = addPlugin();
MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_PLATFORM_INFO_URL + "/"+plugin.getId());
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* ==========用例管理 start==========
*/
public Plugin addPlugin() throws Exception {
PluginUpdateRequest request = new PluginUpdateRequest();
File jarFile = new File(
this.getClass().getClassLoader().getResource("file/metersphere-jira-plugin-3.x.jar")
.getPath()
);
FileInputStream inputStream = new FileInputStream(jarFile);
MockMultipartFile mockMultipartFile = new MockMultipartFile(jarFile.getName(), inputStream);
request.setName("测试插件1");
request.setGlobal(true);
request.setEnable(true);
request.setCreateUser(ADMIN.name());
return pluginService.add(request, mockMultipartFile);
}
private ProjectApplicationRequest getRequest(List<String> types) {
ProjectApplicationRequest request = new ProjectApplicationRequest();
request.setProjectId(PROJECT_ID);

View File

@ -0,0 +1,7 @@
-- 模拟数据
INSERT INTO `service_integration`(`id`, `plugin_id`, `enable`, `configuration`, `organization_id`) VALUES ('1', '952262969139212', b'1', '1111', '100001');

View File

@ -1,9 +1,12 @@
package io.metersphere.system.mapper;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.system.dto.PluginDTO;
import java.util.List;
public interface ExtPluginMapper {
List<PluginDTO> getPlugins();
List<OptionDTO> selectPluginOptions(List<String> pluginIds);
}

View File

@ -7,4 +7,15 @@
FROM
plugin
</select>
<select id="selectPluginOptions" resultType="io.metersphere.sdk.dto.OptionDTO">
SELECT id, name
FROM plugin
WHERE id IN
<foreach collection="list" item="id" index="index"
open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>