|
|
|
@ -15,8 +15,12 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.pf4j; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.junit.jupiter.api.io.TempDir; |
|
|
|
|
import org.pf4j.test.PluginZip; |
|
|
|
|
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse; |
|
|
|
@ -27,6 +31,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
*/ |
|
|
|
|
public class PluginDependencyTest { |
|
|
|
|
|
|
|
|
|
private DefaultPluginManager pluginManager; |
|
|
|
|
|
|
|
|
|
@TempDir |
|
|
|
|
Path pluginsPath; |
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
public void setUp() { |
|
|
|
|
pluginManager = new DefaultPluginManager(pluginsPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Test of getPluginId method, of class PluginDependency. |
|
|
|
|
*/ |
|
|
|
@ -77,4 +91,59 @@ public class PluginDependencyTest {
|
|
|
|
|
assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0, optional=true]", instance.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void dependentStop() throws Exception { |
|
|
|
|
// B depends on A
|
|
|
|
|
PluginZip pluginA = new PluginZip.Builder(pluginsPath.resolve("A-plugin-1.2.3.zip"), "plugin.a") |
|
|
|
|
.pluginVersion("1.2.3").build(); |
|
|
|
|
|
|
|
|
|
PluginZip pluginB = new PluginZip.Builder(pluginsPath.resolve("B-plugin-1.2.3.zip"), "plugin.b") |
|
|
|
|
.pluginDependencies("plugin.a") |
|
|
|
|
.pluginVersion("1.2.3").build(); |
|
|
|
|
|
|
|
|
|
pluginManager.loadPlugins(); |
|
|
|
|
assertEquals(2, pluginManager.getPlugins().size()); |
|
|
|
|
|
|
|
|
|
pluginManager.startPlugins(); |
|
|
|
|
assertEquals(2, pluginManager.getStartedPlugins().size()); |
|
|
|
|
|
|
|
|
|
// stop A, both A and B should be stopped
|
|
|
|
|
pluginManager.stopPlugin("plugin.a"); |
|
|
|
|
assertEquals(0, pluginManager.getStartedPlugins().size()); |
|
|
|
|
|
|
|
|
|
// start all again
|
|
|
|
|
pluginManager.startPlugins(); |
|
|
|
|
assertEquals(2, pluginManager.getStartedPlugins().size()); |
|
|
|
|
|
|
|
|
|
// dependent info should be kept. #394
|
|
|
|
|
pluginManager.stopPlugin("plugin.a"); |
|
|
|
|
assertEquals(0, pluginManager.getStartedPlugins().size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void dependentUnload() throws Exception { |
|
|
|
|
// B depends on A
|
|
|
|
|
PluginZip pluginA = new PluginZip.Builder(pluginsPath.resolve("A-plugin-1.2.3.zip"), "plugin.a") |
|
|
|
|
.pluginVersion("1.2.3").build(); |
|
|
|
|
|
|
|
|
|
PluginZip pluginB = new PluginZip.Builder(pluginsPath.resolve("B-plugin-1.2.3.zip"), "plugin.b") |
|
|
|
|
.pluginDependencies("plugin.a") |
|
|
|
|
.pluginVersion("1.2.3").build(); |
|
|
|
|
|
|
|
|
|
pluginManager.loadPlugins(); |
|
|
|
|
assertEquals(2, pluginManager.getPlugins().size()); |
|
|
|
|
|
|
|
|
|
pluginManager.startPlugins(); |
|
|
|
|
assertEquals(2, pluginManager.getStartedPlugins().size()); |
|
|
|
|
|
|
|
|
|
// stop A, both A and B should be stopped
|
|
|
|
|
pluginManager.stopPlugin("plugin.a"); |
|
|
|
|
assertEquals(0, pluginManager.getStartedPlugins().size()); |
|
|
|
|
|
|
|
|
|
// unload A, both A and B should be unloaded
|
|
|
|
|
pluginManager.unloadPlugin("plugin.a"); |
|
|
|
|
assertEquals(0, pluginManager.getResolvedPlugins().size()); |
|
|
|
|
assertEquals(0, pluginManager.getPlugins().size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|