aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src/test
diff options
context:
space:
mode:
authorrreich <rainer.reich@coremedia.com>2020-11-05 14:37:08 +0100
committerGitHub <noreply@github.com>2020-11-05 15:37:08 +0200
commitf6ede83be37a29b069a602fdf4b4864c16f2c3d2 (patch)
tree079e30e562d5f4a0f0f68fd2c87ec684b489bcdc /pf4j/src/test
parentc2d9998350b3a15ff7678c9053bca434463cf915 (diff)
downloadpf4j-f6ede83be37a29b069a602fdf4b4864c16f2c3d2.tar.gz
pf4j-f6ede83be37a29b069a602fdf4b4864c16f2c3d2.zip
Support multiple plugin root directories (#404)
Diffstat (limited to 'pf4j/src/test')
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java59
-rw-r--r--pf4j/src/test/java/org/pf4j/LoadPluginsFromMultipleRootsTest.java75
-rw-r--r--pf4j/src/test/java/org/pf4j/LoadPluginsTest.java6
3 files changed, 122 insertions, 18 deletions
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
index 3e31811..b8ffd7c 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
@@ -15,10 +15,11 @@
*/
package org.pf4j;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
import org.pf4j.plugin.PluginZip;
+import org.pf4j.util.FileUtils;
import java.io.IOException;
import java.nio.file.Files;
@@ -35,18 +36,40 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
public class DefaultPluginRepositoryTest {
- @TempDir
- Path pluginsPath;
+ Path pluginsPath1;
+ Path pluginsPath2;
@BeforeEach
public void setUp() throws IOException {
- Path plugin1Path = Files.createDirectory(pluginsPath.resolve("plugin-1"));
+ pluginsPath1 = Files.createTempDirectory("junit-pf4j-");
+ pluginsPath2 = Files.createTempDirectory("junit-pf4j-");
+ Path plugin1Path = Files.createDirectory(pluginsPath1.resolve("plugin-1"));
// Prove that we can delete a folder with a file inside
Files.createFile(plugin1Path.resolve("myfile"));
// Create a zip file for plugin-1 to test that it is deleted when plugin is deleted
- new PluginZip.Builder(pluginsPath.resolve("plugin-1.zip"), "plugin-1").pluginVersion("1.0").build();
- Files.createDirectory(pluginsPath.resolve("plugin-2"));
- Files.createDirectory(pluginsPath.resolve("plugin-3"));
+ new PluginZip.Builder(pluginsPath1.resolve("plugin-1.zip"), "plugin-1").pluginVersion("1.0").build();
+ Files.createDirectory(pluginsPath2.resolve("plugin-2"));
+ Files.createDirectory(pluginsPath2.resolve("plugin-3"));
+ }
+
+ @AfterEach
+ public void tearDown() throws IOException {
+ FileUtils.delete(pluginsPath1);
+ FileUtils.delete(pluginsPath2);
+ }
+
+ /**
+ * Test of {@link DefaultPluginRepository#getPluginPaths()} method.
+ */
+ @Test
+ public void testGetPluginArchivesFromSinglePath() {
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath2);
+
+ List<Path> pluginPaths = repository.getPluginPaths();
+
+ assertEquals(2, pluginPaths.size());
+ assertPathExists(pluginPaths, pluginsPath2.resolve("plugin-2"));
+ assertPathExists(pluginPaths, pluginsPath2.resolve("plugin-3"));
}
/**
@@ -54,14 +77,14 @@ public class DefaultPluginRepositoryTest {
*/
@Test
public void testGetPluginArchives() {
- PluginRepository repository = new DefaultPluginRepository(pluginsPath);
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
List<Path> pluginPaths = repository.getPluginPaths();
assertEquals(3, pluginPaths.size());
- assertPathExists(pluginPaths, pluginsPath.resolve("plugin-1"));
- assertPathExists(pluginPaths, pluginsPath.resolve("plugin-2"));
- assertPathExists(pluginPaths, pluginsPath.resolve("plugin-3"));
+ assertPathExists(pluginPaths, pluginsPath1.resolve("plugin-1"));
+ assertPathExists(pluginPaths, pluginsPath2.resolve("plugin-2"));
+ assertPathExists(pluginPaths, pluginsPath2.resolve("plugin-3"));
}
/**
@@ -69,18 +92,18 @@ public class DefaultPluginRepositoryTest {
*/
@Test
public void testDeletePluginPath() {
- PluginRepository repository = new DefaultPluginRepository(pluginsPath);
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
- assertTrue(Files.exists(pluginsPath.resolve("plugin-1.zip")));
- assertTrue(repository.deletePluginPath(pluginsPath.resolve("plugin-1")));
- assertFalse(Files.exists(pluginsPath.resolve("plugin-1.zip")));
- assertTrue(repository.deletePluginPath(pluginsPath.resolve("plugin-3")));
- assertFalse(repository.deletePluginPath(pluginsPath.resolve("plugin-4")));
+ assertTrue(Files.exists(pluginsPath1.resolve("plugin-1.zip")));
+ assertTrue(repository.deletePluginPath(pluginsPath1.resolve("plugin-1")));
+ assertFalse(Files.exists(pluginsPath1.resolve("plugin-1.zip")));
+ assertTrue(repository.deletePluginPath(pluginsPath2.resolve("plugin-3")));
+ assertFalse(repository.deletePluginPath(pluginsPath2.resolve("plugin-4")));
List<Path> pluginPaths = repository.getPluginPaths();
assertEquals(1, pluginPaths.size());
- assertEquals(pluginsPath.relativize(pluginPaths.get(0)).toString(), "plugin-2");
+ assertEquals(pluginsPath2.relativize(pluginPaths.get(0)).toString(), "plugin-2");
}
private void assertPathExists(List<Path> paths, Path path) {
diff --git a/pf4j/src/test/java/org/pf4j/LoadPluginsFromMultipleRootsTest.java b/pf4j/src/test/java/org/pf4j/LoadPluginsFromMultipleRootsTest.java
new file mode 100644
index 0000000..2117a62
--- /dev/null
+++ b/pf4j/src/test/java/org/pf4j/LoadPluginsFromMultipleRootsTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.pf4j;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.pf4j.plugin.PluginZip;
+import org.pf4j.util.FileUtils;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LoadPluginsFromMultipleRootsTest {
+
+ private DefaultPluginManager pluginManager;
+
+ Path pluginsPath1;
+ Path pluginsPath2;
+
+ @BeforeEach
+ public void setUp() throws IOException {
+ pluginsPath1 = Files.createTempDirectory("junit-pf4j-");
+ pluginsPath2 = Files.createTempDirectory("junit-pf4j-");
+ pluginManager = new DefaultPluginManager(pluginsPath1, pluginsPath2);
+ }
+
+ @AfterEach
+ public void tearDown() throws IOException {
+ FileUtils.delete(pluginsPath1);
+ FileUtils.delete(pluginsPath2);
+ }
+
+ @Test
+ public void load() throws Exception {
+ PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath1.resolve("my-plugin-1.2.3.zip"), "myPlugin")
+ .pluginVersion("1.2.3")
+ .build();
+
+ PluginZip pluginZip2 = new PluginZip.Builder(pluginsPath2.resolve("my-other-plugin-4.5.6.zip"), "myOtherPlugin")
+ .pluginVersion("4.5.6")
+ .build();
+
+ assertTrue(Files.exists(pluginZip1.path()));
+ assertEquals(0, pluginManager.getPlugins().size());
+
+ pluginManager.loadPlugins();
+
+ assertTrue(Files.exists(pluginZip1.path()));
+ assertTrue(Files.exists(pluginZip1.unzippedPath()));
+ assertTrue(Files.exists(pluginZip2.path()));
+ assertTrue(Files.exists(pluginZip2.unzippedPath()));
+ assertEquals(2, pluginManager.getPlugins().size());
+ assertEquals(pluginZip1.pluginId(), pluginManager.idForPath(pluginZip1.unzippedPath()));
+ assertEquals(pluginZip2.pluginId(), pluginManager.idForPath(pluginZip2.unzippedPath()));
+ }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
index e3dac02..ef2376b 100644
--- a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
+++ b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
@@ -23,6 +23,7 @@ import org.pf4j.plugin.PluginZip;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -201,6 +202,11 @@ public class LoadPluginsTest {
}
@Test
+ public void getRoots() {
+ assertEquals(Collections.singletonList(pluginsPath), pluginManager.getPluginsRoots());
+ }
+
+ @Test
public void notAPlugin() {
pluginsPath.resolve("not-a-zip");