feat(接口测试): 动态处理函数包
This commit is contained in:
parent
2c123ff830
commit
bbfb7d146e
|
@ -54,4 +54,8 @@ public class LocalRepositoryDir {
|
|||
public static String getSystemCacheDir() {
|
||||
return SYSTEM_CACHE_DIR;
|
||||
}
|
||||
|
||||
public static String getFuncJarDir() {
|
||||
return ROOT_DIR + "/api/func-jar";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,12 @@ public class TaskRequestDTO implements Serializable {
|
|||
* id 为插件的 id + 更新时间戳
|
||||
*/
|
||||
private List<ApiExecuteFileInfo> pluginFiles;
|
||||
|
||||
/**
|
||||
* 接口测试函数包
|
||||
*/
|
||||
private List<ApiExecuteFileInfo> funcJars;
|
||||
|
||||
/**
|
||||
* 误报规则
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.api.parser.jmeter.processor;
|
||||
|
||||
import io.metersphere.plugin.api.constants.ElementProperty;
|
||||
import io.metersphere.project.constants.ScriptLanguageType;
|
||||
import io.metersphere.project.api.processor.ScriptProcessor;
|
||||
import io.metersphere.api.parser.jmeter.constants.JmeterAlias;
|
||||
|
@ -17,6 +18,7 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
|
|||
|
||||
public static final String ENV_VARIABLE_EXPRESSION = "${__metersphere_env_id}";
|
||||
public static final String MS_RUNNING_ENV_PREFIX = "MS.ENV.";
|
||||
|
||||
public static void parse(TestElement testElement, ScriptProcessor scriptProcessor) {
|
||||
// 脚本安全校验
|
||||
ScriptFilter.verify(scriptProcessor.getScriptLanguage(), scriptProcessor.getName(), scriptProcessor.getScript());
|
||||
|
@ -38,9 +40,10 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
|
|||
testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
|
||||
testElement.setProperty(JmeterProperty.SCRIPT_LANGUAGE, scriptProcessor.getScriptLanguage());
|
||||
testElement.setProperty(JmeterProperty.SCRIPT, scriptProcessor.getScript());
|
||||
testElement.setProperty(ElementProperty.PROJECT_ID.name(), scriptProcessor.getProjectId());
|
||||
}
|
||||
|
||||
public static boolean isJSR233(ScriptProcessor scriptProcessor) {
|
||||
return !StringUtils.equals(scriptProcessor.getScriptLanguage(), ScriptLanguageType.BEANSHELL.getValue());
|
||||
return !StringUtils.equals(scriptProcessor.getScriptLanguage(), ScriptLanguageType.BEANSHELL.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.api.parser.TestElementParser;
|
|||
import io.metersphere.api.parser.TestElementParserFactory;
|
||||
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||
import io.metersphere.plugin.api.spi.AbstractMsTestElement;
|
||||
import io.metersphere.project.domain.FileMetadata;
|
||||
import io.metersphere.project.domain.ProjectApplication;
|
||||
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
|
||||
import io.metersphere.project.service.FileAssociationService;
|
||||
|
@ -299,6 +300,27 @@ public class ApiExecuteService {
|
|||
}
|
||||
|
||||
taskRequest.setRefFiles(refFiles);
|
||||
// 获取函数jar包
|
||||
List<FileMetadata> fileMetadataList = fileManagementService.findJarByProjectId(List.of(taskRequest.getProjectId()));
|
||||
taskRequest.setFuncJars(fileMetadataList.stream()
|
||||
.map(file -> {
|
||||
String fileName = file.getName() + "." + file.getType();
|
||||
ApiExecuteFileInfo tempFileInfo = getApiExecuteFileInfo(file.getId(), fileName, file.getProjectId(), file.getStorage());
|
||||
if (StorageType.isGit(file.getStorage())) {
|
||||
// 设置Git信息
|
||||
tempFileInfo.setFileMetadataRepositoryDTO(fileManagementService.getFileMetadataRepositoryDTO(file.getId()));
|
||||
tempFileInfo.setFileModuleRepositoryDTO(fileManagementService.getFileModuleRepositoryDTO(file.getModuleId()));
|
||||
}
|
||||
return tempFileInfo;
|
||||
}).toList());
|
||||
|
||||
// TODO 当前项目没有包分两种情况,1 之前存在被删除,2 一直不存在
|
||||
// 为了兼容1 这种情况需要初始化一条空的数据,由执行机去做卸载
|
||||
if (CollectionUtils.isEmpty(taskRequest.getFuncJars())) {
|
||||
ApiExecuteFileInfo tempFileInfo = new ApiExecuteFileInfo();
|
||||
tempFileInfo.setProjectId(request.getProjectId());
|
||||
taskRequest.setFuncJars(List.of(tempFileInfo));
|
||||
}
|
||||
}
|
||||
|
||||
private static ApiExecuteFileInfo getApiExecuteFileInfo(String fileId, String fileName, String projectId) {
|
||||
|
|
|
@ -231,4 +231,13 @@ public class FileManagementService {
|
|||
byte[] fileBytes = this.getFile(fileMetadata);
|
||||
return TempFileUtils.compressPic(fileBytes);
|
||||
}
|
||||
|
||||
public List<FileMetadata> findJarByProjectId(List<String> projectIds) {
|
||||
FileMetadataExample example = new FileMetadataExample();
|
||||
example.createCriteria().andProjectIdIn(projectIds)
|
||||
.andEnableEqualTo(true)
|
||||
.andTypeEqualTo("jar")
|
||||
.andLatestEqualTo(true);
|
||||
return fileMetadataMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue