From 733fb970b4523f61832f0f92f8b4c90daf949487 Mon Sep 17 00:00:00 2001 From: decebals Date: Thu, 30 May 2019 22:03:51 +0300 Subject: Add JarPluginManagerTest --- .../test/java/org/pf4j/JarPluginManagerTest.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java (limited to 'pf4j') diff --git a/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java new file mode 100644 index 0000000..45c3999 --- /dev/null +++ b/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pf4j; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.pf4j.plugin.PluginJar; +import org.pf4j.plugin.TestPlugin; + +import java.io.IOException; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class JarPluginManagerTest { + + private PluginJar pluginJar; + private JarPluginManager pluginManager; + + @TempDir + Path pluginsPath; + + @BeforeEach + public void setUp() throws IOException { + pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin") + .pluginClass(TestPlugin.class.getName()) + .pluginVersion("1.2.3") + .build(); + + pluginManager = new JarPluginManager(pluginsPath); + } + + @AfterEach + public void tearDown() { + pluginJar = null; + pluginManager = null; + } + + @Test + public void unloadPlugin() throws Exception { + pluginManager.loadPlugins(); + + assertEquals(1, pluginManager.getPlugins().size()); + + boolean unloaded = pluginManager.unloadPlugin(pluginJar.pluginId()); + assertTrue(unloaded); + + assertTrue(pluginJar.file().exists()); + } + + @Test + public void deletePlugin() throws Exception { + pluginManager.loadPlugins(); + + assertEquals(1, pluginManager.getPlugins().size()); + + boolean deleted = pluginManager.deletePlugin(pluginJar.pluginId()); + assertTrue(deleted); + + assertFalse(pluginJar.file().exists()); + } + +} -- cgit v1.2.3