aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src/test
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2019-08-05 22:28:14 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2019-08-05 22:28:14 +0300
commitf66859f71c0e9c043a14ca32f26b459de54317aa (patch)
tree2414aa36e640e2b97c7e16fb81f88ece12115c75 /pf4j/src/test
parentd7344b8d3c11d428184c00cc3b56af901d6be60b (diff)
downloadpf4j-f66859f71c0e9c043a14ca32f26b459de54317aa.tar.gz
pf4j-f66859f71c0e9c043a14ca32f26b459de54317aa.zip
Resolve #335
Diffstat (limited to 'pf4j/src/test')
-rw-r--r--pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java49
1 files changed, 43 insertions, 6 deletions
diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
index ca5b091..b0a0e8e 100644
--- a/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
+++ b/pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.io.TempDir;
import org.pf4j.util.FileUtils;
import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -74,31 +75,67 @@ public class DefaultPluginStatusProviderTest {
@Test
public void testDisablePluginWithEnableEmpty() throws Exception {
+ // scenario with "disabled.txt"
createDisabledFile();
- PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
+ DefaultPluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
statusProvider.disablePlugin("plugin-1");
assertTrue(statusProvider.isPluginDisabled("plugin-1"));
assertTrue(statusProvider.isPluginDisabled("plugin-2"));
assertFalse(statusProvider.isPluginDisabled("plugin-3"));
- List<String> disabledPlugins = FileUtils.readLines(pluginsPath.resolve("disabled.txt"), true);
+ List<String> disabledPlugins = FileUtils.readLines(statusProvider.getDisabledFilePath(), true);
assertTrue(disabledPlugins.contains("plugin-1"));
+
+ assertTrue(Files.notExists(statusProvider.getEnabledFilePath()));
+
+ // scenario with "enabled.txt"
+ Files.delete(statusProvider.getDisabledFilePath());
+ assertTrue(Files.notExists(statusProvider.getDisabledFilePath()));
+
+ createEnabledFile();
+
+ statusProvider = new DefaultPluginStatusProvider(pluginsPath);
+ statusProvider.disablePlugin("plugin-1");
+
+ assertTrue(statusProvider.isPluginDisabled("plugin-1"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-2"));
+
+ List<String> enabledPlugins = FileUtils.readLines(statusProvider.getEnabledFilePath(), true);
+ assertFalse(enabledPlugins.contains("plugin-1"));
}
@Test
public void testEnablePlugin() throws Exception {
+ // scenario with "enabled.txt"
createEnabledFile();
- PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
+ DefaultPluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
statusProvider.enablePlugin("plugin-2");
assertFalse(statusProvider.isPluginDisabled("plugin-1"));
assertFalse(statusProvider.isPluginDisabled("plugin-2"));
assertTrue(statusProvider.isPluginDisabled("plugin-3"));
- List<String> disabledPlugins = FileUtils.readLines(pluginsPath.resolve("disabled.txt"), true);
+ List<String> enabledPlugins = FileUtils.readLines(statusProvider.getEnabledFilePath(), true);
+ assertTrue(enabledPlugins.contains("plugin-2"));
+
+ assertTrue(Files.notExists(statusProvider.getDisabledFilePath()));
+
+ // scenario with "disabled.txt"
+ Files.delete(statusProvider.getEnabledFilePath());
+ assertTrue(Files.notExists(statusProvider.getEnabledFilePath()));
+
+ createDisabledFile();
+
+ statusProvider = new DefaultPluginStatusProvider(pluginsPath);
+ statusProvider.enablePlugin("plugin-2");
+
+ assertFalse(statusProvider.isPluginDisabled("plugin-1"));
+ assertFalse(statusProvider.isPluginDisabled("plugin-2"));
+
+ List<String> disabledPlugins = FileUtils.readLines(statusProvider.getDisabledFilePath(), true);
assertFalse(disabledPlugins.contains("plugin-2"));
}
@@ -126,7 +163,7 @@ public class DefaultPluginStatusProviderTest {
List<String> disabledPlugins = new ArrayList<>();
disabledPlugins.add("plugin-2");
- FileUtils.writeLines(disabledPlugins, pluginsPath.resolve("disabled.txt").toFile());
+ FileUtils.writeLines(disabledPlugins, DefaultPluginStatusProvider.getDisabledFilePath(pluginsPath));
}
private void createEnabledFile() throws IOException {
@@ -134,7 +171,7 @@ public class DefaultPluginStatusProviderTest {
enabledPlugins.add("plugin-1");
enabledPlugins.add("plugin-2");
- FileUtils.writeLines(enabledPlugins, pluginsPath.resolve("enabled.txt").toFile());
+ FileUtils.writeLines(enabledPlugins, DefaultPluginStatusProvider.getEnabledFilePath(pluginsPath));
}
}