|
|
|
@ -15,21 +15,18 @@
|
|
|
|
|
*/ |
|
|
|
|
package ro.fortsoft.pf4j; |
|
|
|
|
|
|
|
|
|
import org.junit.Rule; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.rules.TemporaryFolder; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import org.junit.After; |
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Rule; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.rules.TemporaryFolder; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
@ -40,30 +37,13 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
@Rule |
|
|
|
|
public TemporaryFolder testFolder = new TemporaryFolder(); |
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setUp() throws IOException { |
|
|
|
|
File file = testFolder.newFile("disabled.txt"); |
|
|
|
|
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { |
|
|
|
|
writer.write("plugin-2\r\n"); |
|
|
|
|
} |
|
|
|
|
file.createNewFile(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setUpEnabled() throws IOException { |
|
|
|
|
File file = testFolder.newFile("enabled.txt"); |
|
|
|
|
file.createNewFile(); |
|
|
|
|
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { |
|
|
|
|
writer.write("plugin-1\r\n"); |
|
|
|
|
writer.write("plugin-2\r\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Test of isPluginDisabled method, of class DefaultPluginStatusProvider. |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testIsPluginDisabled() throws IOException { |
|
|
|
|
setUpEnabled(); |
|
|
|
|
createEnabledFile(); |
|
|
|
|
createDisabledFile(); |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertFalse(instance.isPluginDisabled("plugin-1")); |
|
|
|
@ -75,7 +55,8 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
* Test of isPluginDisabled method, of class DefaultPluginStatusProvider. |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testIsPluginDisabledWithEnableEmpty() { |
|
|
|
|
public void testIsPluginDisabledWithEnableEmpty() throws IOException { |
|
|
|
|
createDisabledFile(); |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertFalse(instance.isPluginDisabled("plugin-1")); |
|
|
|
@ -88,7 +69,8 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testDisablePlugin() throws IOException { |
|
|
|
|
setUpEnabled(); |
|
|
|
|
createEnabledFile(); |
|
|
|
|
createDisabledFile(); |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertTrue(instance.disablePlugin("plugin-1")); |
|
|
|
@ -101,7 +83,8 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
* Test of disablePlugin method, of class DefaultPluginStatusProvider. |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testDisablePluginWithEnableEmpty() { |
|
|
|
|
public void testDisablePluginWithEnableEmpty() throws IOException { |
|
|
|
|
createDisabledFile(); |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertTrue(instance.disablePlugin("plugin-1")); |
|
|
|
@ -115,7 +98,7 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testEnablePlugin() throws IOException { |
|
|
|
|
setUpEnabled(); |
|
|
|
|
createEnabledFile(); |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertTrue(instance.enablePlugin("plugin-2")); |
|
|
|
@ -137,4 +120,33 @@ public class DefaultPluginStatusProviderTest {
|
|
|
|
|
assertFalse(instance.isPluginDisabled("plugin-3")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Test of disablePlugin method without a disabled.txt file. |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void testDisablePluginWithoutDisabledFile() throws IOException { |
|
|
|
|
DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); |
|
|
|
|
|
|
|
|
|
assertFalse(instance.isPluginDisabled("plugin-1")); |
|
|
|
|
assertTrue(instance.disablePlugin("plugin-1")); |
|
|
|
|
assertTrue(instance.isPluginDisabled("plugin-1")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createDisabledFile() throws IOException { |
|
|
|
|
File file = testFolder.newFile("disabled.txt"); |
|
|
|
|
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { |
|
|
|
|
writer.write("plugin-2\r\n"); |
|
|
|
|
} |
|
|
|
|
file.createNewFile(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createEnabledFile() throws IOException { |
|
|
|
|
File file = testFolder.newFile("enabled.txt"); |
|
|
|
|
file.createNewFile(); |
|
|
|
|
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { |
|
|
|
|
writer.write("plugin-1\r\n"); |
|
|
|
|
writer.write("plugin-2\r\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|