You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LegacyExtensionFinderTest.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2012-present the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.pf4j;
  17. import org.junit.jupiter.api.Test;
  18. import org.junit.jupiter.api.condition.EnabledOnOs;
  19. import org.junit.jupiter.api.io.TempDir;
  20. import org.pf4j.plugin.PluginJar;
  21. import org.pf4j.plugin.TestExtension;
  22. import org.pf4j.plugin.TestPlugin;
  23. import java.nio.file.Path;
  24. import java.util.Map;
  25. import java.util.Set;
  26. import static org.hamcrest.MatcherAssert.assertThat;
  27. import static org.hamcrest.Matchers.contains;
  28. import static org.junit.jupiter.api.Assertions.assertEquals;
  29. import static org.junit.jupiter.api.Assertions.assertFalse;
  30. import static org.junit.jupiter.api.Assertions.assertNotNull;
  31. import static org.junit.jupiter.api.Assertions.assertTrue;
  32. import static org.junit.jupiter.api.condition.OS.WINDOWS;
  33. public class LegacyExtensionFinderTest {
  34. @TempDir
  35. Path pluginsPath;
  36. @Test
  37. @EnabledOnOs(WINDOWS)
  38. public void shouldUnlockFileAfterReadingExtensionsFromPlugin() throws Exception {
  39. PluginJar pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
  40. .pluginClass(TestPlugin.class.getName())
  41. .pluginVersion("1.2.3")
  42. .extension(TestExtension.class.getName())
  43. .build();
  44. assertTrue(pluginJar.file().exists());
  45. PluginManager pluginManager = new JarPluginManager(pluginsPath);
  46. pluginManager.loadPlugins();
  47. assertEquals(1, pluginManager.getPlugins().size());
  48. LegacyExtensionFinder extensionFinder = new LegacyExtensionFinder(pluginManager);
  49. Map<String, Set<String>> pluginsStorages = extensionFinder.readPluginsStorages();
  50. assertNotNull(pluginsStorages);
  51. pluginManager.unloadPlugin(pluginJar.pluginId());
  52. boolean fileDeleted = pluginJar.file().delete();
  53. Set<String> pluginStorages = pluginsStorages.get(pluginJar.pluginId());
  54. assertNotNull(pluginStorages);
  55. assertEquals(1, pluginStorages.size());
  56. assertThat(pluginStorages, contains(TestExtension.class.getName()));
  57. assertTrue(fileDeleted);
  58. assertFalse(pluginJar.file().exists());
  59. }
  60. }