mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 20:19:16 +08:00
refactor(接口测试): 优化插件加载单元测试
This commit is contained in:
parent
b85aa15910
commit
828f89b130
@ -70,6 +70,7 @@ public class PluginLoadService {
|
||||
|
||||
/**
|
||||
* 从默认的对象存储下载插件到本地,再加载
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
* @throws Exception
|
||||
@ -78,17 +79,15 @@ public class PluginLoadService {
|
||||
MsFileUtils.validateFileName(fileName);
|
||||
String filePath = LocalRepositoryDir.getPluginDir() + "/" + fileName;
|
||||
File file = new File(filePath);
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
InputStream fileAsStream = FileCenter.getDefaultRepository()
|
||||
.getFileAsStream(getDefaultRepositoryFileRequest(fileName));
|
||||
try (InputStream fileAsStream = FileCenter.getDefaultRepository().getFileAsStream(getDefaultRepositoryFileRequest(fileName))) {
|
||||
FileUtils.copyInputStreamToFile(fileAsStream, file);
|
||||
}
|
||||
msPluginManager.loadPlugin(Paths.get(filePath));
|
||||
} catch (Exception e) {
|
||||
LogUtils.error("从对象存储加载插件异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将插件上传到本地文件系统中
|
||||
@ -227,6 +226,7 @@ public class PluginLoadService {
|
||||
|
||||
/**
|
||||
* 删除本地插件
|
||||
*
|
||||
* @param fileName
|
||||
*/
|
||||
public void deleteLocalPluginFile(String fileName) {
|
||||
@ -258,9 +258,10 @@ public class PluginLoadService {
|
||||
|
||||
/**
|
||||
* 获取插件中的是实现类列表
|
||||
*
|
||||
* @param clazz
|
||||
* @return
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T> List<T> getExtensions(Class<T> clazz) {
|
||||
return msPluginManager.getExtensions(clazz);
|
||||
@ -268,10 +269,11 @@ public class PluginLoadService {
|
||||
|
||||
/**
|
||||
* 获取插件中的是实现类
|
||||
*
|
||||
* @param clazz
|
||||
* @param pluginId
|
||||
* @return
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public <T> Class<? extends T> getExtensionsClass(Class<T> clazz, String pluginId) {
|
||||
List<Class<? extends T>> classes = msPluginManager.getExtensionClasses(clazz, pluginId);
|
||||
|
@ -5,6 +5,7 @@ import io.metersphere.sdk.constants.PermissionConstants;
|
||||
import io.metersphere.sdk.constants.PluginScenarioType;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.base.BasePluginTestService;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.param.PluginUpdateRequestDefinition;
|
||||
@ -136,14 +137,14 @@ public class PluginControllerTests extends BaseTest {
|
||||
addPlugin = plugin;
|
||||
|
||||
// 模拟其他节点加载插件
|
||||
pluginLoadService.handlePluginDeleteNotified(plugin.getId(), jarFile.getName());
|
||||
unloadAndDeletePlugin(jarFile, plugin);
|
||||
pluginLoadService.handlePluginAddNotified(plugin.getId(), jarFile.getName());
|
||||
|
||||
// 增加覆盖率
|
||||
pluginLoadService.handlePluginDeleteNotified(plugin.getId(), jarFile.getName());
|
||||
unloadAndDeletePlugin(jarFile, plugin);
|
||||
pluginLoadService.loadPlugin(jarFile.getName());
|
||||
|
||||
pluginLoadService.handlePluginDeleteNotified(plugin.getId(), jarFile.getName());
|
||||
unloadAndDeletePlugin(jarFile, plugin);
|
||||
pluginLoadService.loadPlugins();
|
||||
|
||||
pluginLoadService.getExtensions(Platform.class);
|
||||
@ -235,6 +236,14 @@ public class PluginControllerTests extends BaseTest {
|
||||
requestMultipartPermissionTest(PermissionConstants.SYSTEM_PLUGIN_ADD, DEFAULT_ADD, multiValueMap);
|
||||
}
|
||||
|
||||
private void unloadAndDeletePlugin(File jarFile, Plugin plugin) {
|
||||
try {
|
||||
pluginLoadService.handlePluginDeleteNotified(plugin.getId(), jarFile.getName());
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void update() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user