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.

JarPluginManagerTest.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.AfterEach;
  18. import org.junit.jupiter.api.BeforeEach;
  19. import org.junit.jupiter.api.Test;
  20. import org.junit.jupiter.api.io.TempDir;
  21. import org.pf4j.plugin.PluginJar;
  22. import org.pf4j.plugin.TestPlugin;
  23. import java.io.IOException;
  24. import java.nio.file.Path;
  25. import static org.junit.jupiter.api.Assertions.assertEquals;
  26. import static org.junit.jupiter.api.Assertions.assertFalse;
  27. import static org.junit.jupiter.api.Assertions.assertTrue;
  28. public class JarPluginManagerTest {
  29. private PluginJar pluginJar;
  30. private JarPluginManager pluginManager;
  31. @TempDir
  32. Path pluginsPath;
  33. @BeforeEach
  34. public void setUp() throws IOException {
  35. pluginJar = new PluginJar.Builder(pluginsPath.resolve("test-plugin.jar"), "test-plugin")
  36. .pluginClass(TestPlugin.class.getName())
  37. .pluginVersion("1.2.3")
  38. .build();
  39. pluginManager = new JarPluginManager(pluginsPath);
  40. }
  41. @AfterEach
  42. public void tearDown() {
  43. pluginJar = null;
  44. pluginManager = null;
  45. }
  46. @Test
  47. public void unloadPlugin() throws Exception {
  48. pluginManager.loadPlugins();
  49. assertEquals(1, pluginManager.getPlugins().size());
  50. boolean unloaded = pluginManager.unloadPlugin(pluginJar.pluginId());
  51. assertTrue(unloaded);
  52. assertTrue(pluginJar.file().exists());
  53. }
  54. @Test
  55. public void deletePlugin() throws Exception {
  56. pluginManager.loadPlugins();
  57. assertEquals(1, pluginManager.getPlugins().size());
  58. boolean deleted = pluginManager.deletePlugin(pluginJar.pluginId());
  59. assertTrue(deleted);
  60. assertFalse(pluginJar.file().exists());
  61. }
  62. }