summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2018-06-17 22:02:03 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2018-06-17 22:02:03 +0300
commitc421a3b4e02822d65252b868ecbef3d1a0b09fd8 (patch)
treed13f8c508f7183755ed5c1900919d76d198c65c8
parent0d5ba39ce17130ed3403e6852c53a5158fe7d03f (diff)
downloadpf4j-c421a3b4e02822d65252b868ecbef3d1a0b09fd8.tar.gz
pf4j-c421a3b4e02822d65252b868ecbef3d1a0b09fd8.zip
Formatting, rename fields refactoring, add comments
-rw-r--r--pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java16
-rw-r--r--pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java40
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java37
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java78
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java122
-rw-r--r--pf4j/src/test/java/org/pf4j/LoadPluginsTest.java36
-rw-r--r--pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java31
-rw-r--r--pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java37
8 files changed, 178 insertions, 219 deletions
diff --git a/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java b/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java
index bda50c6..ca85407 100644
--- a/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java
+++ b/pf4j/src/main/java/org/pf4j/DefaultPluginStatusProvider.java
@@ -25,6 +25,8 @@ import java.util.List;
/**
* The default implementation for {@link PluginStatusProvider}.
+ * The enabled plugins are read from {@code enabled.txt} file and
+ * the disabled plugins are read from {@code disabled.txt} file.
*
* @author Decebal Suiu
* @author Mário Franco
@@ -41,10 +43,6 @@ public class DefaultPluginStatusProvider implements PluginStatusProvider {
public DefaultPluginStatusProvider(Path pluginsRoot) {
this.pluginsRoot = pluginsRoot;
- initialize();
- }
-
- private void initialize() {
try {
// create a list with plugin identifiers that should be only accepted by this manager (whitelist from plugins/enabled.txt file)
enabledPlugins = FileUtils.readLines(pluginsRoot.resolve("enabled.txt"), true);
@@ -83,13 +81,13 @@ public class DefaultPluginStatusProvider implements PluginStatusProvider {
@Override
public boolean enablePlugin(String pluginId) {
- try {
- if (disabledPlugins.remove(pluginId)) {
+ if (disabledPlugins.remove(pluginId)) {
+ try {
FileUtils.writeLines(disabledPlugins, pluginsRoot.resolve("disabled.txt").toFile());
+ } catch (IOException e) {
+ log.error("Failed to enable plugin {}", pluginId, e);
+ return false;
}
- } catch (IOException e) {
- log.error("Failed to enable plugin {}", pluginId, e);
- return false;
}
return true;
diff --git a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
index 6cb876c..a30a4ff 100644
--- a/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
+++ b/pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
@@ -27,7 +27,8 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* @author Decebal Suiu
@@ -35,26 +36,26 @@ import static org.junit.Assert.*;
public class CompoundPluginDescriptorFinderTest {
@Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Test
public void add() {
- CompoundPluginDescriptorFinder instance = new CompoundPluginDescriptorFinder();
- assertEquals(0, instance.size());
+ CompoundPluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
+ assertEquals(0, descriptorFinder.size());
- instance.add(new PropertiesPluginDescriptorFinder());
- assertEquals(1, instance.size());
+ descriptorFinder.add(new PropertiesPluginDescriptorFinder());
+ assertEquals(1, descriptorFinder.size());
}
@Test
public void find() throws Exception {
- Path pluginPath = testFolder.newFolder("test-plugin-1").toPath();
+ Path pluginPath = pluginsFolder.newFolder("test-plugin-1").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), StandardCharsets.UTF_8);
- PluginDescriptorFinder instance = new CompoundPluginDescriptorFinder()
+ PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
.add(new PropertiesPluginDescriptorFinder());
- PluginDescriptor pluginDescriptor = instance.find(pluginPath);
+ PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginPath);
assertNotNull(pluginDescriptor);
assertEquals("test-plugin-1", pluginDescriptor.getPluginId());
assertEquals("0.0.1", pluginDescriptor.getVersion());
@@ -62,14 +63,14 @@ public class CompoundPluginDescriptorFinderTest {
@Test
public void findInJar() throws Exception {
- PluginDescriptorFinder instance = new CompoundPluginDescriptorFinder()
+ PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
.add(new PropertiesPluginDescriptorFinder());
- PluginZip pluginJar = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin")
+ PluginZip pluginJar = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3")
.build();
- PluginDescriptor pluginDescriptor = instance.find(pluginJar.path());
+ PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginJar.path());
assertNotNull(pluginDescriptor);
assertEquals("myPlugin", pluginJar.pluginId());
assertEquals("1.2.3", pluginJar.pluginVersion());
@@ -77,20 +78,21 @@ public class CompoundPluginDescriptorFinderTest {
@Test(expected = PluginException.class)
public void testNotFound() throws Exception {
- PluginDescriptorFinder instance = new CompoundPluginDescriptorFinder();
- instance.find(getPluginsRoot().resolve("test-plugin-3"));
+ PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
+ Path pluginsPath = pluginsFolder.getRoot().toPath();
+ descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
}
@Test
public void testSpaceCharacterInFileName() throws Exception {
- PluginDescriptorFinder instance = new PropertiesPluginDescriptorFinder();
- File jar = testFolder.newFile("my plugin-1.2.3.jar");
+ PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
+ File jar = pluginsFolder.newFile("my plugin-1.2.3.jar");
PluginZip pluginJar = new PluginZip.Builder(jar, "myPlugin")
.pluginVersion("1.2.3")
.build();
- PluginDescriptor pluginDescriptor = instance.find(pluginJar.path());
+ PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginJar.path());
assertNotNull(pluginDescriptor);
}
@@ -111,8 +113,4 @@ public class CompoundPluginDescriptorFinderTest {
return Arrays.asList(lines);
}
- private Path getPluginsRoot() {
- return testFolder.getRoot().toPath();
- }
-
}
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
index 6124a79..f105aa8 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
@@ -16,9 +16,9 @@
package org.pf4j;
import org.junit.Test;
+import org.pf4j.plugin.AnotherFailTestPlugin;
import org.pf4j.plugin.FailTestPlugin;
import org.pf4j.plugin.TestPlugin;
-import org.pf4j.plugin.AnotherFailTestPlugin;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull;
@@ -28,14 +28,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
- *
* @author Mario Franco
*/
public class DefaultPluginFactoryTest {
- /**
- * Test of create method, of class DefaultPluginFactory.
- */
@Test
public void testCreate() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
@@ -45,16 +41,13 @@ public class DefaultPluginFactoryTest {
when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
- DefaultPluginFactory instance = new DefaultPluginFactory();
+ PluginFactory pluginFactory = new DefaultPluginFactory();
- Plugin result = instance.create(pluginWrapper);
+ Plugin result = pluginFactory.create(pluginWrapper);
assertNotNull(result);
assertThat(result, instanceOf(TestPlugin.class));
}
- /**
- * Test of create method, of class DefaultPluginFactory.
- */
@Test
public void testCreateFail() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
@@ -64,15 +57,12 @@ public class DefaultPluginFactoryTest {
when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
- DefaultPluginFactory instance = new DefaultPluginFactory();
+ PluginFactory pluginFactory = new DefaultPluginFactory();
- Plugin result = instance.create(pluginWrapper);
- assertNull(result);
+ Plugin plugin = pluginFactory.create(pluginWrapper);
+ assertNull(plugin);
}
- /**
- * Test of create method, of class DefaultPluginFactory.
- */
@Test
public void testCreateFailNotFound() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
@@ -82,15 +72,12 @@ public class DefaultPluginFactoryTest {
when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
- DefaultPluginFactory instance = new DefaultPluginFactory();
+ PluginFactory pluginFactory = new DefaultPluginFactory();
- Plugin result = instance.create(pluginWrapper);
- assertNull(result);
+ Plugin plugin = pluginFactory.create(pluginWrapper);
+ assertNull(plugin);
}
- /**
- * Test of create method, of class DefaultPluginFactory.
- */
@Test
public void testCreateFailConstructor() {
PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
@@ -100,10 +87,10 @@ public class DefaultPluginFactoryTest {
when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
- DefaultPluginFactory instance = new DefaultPluginFactory();
+ PluginFactory pluginFactory = new DefaultPluginFactory();
- Plugin result = instance.create(pluginWrapper);
- assertNull(result);
+ Plugin plugin = pluginFactory.create(pluginWrapper);
+ assertNull(plugin);
}
}
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
index cb629d5..4f39f24 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
@@ -36,21 +36,25 @@ import static org.junit.Assert.assertTrue;
*/
public class DefaultPluginRepositoryTest {
+ private Path pluginsPath;
+
@Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Before
public void setUp() throws IOException {
- testFolder.newFolder("plugin-1");
+ pluginsPath = pluginsFolder.getRoot().toPath();
+
+ pluginsFolder.newFolder("plugin-1");
// Prove that we can delete a folder with a file inside
- Files.createFile(Paths.get(testFolder.getRoot().getAbsolutePath()).resolve("plugin-1").resolve("myfile"));
+ Files.createFile(Paths.get(pluginsFolder.getRoot().getAbsolutePath()).resolve("plugin-1").resolve("myfile"));
// Create a zip file for plugin-1 to test that it is deleted when plugin is deleted
- Files.createFile(Paths.get(testFolder.getRoot().getAbsolutePath()).resolve("plugin-1.zip"));
- testFolder.newFolder("plugin-2");
- testFolder.newFolder("plugin-3");
+ Files.createFile(Paths.get(pluginsFolder.getRoot().getAbsolutePath()).resolve("plugin-1.zip"));
+ pluginsFolder.newFolder("plugin-2");
+ pluginsFolder.newFolder("plugin-3");
// standard maven/gradle bin folder - these should be skipped in development mode because the cause errors
- testFolder.newFolder("target");
- testFolder.newFolder("build");
+ pluginsFolder.newFolder("target");
+ pluginsFolder.newFolder("build");
}
/**
@@ -58,33 +62,29 @@ public class DefaultPluginRepositoryTest {
*/
@Test
public void testGetPluginArchives() {
- Path pluginsRoot = getPluginsRoot();
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath, false);
- PluginRepository instance = new DefaultPluginRepository(pluginsRoot, false);
+ List<Path> pluginPaths = repository.getPluginPaths();
- List<Path> result = instance.getPluginPaths();
-
- assertEquals(5, result.size());
- assertPathExists(result, pluginsRoot.resolve("plugin-1"));
- assertPathExists(result, pluginsRoot.resolve("plugin-2"));
- assertPathExists(result, pluginsRoot.resolve("plugin-3"));
+ assertEquals(5, pluginPaths.size());
+ assertPathExists(pluginPaths, pluginsPath.resolve("plugin-1"));
+ assertPathExists(pluginPaths, pluginsPath.resolve("plugin-2"));
+ assertPathExists(pluginPaths, pluginsPath.resolve("plugin-3"));
// when not in development mode we will honor these folders
- assertPathExists(result, pluginsRoot.resolve("target"));
- assertPathExists(result, pluginsRoot.resolve("build"));
+ assertPathExists(pluginPaths, pluginsPath.resolve("target"));
+ assertPathExists(pluginPaths, pluginsPath.resolve("build"));
}
@Test
public void testGetPluginArchivesInDevelopmentMode() {
- Path pluginsRoot = getPluginsRoot();
-
- PluginRepository instance = new DefaultPluginRepository(pluginsRoot, true);
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath, true);
- List<Path> result = instance.getPluginPaths();
+ List<Path> pluginPaths = repository.getPluginPaths();
// target and build should be ignored
- assertEquals(3, result.size());
- assertPathDoesNotExists(result, pluginsRoot.resolve("target"));
- assertPathDoesNotExists(result, pluginsRoot.resolve("build"));
+ assertEquals(3, pluginPaths.size());
+ assertPathDoesNotExists(pluginPaths, pluginsPath.resolve("target"));
+ assertPathDoesNotExists(pluginPaths, pluginsPath.resolve("build"));
}
/**
@@ -92,22 +92,20 @@ public class DefaultPluginRepositoryTest {
*/
@Test
public void testDeletePluginPath() {
- Path pluginsRoot = getPluginsRoot();
+ PluginRepository repository = new DefaultPluginRepository(pluginsPath, false);
- PluginRepository instance = new DefaultPluginRepository(pluginsRoot, false);
+ 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(repository.deletePluginPath(pluginsPath.resolve("target")));
+ assertTrue(repository.deletePluginPath(pluginsPath.resolve("build")));
- assertTrue(Files.exists(pluginsRoot.resolve("plugin-1.zip")));
- assertTrue(instance.deletePluginPath(pluginsRoot.resolve("plugin-1")));
- assertFalse(Files.exists(pluginsRoot.resolve("plugin-1.zip")));
- assertTrue(instance.deletePluginPath(pluginsRoot.resolve("plugin-3")));
- assertFalse(instance.deletePluginPath(pluginsRoot.resolve("plugin-4")));
- assertTrue(instance.deletePluginPath(pluginsRoot.resolve("target")));
- assertTrue(instance.deletePluginPath(pluginsRoot.resolve("build")));
+ List<Path> pluginPaths = repository.getPluginPaths();
- List<Path> result = instance.getPluginPaths();
-
- assertEquals(1, result.size());
- assertEquals(pluginsRoot.relativize(result.get(0)).toString(), "plugin-2");
+ assertEquals(1, pluginPaths.size());
+ assertEquals(pluginsPath.relativize(pluginPaths.get(0)).toString(), "plugin-2");
}
private void assertPathExists(List<Path> paths, Path path) {
@@ -118,8 +116,4 @@ public class DefaultPluginRepositoryTest {
assertFalse("The directory must not contain the file " + path, paths.contains(path));
}
- private Path getPluginsRoot() {
- return testFolder.getRoot().toPath();
- }
-
}
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
index c0ab38e..b3f8d2b 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
@@ -15,6 +15,7 @@
*/
package org.pf4j;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -35,131 +36,110 @@ import static org.junit.Assert.assertTrue;
*/
public class DefaultPluginStatusProviderTest {
+ private Path pluginsPath;
+
@Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
+
+ @Before
+ public void setUp() {
+ pluginsPath = pluginsFolder.getRoot().toPath();
+ }
- /**
- * Test of isPluginDisabled method, of class DefaultPluginStatusProvider.
- */
@Test
public void testIsPluginDisabled() throws IOException {
createEnabledFile();
createDisabledFile();
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertFalse(instance.isPluginDisabled("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-2"));
- assertTrue(instance.isPluginDisabled("plugin-3"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-2"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of isPluginDisabled method, of class DefaultPluginStatusProvider.
- */
@Test
public void testIsPluginDisabledWithEnableEmpty() throws IOException {
createDisabledFile();
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertFalse(instance.isPluginDisabled("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-2"));
- assertFalse(instance.isPluginDisabled("plugin-3"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-2"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of disablePlugin method, of class DefaultPluginStatusProvider.
- */
@Test
public void testDisablePlugin() throws IOException {
createEnabledFile();
createDisabledFile();
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertTrue(instance.disablePlugin("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-2"));
- assertTrue(instance.isPluginDisabled("plugin-3"));
+ assertTrue(statusProvider.disablePlugin("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-2"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of disablePlugin method, of class DefaultPluginStatusProvider.
- */
@Test
public void testDisablePluginWithEnableEmpty() throws IOException {
createDisabledFile();
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertTrue(instance.disablePlugin("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-2"));
- assertFalse(instance.isPluginDisabled("plugin-3"));
+ assertTrue(statusProvider.disablePlugin("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-2"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of enablePlugin method, of class DefaultPluginStatusProvider.
- */
@Test
public void testEnablePlugin() throws IOException {
createEnabledFile();
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertTrue(instance.enablePlugin("plugin-2"));
- assertFalse(instance.isPluginDisabled("plugin-1"));
- assertFalse(instance.isPluginDisabled("plugin-2"));
- assertTrue(instance.isPluginDisabled("plugin-3"));
+ assertTrue(statusProvider.enablePlugin("plugin-2"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-2"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of enablePlugin method, of class DefaultPluginStatusProvider.
- */
@Test
public void testEnablePluginWithEnableEmpty() {
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertTrue(instance.enablePlugin("plugin-2"));
- assertFalse(instance.isPluginDisabled("plugin-1"));
- assertFalse(instance.isPluginDisabled("plugin-2"));
- assertFalse(instance.isPluginDisabled("plugin-3"));
+ assertTrue(statusProvider.enablePlugin("plugin-2"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-2"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-3"));
}
- /**
- * Test of disablePlugin method without a disabled.txt file.
- */
@Test
- public void testDisablePluginWithoutDisabledFile() throws IOException {
- PluginStatusProvider instance = new DefaultPluginStatusProvider(getPluginsRoot());
+ public void testDisablePluginWithoutDisabledFile() {
+ PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
- assertFalse(instance.isPluginDisabled("plugin-1"));
- assertTrue(instance.disablePlugin("plugin-1"));
- assertTrue(instance.isPluginDisabled("plugin-1"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertTrue(statusProvider.disablePlugin("plugin-1"));
+ assertTrue(statusProvider.isPluginDisabled("plugin-1"));
}
private void createDisabledFile() throws IOException {
- List<String> plugins = new ArrayList<>();
- plugins.add("plugin-2");
+ List<String> disabledPlugins = new ArrayList<>();
+ disabledPlugins.add("plugin-2");
- writeLines(plugins, "disabled.txt");
+ File disabledFile = pluginsFolder.newFile("disabled.txt");
+ FileUtils.writeLines(disabledPlugins, disabledFile);
}
private void createEnabledFile() throws IOException {
- List<String> plugins = new ArrayList<>();
- plugins.add("plugin-1");
- plugins.add("plugin-2");
-
- writeLines(plugins, "enabled.txt");
- }
-
- private void writeLines(List<String> lines, String fileName) throws IOException {
- File file = testFolder.newFile(fileName);
- FileUtils.writeLines(lines, file);
- }
+ List<String> enabledPlugins = new ArrayList<>();
+ enabledPlugins.add("plugin-1");
+ enabledPlugins.add("plugin-2");
- private Path getPluginsRoot() {
- return testFolder.getRoot().toPath();
+ File enabledFile = pluginsFolder.newFile("enabled.txt");
+ FileUtils.writeLines(enabledPlugins, enabledFile);
}
}
diff --git a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
index 98c33c0..cf7280f 100644
--- a/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
+++ b/pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
@@ -21,33 +21,37 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.pf4j.plugin.PluginZip;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class LoadPluginsTest {
- @Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
-
private DefaultPluginManager pluginManager;
+ @Rule
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
+
@Before
- public void setup() {
- pluginManager = new DefaultPluginManager(testFolder.getRoot().toPath());
+ public void setUp() {
+ pluginManager = new DefaultPluginManager(pluginsFolder.getRoot().toPath());
}
@Test
public void load() throws Exception {
- PluginZip pluginZip = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
+ PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
assertTrue(Files.exists(pluginZip.path()));
assertEquals(0, pluginManager.getPlugins().size());
pluginManager.loadPlugins();
+
assertTrue(Files.exists(pluginZip.path()));
assertTrue(Files.exists(pluginZip.unzippedPath()));
assertEquals(1, pluginManager.getPlugins().size());
@@ -61,7 +65,7 @@ public class LoadPluginsTest {
@Test(expected = PluginAlreadyLoadedException.class)
public void loadTwiceFails() throws Exception {
- PluginZip pluginZip = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
+ PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
@@ -71,7 +75,7 @@ public class LoadPluginsTest {
@Test
public void loadUnloadLoad() throws Exception {
- PluginZip pluginZip = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
+ PluginZip pluginZip = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
@@ -88,7 +92,7 @@ public class LoadPluginsTest {
@Test
public void upgrade() throws Exception {
- new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
+ new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
@@ -98,7 +102,7 @@ public class LoadPluginsTest {
assertEquals(1, pluginManager.getPlugins().size());
assertEquals(1, pluginManager.getStartedPlugins().size());
- PluginZip pluginZip2 = new PluginZip.Builder(testFolder.newFile("my-plugin-2.0.0.ZIP"), "myPlugin")
+ PluginZip pluginZip2 = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-2.0.0.ZIP"), "myPlugin")
.pluginVersion("2.0.0")
.build();
@@ -114,12 +118,12 @@ public class LoadPluginsTest {
@Test
public void getRoot() {
- assertEquals(testFolder.getRoot().toPath(), pluginManager.getPluginsRoot());
+ assertEquals(pluginsFolder.getRoot().toPath(), pluginManager.getPluginsRoot());
}
@Test
public void notAPlugin() throws Exception {
- testFolder.newFile("not-a-zip");
+ pluginsFolder.newFile("not-a-zip");
pluginManager.loadPlugins();
@@ -128,11 +132,11 @@ public class LoadPluginsTest {
@Test
public void deletePlugin() throws Exception {
- PluginZip pluginZip1 = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
+ PluginZip pluginZip1 = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.zip"), "myPlugin")
.pluginVersion("1.2.3")
.build();
- PluginZip pluginZip3 = new PluginZip.Builder(testFolder.newFile("other-3.0.0.Zip"), "other")
+ PluginZip pluginZip3 = new PluginZip.Builder(pluginsFolder.newFile("other-3.0.0.Zip"), "other")
.pluginVersion("3.0.0")
.build();
diff --git a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
index 863b01c..bc4eb5f 100644
--- a/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
+++ b/pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
@@ -36,37 +36,40 @@ import static org.junit.Assert.*;
public class ManifestPluginDescriptorFinderTest {
private VersionManager versionManager;
+ private Path pluginsPath;
@Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Before
public void setUp() throws IOException {
+ pluginsPath = pluginsFolder.getRoot().toPath();
+
Charset charset = Charset.forName("UTF-8");
- Path pluginPath = testFolder.newFolder("test-plugin-1", "classes", "META-INF").toPath();
+ Path pluginPath = pluginsFolder.newFolder("test-plugin-1", "classes", "META-INF").toPath();
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin1Manifest(), charset);
- pluginPath = testFolder.newFolder("test-plugin-2", "classes", "META-INF").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-2", "classes", "META-INF").toPath();
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin2Manifest(), charset);
// empty plugin
- testFolder.newFolder("test-plugin-3");
+ pluginsFolder.newFolder("test-plugin-3");
// no plugin class
- pluginPath = testFolder.newFolder("test-plugin-4", "classes", "META-INF").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-4", "classes", "META-INF").toPath();
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin4Manifest(), charset);
// no plugin version
- pluginPath = testFolder.newFolder("test-plugin-5", "classes", "META-INF").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-5", "classes", "META-INF").toPath();
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin5Manifest(), charset);
// no plugin id
- pluginPath = testFolder.newFolder("test-plugin-6", "classes", "META-INF").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-6", "classes", "META-INF").toPath();
Files.write(pluginPath.resolve("extensions.idx"), "org.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes());
Files.write(pluginPath.resolve("MANIFEST.MF"), getPlugin6Manifest(), charset);
@@ -78,10 +81,10 @@ public class ManifestPluginDescriptorFinderTest {
*/
@Test
public void testFind() throws Exception {
- PluginDescriptorFinder instance = new ManifestPluginDescriptorFinder();
+ PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder();
- PluginDescriptor plugin1 = instance.find(getPluginsRoot().resolve("test-plugin-1"));
- PluginDescriptor plugin2 = instance.find(getPluginsRoot().resolve("test-plugin-2"));
+ PluginDescriptor plugin1 = descriptorFinder.find(pluginsPath.resolve("test-plugin-1"));
+ PluginDescriptor plugin2 = descriptorFinder.find(pluginsPath.resolve("test-plugin-2"));
assertEquals("test-plugin-1", plugin1.getPluginId());
assertEquals("Test Plugin 1", plugin1.getPluginDescription());
@@ -109,8 +112,8 @@ public class ManifestPluginDescriptorFinderTest {
*/
@Test(expected = PluginException.class)
public void testFindNotFound() throws Exception {
- PluginDescriptorFinder instance = new ManifestPluginDescriptorFinder();
- instance.find(getPluginsRoot().resolve("test-plugin-3"));
+ PluginDescriptorFinder descriptorFinder = new ManifestPluginDescriptorFinder();
+ descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
}
private List<String> getPlugin1Manifest() {
@@ -229,8 +232,4 @@ public class ManifestPluginDescriptorFinderTest {
return Arrays.asList(lines);
}
- private Path getPluginsRoot() {
- return testFolder.getRoot().toPath();
- }
-
}
diff --git a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
index c776620..377d5ca 100644
--- a/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
+++ b/pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
@@ -33,33 +33,36 @@ import static org.junit.Assert.*;
public class PropertiesPluginDescriptorFinderTest {
private VersionManager versionManager;
+ private Path pluginsPath;
@Rule
- public TemporaryFolder testFolder = new TemporaryFolder();
+ public TemporaryFolder pluginsFolder = new TemporaryFolder();
@Before
public void setUp() throws IOException {
+ pluginsPath = pluginsFolder.getRoot().toPath();
+
Charset charset = Charset.forName("UTF-8");
- Path pluginPath = testFolder.newFolder("test-plugin-1").toPath();
+ Path pluginPath = pluginsFolder.newFolder("test-plugin-1").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin1Properties(), charset);
- pluginPath = testFolder.newFolder("test-plugin-2").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-2").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin2Properties(), charset);
// empty plugin
- testFolder.newFolder("test-plugin-3");
+ pluginsFolder.newFolder("test-plugin-3");
// no plugin class
- pluginPath = testFolder.newFolder("test-plugin-4").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-4").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin4Properties(), charset);
// no plugin version
- pluginPath = testFolder.newFolder("test-plugin-5").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-5").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin5Properties(), charset);
// no plugin id
- pluginPath = testFolder.newFolder("test-plugin-6").toPath();
+ pluginPath = pluginsFolder.newFolder("test-plugin-6").toPath();
Files.write(pluginPath.resolve("plugin.properties"), getPlugin6Properties(), charset);
versionManager = new DefaultVersionManager();
@@ -67,10 +70,10 @@ public class PropertiesPluginDescriptorFinderTest {
@Test
public void testFind() throws Exception {
- PluginDescriptorFinder instance = new PropertiesPluginDescriptorFinder();
+ PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
- PluginDescriptor plugin1 = instance.find(getPluginsRoot().resolve("test-plugin-1"));
- PluginDescriptor plugin2 = instance.find(getPluginsRoot().resolve("test-plugin-2"));
+ PluginDescriptor plugin1 = descriptorFinder.find(pluginsPath.resolve("test-plugin-1"));
+ PluginDescriptor plugin2 = descriptorFinder.find(pluginsPath.resolve("test-plugin-2"));
assertEquals("test-plugin-1", plugin1.getPluginId());
assertEquals("Test Plugin 1", plugin1.getPluginDescription());
@@ -98,20 +101,20 @@ public class PropertiesPluginDescriptorFinderTest {
@Test(expected = PluginException.class)
public void testNotFound() throws Exception {
- PluginDescriptorFinder instance = new PropertiesPluginDescriptorFinder();
- instance.find(getPluginsRoot().resolve("test-plugin-3"));
+ PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
+ descriptorFinder.find(pluginsPath.resolve("test-plugin-3"));
}
@Test
public void findInJar() throws Exception {
- PluginZip pluginJar = new PluginZip.Builder(testFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin")
+ PluginZip pluginJar = new PluginZip.Builder(pluginsFolder.newFile("my-plugin-1.2.3.jar"), "myPlugin")
.pluginVersion("1.2.3")
.build();
assertTrue(Files.exists(pluginJar.path()));
- PluginDescriptorFinder instance = new PropertiesPluginDescriptorFinder();
- PluginDescriptor pluginDescriptor = instance.find(pluginJar.path());
+ PluginDescriptorFinder descriptorFinder = new PropertiesPluginDescriptorFinder();
+ PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginJar.path());
assertNotNull(pluginDescriptor);
assertEquals("myPlugin", pluginJar.pluginId());
assertEquals("1.2.3", pluginJar.pluginVersion());
@@ -190,8 +193,4 @@ public class PropertiesPluginDescriptorFinderTest {
return Arrays.asList(lines);
}
- private Path getPluginsRoot() {
- return testFolder.getRoot().toPath();
- }
-
}