diff options
author | hazemkmammu <hazemkmammu@users.noreply.github.com> | 2019-06-04 15:02:55 +0530 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-06-04 12:32:55 +0300 |
commit | 1bd6b801d45193b660d59656fafe6ea6cde77975 (patch) | |
tree | 5116513db28b36ee56382208eb5830cf52a37d9b /pf4j | |
parent | 6fd8ae23848fafaadb37d0e9e9169e0c1dc4ccb2 (diff) | |
download | pf4j-1bd6b801d45193b660d59656fafe6ea6cde77975.tar.gz pf4j-1bd6b801d45193b660d59656fafe6ea6cde77975.zip |
Recreate FileSystemException in windows on plugin delete (#321)
Diffstat (limited to 'pf4j')
-rw-r--r-- | pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java b/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java new file mode 100644 index 0000000..fe2cac2 --- /dev/null +++ b/pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java @@ -0,0 +1,69 @@ +package org.pf4j; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.pf4j.plugin.PluginJar; + +public class LegacyExtensionFinderTest { + + @TempDir + public Path pluginsPath; + + public static class TestPlugin extends Plugin { + + public TestPlugin(PluginWrapper wrapper) { + super(wrapper); + } + } + + @Extension + public static class TestExtension implements ExtensionPoint { + + } + + private static boolean systemIsWindows() { + String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); + return os.startsWith("win"); + } + + @Test + public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws IOException, PluginException { + + assumeTrue(systemIsWindows()); + final Path pluginJarPath = pluginsPath.resolve("test-plugin.jar"); + PluginJar pluginJar = new PluginJar.Builder(pluginJarPath, "test-plugin") + .pluginClass(TestPlugin.class.getName()) + .pluginVersion("1.2.3") + .extension(TestExtension.class.getName()) + .build(); + + JarPluginManager pluginManager = new JarPluginManager(pluginsPath); + + pluginManager.loadPlugins(); + LegacyExtensionFinder extensionFinder = new LegacyExtensionFinder(pluginManager); + Map<String, Set<String>> pluginStorages = extensionFinder.readPluginsStorages(); + pluginManager.unloadPlugin(pluginJar.pluginId()); + boolean fileDeleted = pluginJarPath.toFile().delete(); + + assertThat(pluginStorages, is(notNullValue())); + assertThat(pluginStorages.get(pluginJar.pluginId()), is(notNullValue())); + assertThat(pluginStorages.get(pluginJar.pluginId()).size(), is(equalTo(1))); + assertThat(pluginStorages.get(pluginJar.pluginId()), + contains("org.pf4j.LegacyExtensionFinderTest$TestExtension")); + assertThat(fileDeleted, is(equalTo(true))); + } + +} |