refactor(接口测试): 接口执行参数添加插件信息

This commit is contained in:
AgAngle 2024-02-06 20:02:01 +08:00 committed by Craftsman
parent a100078e46
commit def0db3f50
5 changed files with 45 additions and 9 deletions

View File

@ -4,12 +4,18 @@ import io.metersphere.sdk.dto.FileMetadataRepositoryDTO;
import io.metersphere.sdk.dto.FileModuleRepositoryDTO; import io.metersphere.sdk.dto.FileModuleRepositoryDTO;
import lombok.Data; import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/** /**
* @Author: jianxing * @Author: jianxing
* @CreateTime: 2023-12-15 16:59 * @CreateTime: 2023-12-15 16:59
*/ */
@Data @Data
public class ApiExecuteFileInfo { public class ApiExecuteFileInfo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String fileId; private String fileId;
private String fileName; private String fileName;
/** /**

View File

@ -61,11 +61,15 @@ public class TaskRequestDTO implements Serializable {
* 执行时下载文件后按原文件命名 * 执行时下载文件后按原文件命名
*/ */
private List<ApiExecuteFileInfo> refFiles; private List<ApiExecuteFileInfo> refFiles;
/**
* 插件文件列表
* id 为插件的 id + 更新时间戳
*/
private List<ApiExecuteFileInfo> pluginFiles;
/** /**
* 误报规则 * 误报规则
*/ */
List<MsRegexDTO> msRegexList; List<MsRegexDTO> msRegexList;
/** /**
* 项目id * 项目id
*/ */

View File

@ -23,10 +23,13 @@ public class MsFormDataBodyConverter extends MsBodyConverter<FormDataBody> {
@Override @Override
public void parse(HTTPSamplerProxy sampler, FormDataBody body, ParameterConfig config) { public void parse(HTTPSamplerProxy sampler, FormDataBody body, ParameterConfig config) {
List<FormDataKV> formValues = body.getFormValues(); List<FormDataKV> formValues = body.getFormValues();
sampler.setDoMultipart(true);
if (CollectionUtils.isEmpty(formValues)) {
return;
}
List<FormDataKV> validFormValues = formValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList()); List<FormDataKV> validFormValues = formValues.stream().filter(FormDataKV::isValid).collect(Collectors.toList());
List<FormDataKV> fileFormValues = validFormValues.stream().filter(FormDataKV::isFile).collect(Collectors.toList()); List<FormDataKV> fileFormValues = validFormValues.stream().filter(FormDataKV::isFile).collect(Collectors.toList());
List<FormDataKV> textFormValues = validFormValues.stream().filter(kv -> !kv.isFile()).collect(Collectors.toList()); List<FormDataKV> textFormValues = validFormValues.stream().filter(kv -> !kv.isFile()).collect(Collectors.toList());
sampler.setDoMultipart(true);
sampler.setHTTPFiles(getHttpFileArg(fileFormValues)); sampler.setHTTPFiles(getHttpFileArg(fileFormValues));
sampler.setArguments(getArguments(textFormValues)); sampler.setArguments(getArguments(textFormValues));
} }

View File

@ -12,6 +12,7 @@ import io.metersphere.plugin.api.dto.ParameterConfig;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest; import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.project.service.FileAssociationService; import io.metersphere.project.service.FileAssociationService;
import io.metersphere.project.service.FileManagementService; import io.metersphere.project.service.FileManagementService;
import io.metersphere.project.service.FileMetadataService; import io.metersphere.project.service.FileMetadataService;
@ -29,6 +30,7 @@ import io.metersphere.system.config.MinioProperties;
import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.pool.TestResourceNodeDTO; import io.metersphere.system.dto.pool.TestResourceNodeDTO;
import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO; import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO;
import io.metersphere.system.service.ApiPluginService;
import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.service.CommonProjectService;
import io.metersphere.system.service.SystemParameterService; import io.metersphere.system.service.SystemParameterService;
import io.metersphere.system.service.TestResourcePoolService; import io.metersphere.system.service.TestResourcePoolService;
@ -78,7 +80,8 @@ public class ApiExecuteService {
private FileMetadataService fileMetadataService; private FileMetadataService fileMetadataService;
@Resource @Resource
private FileManagementService fileManagementService; private FileManagementService fileManagementService;
@Resource
private ApiPluginService apiPluginService;
@PostConstruct @PostConstruct
private void init() { private void init() {
@ -148,6 +151,9 @@ public class ApiExecuteService {
String executeScript, String executeScript,
String projectId) { String projectId) {
// 设置插件文件信息
taskRequest.setPluginFiles(apiPluginService.getFileInfoByProjectId(projectId));
TestResourcePoolReturnDTO testResourcePoolDTO = getGetResourcePoolNodeDTO(projectId); TestResourcePoolReturnDTO testResourcePoolDTO = getGetResourcePoolNodeDTO(projectId);
TestResourceNodeDTO testResourceNodeDTO = getProjectExecuteNode(testResourcePoolDTO); TestResourceNodeDTO testResourceNodeDTO = getProjectExecuteNode(testResourcePoolDTO);
if (StringUtils.isNotBlank(testResourcePoolDTO.getServerUrl())) { if (StringUtils.isNotBlank(testResourcePoolDTO.getServerUrl())) {

View File

@ -4,7 +4,9 @@ import io.metersphere.plugin.api.spi.AbstractApiPlugin;
import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.AbstractMsTestElement;
import io.metersphere.plugin.api.spi.AbstractProtocolPlugin; import io.metersphere.plugin.api.spi.AbstractProtocolPlugin;
import io.metersphere.plugin.api.spi.MsTestElement; import io.metersphere.plugin.api.spi.MsTestElement;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.PluginScenarioType; import io.metersphere.sdk.constants.PluginScenarioType;
import io.metersphere.sdk.dto.api.task.ApiExecuteFileInfo;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.domain.Plugin; import io.metersphere.system.domain.Plugin;
import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.dto.ProtocolDTO;
@ -26,6 +28,8 @@ public class ApiPluginService {
private PluginLoadService pluginLoadService; private PluginLoadService pluginLoadService;
@Resource @Resource
private BasePluginService basePluginService; private BasePluginService basePluginService;
@Resource
private ProjectMapper projectMapper;
/** /**
* 获取协议插件的的协议列表 * 获取协议插件的的协议列表
@ -83,6 +87,7 @@ public class ApiPluginService {
/** /**
* 返回 MsTestElement 实现类与插件 ID 的映射 * 返回 MsTestElement 实现类与插件 ID 的映射
*
* @return * @return
*/ */
public Map<Class<? extends AbstractMsTestElement>, String> getTestElementPluginMap() { public Map<Class<? extends AbstractMsTestElement>, String> getTestElementPluginMap() {
@ -97,6 +102,7 @@ public class ApiPluginService {
/** /**
* 返回 MsTestElement 实现类与接口协议的映射 * 返回 MsTestElement 实现类与接口协议的映射
*
* @return * @return
*/ */
public Map<Class<? extends AbstractMsTestElement>, String> getTestElementProtocolMap() { public Map<Class<? extends AbstractMsTestElement>, String> getTestElementProtocolMap() {
@ -114,4 +120,15 @@ public class ApiPluginService {
} }
return testElementProtocolMap; return testElementProtocolMap;
} }
public List<ApiExecuteFileInfo> getFileInfoByProjectId(String projectId) {
return basePluginService.getOrgEnabledPlugins(projectMapper.selectByPrimaryKey(projectId).getOrganizationId(), PluginScenarioType.API_PROTOCOL)
.stream().map(plugin -> {
ApiExecuteFileInfo apiExecuteFileInfo = new ApiExecuteFileInfo();
apiExecuteFileInfo.setFileId(plugin.getId() + "_" + plugin.getUpdateTime());
apiExecuteFileInfo.setFileName(plugin.getFileName());
return apiExecuteFileInfo;
}).toList();
}
} }