fix(接口测试): 修复上传数据库驱动,执行报错的缺陷

--bug=1038846 --user=王孝刚 【场景】-场景步骤后置 SQL 查询 Oracle 数据库失败,没有找到驱动
https://www.tapd.cn/55049933/s/1492042
This commit is contained in:
wxg0103 2024-04-09 17:32:49 +08:00 committed by Craftsman
parent 5d6d392768
commit 34267b15a9
2 changed files with 24 additions and 5 deletions

View File

@ -35,10 +35,7 @@ import io.metersphere.system.config.MinioProperties;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.pool.TestResourceNodeDTO;
import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO;
import io.metersphere.system.service.ApiPluginService;
import io.metersphere.system.service.CommonProjectService;
import io.metersphere.system.service.SystemParameterService;
import io.metersphere.system.service.TestResourcePoolService;
import io.metersphere.system.service.*;
import io.metersphere.system.utils.TaskRunnerClient;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
@ -98,6 +95,8 @@ public class ApiExecuteService {
private GlobalParamsService globalParamsService;
@Resource
private ApiCommonService apiCommonService;
@Resource
private JdbcDriverPluginService jdbcDriverPluginService;
@PostConstruct
private void init() {
@ -144,7 +143,11 @@ public class ApiExecuteService {
String executeScript = parseExecuteScript(runRequest.getTestElement(), parameterConfig);
// 设置插件文件信息 todo 多项目
taskRequest.setPluginFiles(apiPluginService.getFileInfoByProjectId(taskRequest.getProjectId()));
List<ApiExecuteFileInfo> pluginFiles = new ArrayList<>();
pluginFiles.addAll(apiPluginService.getFileInfoByProjectId(taskRequest.getProjectId()));
pluginFiles.addAll(jdbcDriverPluginService.getFileInfoByProjectId(taskRequest.getProjectId()));
taskRequest.setPluginFiles(pluginFiles);
// 将测试脚本缓存到 redis
String scriptRedisKey = getScriptRedisKey(taskRequest.getReportId(), taskRequest.getResourceId());

View File

@ -1,6 +1,8 @@
package io.metersphere.system.service;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.PluginScenarioType;
import io.metersphere.sdk.dto.api.task.ApiExecuteFileInfo;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.LogUtils;
@ -23,6 +25,9 @@ public class JdbcDriverPluginService {
private PluginLoadService pluginLoadService;
@Resource
private BasePluginService basePluginService;
@Resource
private ProjectMapper projectMapper;
public static final String MYSQL_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
public static final String DRIVER_OPTION_SEPARATOR = "&";
public static final String SYSTEM_PLUGIN_ID = "system";
@ -89,4 +94,15 @@ public class JdbcDriverPluginService {
.findFirst()
.orElseThrow(() -> new MSException("未找到对应的驱动"));
}
public List<ApiExecuteFileInfo> getFileInfoByProjectId(String projectId) {
return basePluginService.getOrgEnabledPlugins(projectMapper.selectByPrimaryKey(projectId).getOrganizationId(), PluginScenarioType.JDBC_DRIVER)
.stream().map(plugin -> {
ApiExecuteFileInfo apiExecuteFileInfo = new ApiExecuteFileInfo();
apiExecuteFileInfo.setFileId(plugin.getId() + "_" + plugin.getUpdateTime());
apiExecuteFileInfo.setFileName(plugin.getFileName());
return apiExecuteFileInfo;
}).toList();
}
}