refactor(接口测试): 优化接口用例执行选择资源池

This commit is contained in:
wxg0103 2024-03-15 20:54:12 +08:00 committed by Craftsman
parent d01c89ddc8
commit ffbe77bb73
8 changed files with 106 additions and 14 deletions

View File

@ -11,6 +11,7 @@ import io.metersphere.project.dto.environment.EnvironmentConfig;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.ProtocolDTO;
import io.metersphere.system.security.CheckOwner;
import io.swagger.v3.oas.annotations.Operation;
@ -107,4 +108,30 @@ public class ApiTestController {
public EnvironmentConfig getEnvironmentConfig(@PathVariable String environmentId) {
return apiTestService.getEnvironmentConfig(environmentId);
}
@GetMapping("/pool-option/{projectId}")
@Operation(summary = "接口测试-获取资源池")
@RequiresPermissions(value = {
PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE,
PermissionConstants.PROJECT_API_DEFINITION_EXECUTE,
PermissionConstants.PROJECT_API_SCENARIO_EXECUTE
}, logical = Logical.OR)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public List<TestResourcePool> getPool(@PathVariable String projectId) {
return apiTestService.getPoolOption(projectId);
}
@GetMapping("/get-pool/{projectId}")
@Operation(summary = "接口测试-获取资源池")
@RequiresPermissions(value = {
PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE,
PermissionConstants.PROJECT_API_DEFINITION_EXECUTE,
PermissionConstants.PROJECT_API_SCENARIO_EXECUTE
}, logical = Logical.OR)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public String getPoolId(@PathVariable String projectId) {
return apiTestService.getPoolId(projectId);
}
}

View File

@ -9,9 +9,13 @@ import io.metersphere.plugin.api.spi.AbstractApiPlugin;
import io.metersphere.plugin.api.spi.AbstractProtocolPlugin;
import io.metersphere.project.dto.environment.EnvironmentConfig;
import io.metersphere.project.mapper.ExtEnvironmentMapper;
import io.metersphere.project.mapper.ExtProjectMapper;
import io.metersphere.project.service.EnvironmentService;
import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.ProtocolDTO;
import io.metersphere.system.service.ApiPluginService;
import io.metersphere.system.service.PluginLoadService;
@ -22,7 +26,9 @@ import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author jianxing
@ -40,6 +46,10 @@ public class ApiTestService {
private ExtEnvironmentMapper extEnvironmentMapper;
@Resource
private EnvironmentService environmentService;
@Resource
private ExtProjectMapper extProjectMapper;
@Resource
private ProjectApplicationService projectApplicationService;
public List<ProtocolDTO> getProtocols(String orgId) {
List<ProtocolDTO> protocols = apiPluginService.getProtocols(orgId);
@ -99,4 +109,15 @@ public class ApiTestService {
newEnvironmentConfig.setDataSources(environmentConfig.getDataSources());
return newEnvironmentConfig;
}
public List<TestResourcePool> getPoolOption(String projectId) {
//获取资源池
return extProjectMapper.getResourcePoolOption(projectId, "api_test");
}
public String getPoolId(String projectId) {
Map<String, Object> configMap = new HashMap<>();
projectApplicationService.putResourcePool(projectId, configMap, "apiTest");
return (String) configMap.get(ProjectApplicationType.API.API_RESOURCE_POOL_ID.name());
}
}

View File

@ -223,4 +223,16 @@ public class ApiTestControllerTests extends BaseTest {
Assertions.assertNull(environmentConfig.getAssertionConfig());
}
@Test
public void getPoolOption() throws Exception {
// @@请求成功
this.requestGet("/pool-option/" + DEFAULT_PROJECT_ID);
}
@Test
public void getPoolId() throws Exception {
// @@请求成功
this.requestGet("/get-pool/" + DEFAULT_PROJECT_ID);
}
}

View File

@ -2,6 +2,7 @@ package io.metersphere.project.mapper;
import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectTestResourcePool;
import io.metersphere.system.domain.TestResourcePool;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -25,4 +26,7 @@ public interface ExtProjectMapper {
List<ProjectTestResourcePool> getResourcePool(@Param("projectId") String projectId, @Param("type") String type);
List<Project> getAllProject(@Param("organizationId") String organizationId);
List<TestResourcePool> getResourcePoolOption(@Param("projectId") String projectId, @Param("type") String type);
}

View File

@ -84,4 +84,14 @@
order by
CONVERT( name USING GBK) ASC
</select>
<select id="getResourcePoolOption" resultType="io.metersphere.system.domain.TestResourcePool">
select t.*
from project_test_resource_pool p left join test_resource_pool t on
t.id = p.test_resource_pool_id
where p.project_id = #{projectId}
and t.enable = 1
and t.deleted = 0
and t.${type} = 1
</select>
</mapper>

View File

@ -40,11 +40,13 @@ import {
GetModuleCountUrl,
GetModuleOnlyTreeUrl,
GetModuleTreeUrl,
GetPoolId,
GetTrashModuleCountUrl,
GetTrashModuleTreeUrl,
ImportDefinitionUrl,
MoveModuleUrl,
OperationHistoryUrl,
PoolOption,
RecoverCaseUrl,
RecoverDefinitionUrl,
RecoverOperationHistoryUrl,
@ -115,6 +117,7 @@ import {
TableQueryParams,
TransferFileParams,
} from '@/models/common';
import { ResourcePoolItem } from '@/models/setting/resourcePool';
// 更新模块
export function updateModule(data: ApiDefinitionUpdateModuleParams) {
@ -460,3 +463,12 @@ export function getApiCaseChangeHistory(data: ApiCaseChangeHistoryParams) {
export function getApiCaseDependency(data: ApiCaseDependencyParams) {
return MSR.post({ url: GetDependencyUrl, data });
}
// 获取接口的资源池列表
export function getPoolOption(projectId: string) {
return MSR.get<ResourcePoolItem[]>({ url: PoolOption + projectId });
}
export function getPoolId(projectId: string) {
return MSR.get<string>({ url: GetPoolId + projectId });
}

View File

@ -83,3 +83,6 @@ export const BatchRecoverCaseUrl = '/api/case/batch/recover'; // 接口用例批
export const DeleteRecycleCaseUrl = '/api/case/delete'; // 接口用例彻底删除
export const BatchDeleteRecycleCaseUrl = '/api/case/batch/delete'; // 接口用例批量彻底删除
export const AddCaseUrl = '/api/case/add'; // 添加用例
export const PoolOption = '/api/test/pool-option/'; // 获取接口资源池
export const GetPoolId = '/api/test/get-pool/'; // 获取项目应用设置的资源池id

View File

@ -358,18 +358,19 @@
executeCase,
getCasePage,
getEnvList,
getPoolId,
getPoolOption,
updateCasePriority,
updateCaseStatus, updateDefinition,
updateCaseStatus,
} from '@/api/modules/api-test/management';
import { getCaseDefaultFields } from '@/api/modules/case-management/featureCase';
import { getPoolList } from '@/api/modules/setting/resourcePool';
import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal';
import useTableStore from '@/hooks/useTableStore';
import useAppStore from '@/store/modules/app';
import { ApiCaseDetail, Environment } from '@/models/apiTest/management';
import { DragSortParams, TableQueryParams } from '@/models/common';
import { DragSortParams } from '@/models/common';
import { ResourcePoolItem } from '@/models/setting/resourcePool';
import { RequestDefinitionStatus } from '@/enums/apiEnum';
import { TableKeyEnum } from '@/enums/tableEnum';
@ -576,6 +577,7 @@
const environmentList = ref<Environment[]>();
const resourcePoolList = ref<ResourcePoolItem[]>();
const defaultPoolId = ref<string>();
const moduleIds = computed(() => {
return props.activeModule === 'all' ? [] : [props.activeModule];
@ -615,22 +617,23 @@
//
async function initPoolList() {
const searchPoolParams = ref<TableQueryParams>({
current: 1,
pageSize: 10,
keyword: '',
deleted: false,
apiTest: true,
enable: false,
});
const result = await getPoolList(searchPoolParams.value);
resourcePoolList.value = result.list;
resourcePoolList.value = await getPoolOption(appStore.getCurrentProjectId);
}
async function getDefaultPoolId() {
try {
defaultPoolId.value = await getPoolId(appStore.getCurrentProjectId);
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
onBeforeMount(() => {
loadCaseList();
initPoolList();
getCaseLevelFields();
getDefaultPoolId();
});
function handleFilterHidden(val: boolean) {
@ -936,6 +939,7 @@
break;
case 'execute':
showBatchExecute.value = true;
batchExecuteForm.value.poolId = defaultPoolId.value || '';
initEnvList();
break;
default:
@ -974,7 +978,6 @@
:deep(.arco-radio-group) {
margin-left: -5px;
}
.ms-switch {
display: flex;
align-items: center;