Java Code Examples for org.pf4j.PluginManager#stopPlugin()
The following examples show how to use
org.pf4j.PluginManager#stopPlugin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JarPluginManagerSmokeIntegrationTest.java From exonum-java-binding with Apache License 2.0 | 5 votes |
@Test void loadsUnloadsJarPlugins(@TempDir Path tmp) throws IOException { Path pluginPath = tmp.resolve("test-plugin.jar"); String pluginId = "test-plugin"; String version = "1.0.1"; new ServiceArtifactBuilder() .setPluginId(pluginId) .setPluginVersion(version) .addExtensionClass(TestServiceModule1.class) .writeTo(pluginPath); PluginManager pluginManager = new JarPluginManager(); // Try to load the plugin String loadedPluginId = pluginManager.loadPlugin(pluginPath); assertThat(loadedPluginId).isEqualTo(pluginId); // Try to start PluginState pluginState = pluginManager.startPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STARTED); // Check the extensions List<Class<? extends ServiceModule>> extensionClasses = pluginManager .getExtensionClasses(ServiceModule.class, pluginId); assertThat(extensionClasses).hasSize(1); Class<?> extensionType = extensionClasses.get(0); assertNamesEqual(extensionType, TestServiceModule1.class); // Try to stop and unload pluginState = pluginManager.stopPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STOPPED); boolean unloadResult = pluginManager.unloadPlugin(pluginId); assertTrue(unloadResult); }
Example 2
Source File: ServiceArtifactBuilderSmokeIntegrationTest.java From exonum-java-binding with Apache License 2.0 | 4 votes |
@Test @DisplayName("Created plugin must be successfully loaded and unloaded by the PluginManager. " + "If this test does not work, subsequent use of ServiceArtifactBuilder in other ITs makes " + "no sense.") void createdArtifactCanBeLoaded(@TempDir Path tmp) throws IOException { Path pluginPath = tmp.resolve("test-plugin.jar"); String pluginId = "test-plugin"; String version = "1.0.1"; Class<?> pluginClass = TestPlugin.class; new ServiceArtifactBuilder() .setPluginId(pluginId) .setPluginVersion(version) .setManifestEntry("Plugin-Class", pluginClass.getName()) .addClass(pluginClass) .addExtensionClass(TestServiceExtensionImpl.class) .writeTo(pluginPath); PluginManager pluginManager = new DefaultPluginManager(); // Try to load the plugin String loadedPluginId = pluginManager.loadPlugin(pluginPath); assertThat(loadedPluginId).isEqualTo(pluginId); // Check it has correct version PluginWrapper plugin = pluginManager.getPlugin(pluginId); assertThat(plugin.getDescriptor().getVersion()).isEqualTo(version); assertNamesEqual(plugin.getPlugin().getClass(), pluginClass); // Try to start PluginState pluginState = pluginManager.startPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STARTED); // Check the extensions List<Class<? extends TestServiceExtension>> extensionClasses = pluginManager .getExtensionClasses(TestServiceExtension.class, pluginId); assertThat(extensionClasses).hasSize(1); Class<?> extensionType = extensionClasses.get(0); assertNamesEqual(extensionType, TestServiceExtensionImpl.class); // Try to stop and unload pluginState = pluginManager.stopPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STOPPED); boolean unloadResult = pluginManager.unloadPlugin(pluginId); assertTrue(unloadResult); }