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.

LoadPluginsFromMultipleRootsTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.pf4j.test.PluginZip;
  21. import org.pf4j.util.FileUtils;
  22. import java.io.IOException;
  23. import java.nio.file.Files;
  24. import java.nio.file.Path;
  25. import static org.junit.jupiter.api.Assertions.assertEquals;
  26. import static org.junit.jupiter.api.Assertions.assertTrue;
  27. public class LoadPluginsFromMultipleRootsTest {
  28. private DefaultPluginManager pluginManager;
  29. Path pluginsPath1;
  30. Path pluginsPath2;
  31. @BeforeEach
  32. public void setUp() throws IOException {
  33. pluginsPath1 = Files.createTempDirectory("junit-pf4j-");
  34. pluginsPath2 = Files.createTempDirectory("junit-pf4j-");
  35. pluginManager = new DefaultPluginManager(pluginsPath1, pluginsPath2);
  36. }
  37. @AfterEach
  38. public void tearDown() throws IOException {
  39. FileUtils.delete(pluginsPath1);
  40. FileUtils.delete(pluginsPath2);
  41. }
  42. @Test
  43. public void load() throws Exception {
  44. PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath1.resolve("my-plugin-1.2.3.zip"), "myPlugin")
  45. .pluginVersion("1.2.3")
  46. .build();
  47. PluginZip pluginZip2 = new PluginZip.Builder(pluginsPath2.resolve("my-other-plugin-4.5.6.zip"), "myOtherPlugin")
  48. .pluginVersion("4.5.6")
  49. .build();
  50. assertTrue(Files.exists(pluginZip1.path()));
  51. assertEquals(0, pluginManager.getPlugins().size());
  52. pluginManager.loadPlugins();
  53. assertTrue(Files.exists(pluginZip1.path()));
  54. assertTrue(Files.exists(pluginZip1.unzippedPath()));
  55. assertTrue(Files.exists(pluginZip2.path()));
  56. assertTrue(Files.exists(pluginZip2.unzippedPath()));
  57. assertEquals(2, pluginManager.getPlugins().size());
  58. assertEquals(pluginZip1.pluginId(), pluginManager.idForPath(pluginZip1.unzippedPath()));
  59. assertEquals(pluginZip2.pluginId(), pluginManager.idForPath(pluginZip2.unzippedPath()));
  60. }
  61. }