aboutsummaryrefslogtreecommitdiffstats
path: root/pf4j/src/test
diff options
context:
space:
mode:
authorMário Franco <mario.ffranco@gmail.com>2015-07-20 19:02:46 +0100
committerMário Franco <mario.ffranco@gmail.com>2015-07-20 19:02:46 +0100
commit993a899501b90f971142df8917a7d3b85bb1c204 (patch)
tree9b521c749af79941c9db623cb5671b1167f891e0 /pf4j/src/test
parent46f2bfd1798d32af90ae41292f651d6072b8d4ec (diff)
downloadpf4j-993a899501b90f971142df8917a7d3b85bb1c204.tar.gz
pf4j-993a899501b90f971142df8917a7d3b85bb1c204.zip
Added Test for PluginStatusProvider
Diffstat (limited to 'pf4j/src/test')
-rw-r--r--pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java145
1 files changed, 145 insertions, 0 deletions
diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java
new file mode 100644
index 0000000..5da32fc
--- /dev/null
+++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2015 Mario Franco.
+ *
+ * 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 ro.fortsoft.pf4j;
+
+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.*;
+
+/**
+ *
+ * @author Mario Franco
+ */
+public class DefaultPluginStatusProviderTest {
+
+ @Rule
+ public TemporaryFolder testFolder = new TemporaryFolder();
+
+ public DefaultPluginStatusProviderTest() {
+ }
+
+ @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");
+ }
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of isPluginDisabled method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testIsPluginDisabled() throws IOException {
+ setUpEnabled();
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(false, instance.isPluginDisabled("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-2"));
+ assertEquals(true, instance.isPluginDisabled("plugin-3"));
+ }
+
+ /**
+ * Test of isPluginDisabled method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testIsPluginDisabledWithEnableEmpty() {
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(false, instance.isPluginDisabled("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-2"));
+ assertEquals(false, instance.isPluginDisabled("plugin-3"));
+ }
+
+ /**
+ * Test of disablePlugin method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testDisablePlugin() throws IOException {
+ setUpEnabled();
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(true, instance.disablePlugin("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-2"));
+ assertEquals(true, instance.isPluginDisabled("plugin-3"));
+ }
+
+ /**
+ * Test of disablePlugin method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testDisablePluginWithEnableEmpty() {
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(true, instance.disablePlugin("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-1"));
+ assertEquals(true, instance.isPluginDisabled("plugin-2"));
+ assertEquals(false, instance.isPluginDisabled("plugin-3"));
+ }
+
+ /**
+ * Test of enablePlugin method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testEnablePlugin() throws IOException {
+ setUpEnabled();
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(true, instance.enablePlugin("plugin-2"));
+ assertEquals(false, instance.isPluginDisabled("plugin-1"));
+ assertEquals(false, instance.isPluginDisabled("plugin-2"));
+ assertEquals(true, instance.isPluginDisabled("plugin-3"));
+ }
+
+ /**
+ * Test of enablePlugin method, of class DefaultPluginStatusProvider.
+ */
+ @Test
+ public void testEnablePluginWithEnableEmpty() {
+ DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot());
+
+ assertEquals(true, instance.enablePlugin("plugin-2"));
+ assertEquals(false, instance.isPluginDisabled("plugin-1"));
+ assertEquals(false, instance.isPluginDisabled("plugin-2"));
+ assertEquals(false, instance.isPluginDisabled("plugin-3"));
+ }
+
+}