From c1f799cce8aa7e6ddee3385f6ff7dda8488f7553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 14:17:17 +0100 Subject: [PATCH 1/7] Added one more fail test to DefaultPluginFactory --- .../pf4j/DefaultPluginFactoryTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java index 203aa02..e32b4dc 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java @@ -72,6 +72,24 @@ public class DefaultPluginFactoryTest { assertNull(result); } + /** + * Test of create method, of class DefaultPluginFactory. + */ + @Test + public void testCreateFailNotFound() { + PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class); + when(pluginDescriptor.getPluginClass()).thenReturn("ro.fortsoft.pf4j.plugin.NotFoundTestPlugin"); + + PluginWrapper pluginWrapper = mock(PluginWrapper.class); + when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor); + when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader()); + + DefaultPluginFactory instance = new DefaultPluginFactory(); + + Plugin result = instance.create(pluginWrapper); + assertNull(result); + } + /** * Test of create method, of class DefaultPluginFactory. */ From d4ac8c023b6b1ceb1b36d7524abfd74253c975a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 14:26:57 +0100 Subject: [PATCH 2/7] Added one more fail test to DefaultExtensionFactory --- .../pf4j/DefaultExtensionFactoryTest.java | 11 ++++++++ .../pf4j/plugin/FailTestExtension.java | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestExtension.java diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java index 506a393..552699e 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java @@ -18,6 +18,7 @@ package ro.fortsoft.pf4j; import org.junit.After; import org.junit.Before; import org.junit.Test; +import ro.fortsoft.pf4j.plugin.FailTestExtension; import ro.fortsoft.pf4j.plugin.TestExtension; import static org.junit.Assert.*; @@ -38,4 +39,14 @@ public class DefaultExtensionFactoryTest { assertNotNull(result); } + /** + * Test of create method, of class DefaultExtensionFactory. + */ + @Test + public void testCreateFailConstructor() { + DefaultExtensionFactory instance = new DefaultExtensionFactory(); + Object result = instance.create(FailTestExtension.class); + assertNull(result); + } + } diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestExtension.java b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestExtension.java new file mode 100644 index 0000000..4bc6110 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestExtension.java @@ -0,0 +1,28 @@ +/* + * Copyright 2015 Decebal Suiu + * + * 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.plugin; + +import ro.fortsoft.pf4j.ExtensionPoint; + +/** + * + * @author Mario Franco + */ +public class FailTestExtension implements ExtensionPoint { + + public FailTestExtension(String name) { + } +} From aa35da32f675302bb0bafcdd4d57af3c6882d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 15:46:54 +0100 Subject: [PATCH 3/7] Added ManifestPluginDescriptorFinder tests --- .../ManifestPluginDescriptorFinderTest.java | 85 +++++++++++++++++++ .../classes/META-INF/MANIFEST.MF | 18 ++++ .../classes/META-INF/MANIFEST.MF | 16 ++++ .../test/resources/test-plugin-3/empty.txt | 0 4 files changed, 119 insertions(+) create mode 100644 pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java create mode 100644 pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF create mode 100644 pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF create mode 100644 pf4j/src/test/resources/test-plugin-3/empty.txt diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java new file mode 100644 index 0000000..2007ba0 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2015 Decebal Suiu + * + * 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 com.github.zafarkhaja.semver.Version; +import java.io.File; +import java.net.URL; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + * @author Mario Franco + */ +public class ManifestPluginDescriptorFinderTest { + + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of find method, of class ManifestPluginDescriptorFinder. + */ + @Test + public void testFind() throws Exception { + ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + URL url = getClass().getResource("/test-plugin-1"); + PluginDescriptor plugin1 = instance.find(new File(url.getPath())); + url = getClass().getResource("/test-plugin-2"); + PluginDescriptor plugin2 = instance.find(new File(url.getPath())); + + assertEquals("test-plugin-1", plugin1.getPluginId()); + assertEquals("Test Plugin 1", plugin1.getPluginDescription()); + assertEquals("ro.fortsoft.pf4j.plugin.TestPlugin", plugin1.getPluginClass()); + assertEquals(Version.valueOf("0.0.1"), plugin1.getVersion()); + assertEquals("Decebal Suiu", plugin1.getProvider()); + assertEquals(2, plugin1.getDependencies().size()); + assertEquals("test-plugin-2", plugin1.getDependencies().get(0).getPluginId()); + assertEquals("test-plugin-3", plugin1.getDependencies().get(1).getPluginId()); + assertEquals("~1.0", plugin1.getDependencies().get(1).getPluginVersionSupport()); + assertTrue(plugin1.getRequires().interpret(Version.valueOf("1.0.0"))); + + assertEquals("test-plugin-2", plugin2.getPluginId()); + assertEquals("", plugin2.getPluginDescription()); + assertEquals("ro.fortsoft.pf4j.plugin.TestPlugin", plugin2.getPluginClass()); + assertEquals(Version.valueOf("0.0.1"), plugin2.getVersion()); + assertEquals("Decebal Suiu", plugin2.getProvider()); + assertEquals(0, plugin2.getDependencies().size()); + assertTrue(plugin2.getRequires().interpret(Version.valueOf("1.0.0"))); + } + + /** + * Test of find method, of class ManifestPluginDescriptorFinder. + */ + @Test(expected=PluginException.class) + public void testFindNotFound() throws Exception { + + ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + URL url = getClass().getResource("/test-plugin-3"); + PluginDescriptor result = instance.find(new File(url.getPath())); + } + +} diff --git a/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b5e48da --- /dev/null +++ b/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Implementation-Title: Test Plugin #1 +Implementation-Version: 0.10.0-SNAPSHOT +Archiver-Version: Plexus Archiver +Built-By: Mario Franco +Specification-Title: Test Plugin #1 +Implementation-Vendor-Id: ro.fortsoft.pf4j.demo +Plugin-Version: 0.0.1 +Plugin-Id: test-plugin-1 +Plugin-Description: Test Plugin 1 +Plugin-Provider: Decebal Suiu +Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin +Plugin-Dependencies: test-plugin-2,test-plugin-3@~1.0 +Plugin-Requires: * +Created-By: Apache Maven 3.0.5 +Build-Jdk: 1.8.0_45 +Specification-Version: 0.10.0-SNAPSHOT + diff --git a/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4cca6ac --- /dev/null +++ b/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Plugin-Dependencies: +Implementation-Title: Test Plugin #2 +Implementation-Version: 0.10.0-SNAPSHOT +Archiver-Version: Plexus Archiver +Built-By: Mario Franco +Specification-Title: Test Plugin #2 +Implementation-Vendor-Id: ro.fortsoft.pf4j.demo +Plugin-Version: 0.0.1 +Plugin-Id: test-plugin-2 +Plugin-Provider: Decebal Suiu +Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin +Created-By: Apache Maven 3.0.5 +Build-Jdk: 1.8.0_45 +Specification-Version: 0.10.0-SNAPSHOT + diff --git a/pf4j/src/test/resources/test-plugin-3/empty.txt b/pf4j/src/test/resources/test-plugin-3/empty.txt new file mode 100644 index 0000000..e69de29 From 13ace71e16d865d620177dc176cafa5ced28e67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 15:55:48 +0100 Subject: [PATCH 4/7] Added more fail tests --- .../ManifestPluginDescriptorFinderTest.java | 27 ++++++++++++++++--- .../classes/META-INF/MANIFEST.MF | 14 ++++++++++ .../classes/META-INF/MANIFEST.MF | 14 ++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF create mode 100644 pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java index 2007ba0..10109d4 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -31,7 +31,6 @@ import static org.junit.Assert.assertTrue; */ public class ManifestPluginDescriptorFinderTest { - @Before public void setUp() { } @@ -45,7 +44,7 @@ public class ManifestPluginDescriptorFinderTest { */ @Test public void testFind() throws Exception { - ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + DefaultPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); URL url = getClass().getResource("/test-plugin-1"); PluginDescriptor plugin1 = instance.find(new File(url.getPath())); url = getClass().getResource("/test-plugin-2"); @@ -74,7 +73,7 @@ public class ManifestPluginDescriptorFinderTest { /** * Test of find method, of class ManifestPluginDescriptorFinder. */ - @Test(expected=PluginException.class) + @Test(expected = PluginException.class) public void testFindNotFound() throws Exception { ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); @@ -82,4 +81,26 @@ public class ManifestPluginDescriptorFinderTest { PluginDescriptor result = instance.find(new File(url.getPath())); } + /** + * Test of find method, of class ManifestPluginDescriptorFinder. + */ + @Test(expected = PluginException.class) + public void testFindMissingPluginClass() throws Exception { + + ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + URL url = getClass().getResource("/test-plugin-4"); + PluginDescriptor result = instance.find(new File(url.getPath())); + } + + /** + * Test of find method, of class ManifestPluginDescriptorFinder. + */ + @Test(expected = PluginException.class) + public void testFindMissingPluginVersion() throws Exception { + + ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + URL url = getClass().getResource("/test-plugin-5"); + PluginDescriptor result = instance.find(new File(url.getPath())); + } + } diff --git a/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..95d8b81 --- /dev/null +++ b/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Implementation-Title: Test Plugin #2 +Implementation-Version: 0.10.0-SNAPSHOT +Archiver-Version: Plexus Archiver +Built-By: Mario Franco +Specification-Title: Test Plugin #2 +Implementation-Vendor-Id: ro.fortsoft.pf4j.demo +Plugin-Version: 0.0.1 +Plugin-Id: test-plugin-2 +Plugin-Provider: Decebal Suiu +Created-By: Apache Maven 3.0.5 +Build-Jdk: 1.8.0_45 +Specification-Version: 0.10.0-SNAPSHOT + diff --git a/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9ab8968 --- /dev/null +++ b/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Implementation-Title: Test Plugin #2 +Implementation-Version: 0.10.0-SNAPSHOT +Archiver-Version: Plexus Archiver +Built-By: Mario Franco +Specification-Title: Test Plugin #2 +Implementation-Vendor-Id: ro.fortsoft.pf4j.demo +Plugin-Id: test-plugin-2 +Plugin-Provider: Decebal Suiu +Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin +Created-By: Apache Maven 3.0.5 +Build-Jdk: 1.8.0_45 +Specification-Version: 0.10.0-SNAPSHOT + From b714dfe676a8c2ba90bb54a02897d8fbc02fe578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 16:00:24 +0100 Subject: [PATCH 5/7] Added fail on missing plugin id --- .../pf4j/ManifestPluginDescriptorFinderTest.java | 11 +++++++++++ .../test-plugin-6/classes/META-INF/MANIFEST.MF | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java index 10109d4..5038f66 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -81,6 +81,17 @@ public class ManifestPluginDescriptorFinderTest { PluginDescriptor result = instance.find(new File(url.getPath())); } + /** + * Test of find method, of class ManifestPluginDescriptorFinder. + */ + @Test(expected = PluginException.class) + public void testFindMissingPluginId() throws Exception { + + ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); + URL url = getClass().getResource("/test-plugin-6"); + PluginDescriptor result = instance.find(new File(url.getPath())); + } + /** * Test of find method, of class ManifestPluginDescriptorFinder. */ diff --git a/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b271753 --- /dev/null +++ b/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Implementation-Title: Test Plugin #2 +Implementation-Version: 0.10.0-SNAPSHOT +Archiver-Version: Plexus Archiver +Built-By: Mario Franco +Specification-Title: Test Plugin #2 +Implementation-Vendor-Id: ro.fortsoft.pf4j.demo +Plugin-Provider: Decebal Suiu +Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin +Created-By: Apache Maven 3.0.5 +Build-Jdk: 1.8.0_45 +Specification-Version: 0.10.0-SNAPSHOT + From a1bf455af29046a00a5ee979c7ec236448adc978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Tue, 21 Jul 2015 16:17:23 +0100 Subject: [PATCH 6/7] Added a few more --- .../ro/fortsoft/pf4j/PluginDependency.java | 6 ++- .../ManifestPluginDescriptorFinderTest.java | 10 ---- .../fortsoft/pf4j/PluginDependencyTest.java | 49 +++++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 pf4j/src/test/java/ro/fortsoft/pf4j/PluginDependencyTest.java diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java index 2d1887e..d6a2032 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDependency.java @@ -20,7 +20,7 @@ import com.github.zafarkhaja.semver.Version; public class PluginDependency { private String pluginId; - private String pluginVersionSupport; + private String pluginVersionSupport = "*"; public PluginDependency(String dependency) { int index = dependency.indexOf('@'); @@ -29,7 +29,9 @@ public class PluginDependency { } else { this.pluginId = dependency.substring(0, index); - this.pluginVersionSupport = dependency.substring(index + 1); + if (dependency.length() > index + 1) { + this.pluginVersionSupport = dependency.substring(index + 1); + } } } diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java index 5038f66..459d123 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -18,8 +18,6 @@ package ro.fortsoft.pf4j; import com.github.zafarkhaja.semver.Version; import java.io.File; import java.net.URL; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -31,14 +29,6 @@ import static org.junit.Assert.assertTrue; */ public class ManifestPluginDescriptorFinderTest { - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - /** * Test of find method, of class ManifestPluginDescriptorFinder. */ diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/PluginDependencyTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/PluginDependencyTest.java new file mode 100644 index 0000000..c8bc63b --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/PluginDependencyTest.java @@ -0,0 +1,49 @@ +/* + * 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 org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * + * @author Mario Franco + */ +public class PluginDependencyTest { + + /** + * Test of getPluginId method, of class PluginDependency. + */ + @Test + public void testPluginDependecy() { + PluginDependency instance = new PluginDependency("test"); + assertEquals("test", instance.getPluginId()); + assertEquals("*", instance.getPluginVersionSupport()); + + instance = new PluginDependency("test@"); + assertEquals("test", instance.getPluginId()); + assertEquals("*", instance.getPluginVersionSupport()); + + instance = new PluginDependency("test@1.0"); + assertEquals("test", instance.getPluginId()); + assertEquals("1.0", instance.getPluginVersionSupport()); + assertEquals("PluginDependency [pluginId=test, pluginVersionSupport=1.0]", instance.toString()); + } + + + +} From b368a786b0490183d0dfd8779e3d0ecbd72f51c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Franco?= Date: Wed, 9 Sep 2015 12:00:01 +0100 Subject: [PATCH 7/7] Generate Manifest content for testing --- .../pf4j/DefaultPluginFactoryTest.java | 2 - .../ManifestPluginDescriptorFinderTest.java | 179 ++++++++++++++++-- .../classes/META-INF/MANIFEST.MF | 18 -- .../classes/META-INF/MANIFEST.MF | 16 -- .../test/resources/test-plugin-3/empty.txt | 0 .../classes/META-INF/MANIFEST.MF | 14 -- .../classes/META-INF/MANIFEST.MF | 14 -- .../classes/META-INF/MANIFEST.MF | 13 -- 8 files changed, 163 insertions(+), 93 deletions(-) delete mode 100644 pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF delete mode 100644 pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF delete mode 100644 pf4j/src/test/resources/test-plugin-3/empty.txt delete mode 100644 pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF delete mode 100644 pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF delete mode 100644 pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java index e32b4dc..0c0009b 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java @@ -15,8 +15,6 @@ */ package ro.fortsoft.pf4j; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import ro.fortsoft.pf4j.plugin.AnotherFailTestPlugin; import ro.fortsoft.pf4j.plugin.FailTestPlugin; diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java index 459d123..593c126 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -17,8 +17,16 @@ package ro.fortsoft.pf4j; import com.github.zafarkhaja.semver.Version; import java.io.File; -import java.net.URL; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -29,16 +37,50 @@ import static org.junit.Assert.assertTrue; */ public class ManifestPluginDescriptorFinderTest { + @Rule + public TemporaryFolder testFolder = new TemporaryFolder(); + + @Before + public void setUp() throws IOException { + Charset charset = Charset.forName("UTF-8"); + + File plugin = testFolder.newFolder("test-plugin-1", "classes", "META-INF"); + Files.write(Paths.get(plugin.getPath(), "extensions.idx"), "ro.fortsoft.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); + Files.write(Paths.get(plugin.getPath(), "MANIFEST.MF"), getPlugin1Manifest(), charset); + + plugin = testFolder.newFolder("test-plugin-2", "classes", "META-INF"); + Files.write(Paths.get(plugin.getPath(), "extensions.idx"), "ro.fortsoft.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); + Files.write(Paths.get(plugin.getPath(), "MANIFEST.MF"), getPlugin2Manifest(), charset); + + // Empty Plugin + testFolder.newFolder("test-plugin-3"); + + // No Plugin Class + plugin = testFolder.newFolder("test-plugin-4", "classes", "META-INF"); + Files.write(Paths.get(plugin.getPath(), "extensions.idx"), "ro.fortsoft.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); + Files.write(Paths.get(plugin.getPath(), "MANIFEST.MF"), getPlugin4Manifest(), charset); + + // No Plugin Version + plugin = testFolder.newFolder("test-plugin-5", "classes", "META-INF"); + Files.write(Paths.get(plugin.getPath(), "extensions.idx"), "ro.fortsoft.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); + Files.write(Paths.get(plugin.getPath(), "MANIFEST.MF"), getPlugin5Manifest(), charset); + + // No Plugin Id + plugin = testFolder.newFolder("test-plugin-6", "classes", "META-INF"); + Files.write(Paths.get(plugin.getPath(), "extensions.idx"), "ro.fortsoft.pf4j.demo.hello.HelloPlugin$HelloGreeting".getBytes()); + Files.write(Paths.get(plugin.getPath(), "MANIFEST.MF"), getPlugin6Manifest(), charset); + } + /** * Test of find method, of class ManifestPluginDescriptorFinder. */ @Test public void testFind() throws Exception { DefaultPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); - URL url = getClass().getResource("/test-plugin-1"); - PluginDescriptor plugin1 = instance.find(new File(url.getPath())); - url = getClass().getResource("/test-plugin-2"); - PluginDescriptor plugin2 = instance.find(new File(url.getPath())); + + PluginDescriptor plugin1 = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-1").toFile()); + + PluginDescriptor plugin2 = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-2").toFile()); assertEquals("test-plugin-1", plugin1.getPluginId()); assertEquals("Test Plugin 1", plugin1.getPluginDescription()); @@ -67,41 +109,146 @@ public class ManifestPluginDescriptorFinderTest { public void testFindNotFound() throws Exception { ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); - URL url = getClass().getResource("/test-plugin-3"); - PluginDescriptor result = instance.find(new File(url.getPath())); + PluginDescriptor result = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-3").toFile()); } /** * Test of find method, of class ManifestPluginDescriptorFinder. */ @Test(expected = PluginException.class) - public void testFindMissingPluginId() throws Exception { + public void testFindMissingPluginClass() throws Exception { ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); - URL url = getClass().getResource("/test-plugin-6"); - PluginDescriptor result = instance.find(new File(url.getPath())); + PluginDescriptor result = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-4").toFile()); } /** * Test of find method, of class ManifestPluginDescriptorFinder. */ @Test(expected = PluginException.class) - public void testFindMissingPluginClass() throws Exception { + public void testFindMissingPluginVersion() throws Exception { ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); - URL url = getClass().getResource("/test-plugin-4"); - PluginDescriptor result = instance.find(new File(url.getPath())); + PluginDescriptor result = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-5").toFile()); } /** * Test of find method, of class ManifestPluginDescriptorFinder. */ @Test(expected = PluginException.class) - public void testFindMissingPluginVersion() throws Exception { + public void testFindMissingPluginId() throws Exception { ManifestPluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new PluginClasspath()); - URL url = getClass().getResource("/test-plugin-5"); - PluginDescriptor result = instance.find(new File(url.getPath())); + PluginDescriptor result = instance.find(Paths.get(testFolder.getRoot().getPath(),"test-plugin-6").toFile()); + } + + private List getPlugin1Manifest() { + + String[] lines = new String[]{"Manifest-Version: 1.0\n" + + "Implementation-Title: Test Plugin #1\n" + + "Implementation-Version: 0.10.0-SNAPSHOT\n" + + "Archiver-Version: Plexus Archiver\n" + + "Built-By: Mario Franco\n" + + "Specification-Title: Test Plugin #1\n" + + "Implementation-Vendor-Id: ro.fortsoft.pf4j.demo\n" + + "Plugin-Version: 0.0.1\n" + + "Plugin-Id: test-plugin-1\n" + + "Plugin-Description: Test Plugin 1\n" + + "Plugin-Provider: Decebal Suiu\n" + + "Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin\n" + + "Plugin-Dependencies: test-plugin-2,test-plugin-3@~1.0\n" + + "Plugin-Requires: *\n" + + "Created-By: Apache Maven 3.0.5\n" + + "Build-Jdk: 1.8.0_45\n" + + "Specification-Version: 0.10.0-SNAPSHOT\n" + + "\n" + + ""}; + + return Arrays.asList(lines); + } + + private List getPlugin2Manifest() { + + String[] lines = new String[]{"Manifest-Version: 1.0\n" + + "Plugin-Dependencies: \n" + + "Implementation-Title: Test Plugin #2\n" + + "Implementation-Version: 0.10.0-SNAPSHOT\n" + + "Archiver-Version: Plexus Archiver\n" + + "Built-By: Mario Franco\n" + + "Specification-Title: Test Plugin #2\n" + + "Implementation-Vendor-Id: ro.fortsoft.pf4j.demo\n" + + "Plugin-Version: 0.0.1\n" + + "Plugin-Id: test-plugin-2\n" + + "Plugin-Provider: Decebal Suiu\n" + + "Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin\n" + + "Created-By: Apache Maven 3.0.5\n" + + "Build-Jdk: 1.8.0_45\n" + + "Specification-Version: 0.10.0-SNAPSHOT\n" + + "\n" + + ""}; + + return Arrays.asList(lines); + } + + private List getPlugin4Manifest() { + + String[] lines = new String[]{"Manifest-Version: 1.0\n" + + "Implementation-Title: Test Plugin #4\n" + + "Implementation-Version: 0.10.0-SNAPSHOT\n" + + "Archiver-Version: Plexus Archiver\n" + + "Built-By: Mario Franco\n" + + "Specification-Title: Test Plugin #4\n" + + "Implementation-Vendor-Id: ro.fortsoft.pf4j.demo\n" + + "Plugin-Version: 0.0.1\n" + + "Plugin-Id: test-plugin-2\n" + + "Plugin-Provider: Decebal Suiu\n" + + "Created-By: Apache Maven 3.0.5\n" + + "Build-Jdk: 1.8.0_45\n" + + "Specification-Version: 0.10.0-SNAPSHOT\n" + + "\n" + + ""}; + + return Arrays.asList(lines); } + private List getPlugin5Manifest() { + + String[] lines = new String[]{"Manifest-Version: 1.0\n" + + "Implementation-Title: Test Plugin #5\n" + + "Implementation-Version: 0.10.0-SNAPSHOT\n" + + "Archiver-Version: Plexus Archiver\n" + + "Built-By: Mario Franco\n" + + "Specification-Title: Test Plugin #5\n" + + "Implementation-Vendor-Id: ro.fortsoft.pf4j.demo\n" + + "Plugin-Id: test-plugin-2\n" + + "Plugin-Provider: Decebal Suiu\n" + + "Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin\n" + + "Created-By: Apache Maven 3.0.5\n" + + "Build-Jdk: 1.8.0_45\n" + + "Specification-Version: 0.10.0-SNAPSHOT\n" + + "\n" + + ""}; + + return Arrays.asList(lines); + } + + private List getPlugin6Manifest() { + + String[] lines = new String[]{"Manifest-Version: 1.0\n" + + "Implementation-Title: Test Plugin #6\n" + + "Implementation-Version: 0.10.0-SNAPSHOT\n" + + "Archiver-Version: Plexus Archiver\n" + + "Built-By: Mario Franco\n" + + "Specification-Title: Test Plugin #6\n" + + "Implementation-Vendor-Id: ro.fortsoft.pf4j.demo\n" + + "Plugin-Provider: Decebal Suiu\n" + + "Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin\n" + + "Created-By: Apache Maven 3.0.5\n" + + "Build-Jdk: 1.8.0_45\n" + + "Specification-Version: 0.10.0-SNAPSHOT\n" + + "\n" + + ""}; + + return Arrays.asList(lines); + } } diff --git a/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF deleted file mode 100644 index b5e48da..0000000 --- a/pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Manifest-Version: 1.0 -Implementation-Title: Test Plugin #1 -Implementation-Version: 0.10.0-SNAPSHOT -Archiver-Version: Plexus Archiver -Built-By: Mario Franco -Specification-Title: Test Plugin #1 -Implementation-Vendor-Id: ro.fortsoft.pf4j.demo -Plugin-Version: 0.0.1 -Plugin-Id: test-plugin-1 -Plugin-Description: Test Plugin 1 -Plugin-Provider: Decebal Suiu -Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin -Plugin-Dependencies: test-plugin-2,test-plugin-3@~1.0 -Plugin-Requires: * -Created-By: Apache Maven 3.0.5 -Build-Jdk: 1.8.0_45 -Specification-Version: 0.10.0-SNAPSHOT - diff --git a/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF deleted file mode 100644 index 4cca6ac..0000000 --- a/pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,16 +0,0 @@ -Manifest-Version: 1.0 -Plugin-Dependencies: -Implementation-Title: Test Plugin #2 -Implementation-Version: 0.10.0-SNAPSHOT -Archiver-Version: Plexus Archiver -Built-By: Mario Franco -Specification-Title: Test Plugin #2 -Implementation-Vendor-Id: ro.fortsoft.pf4j.demo -Plugin-Version: 0.0.1 -Plugin-Id: test-plugin-2 -Plugin-Provider: Decebal Suiu -Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin -Created-By: Apache Maven 3.0.5 -Build-Jdk: 1.8.0_45 -Specification-Version: 0.10.0-SNAPSHOT - diff --git a/pf4j/src/test/resources/test-plugin-3/empty.txt b/pf4j/src/test/resources/test-plugin-3/empty.txt deleted file mode 100644 index e69de29..0000000 diff --git a/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF deleted file mode 100644 index 95d8b81..0000000 --- a/pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,14 +0,0 @@ -Manifest-Version: 1.0 -Implementation-Title: Test Plugin #2 -Implementation-Version: 0.10.0-SNAPSHOT -Archiver-Version: Plexus Archiver -Built-By: Mario Franco -Specification-Title: Test Plugin #2 -Implementation-Vendor-Id: ro.fortsoft.pf4j.demo -Plugin-Version: 0.0.1 -Plugin-Id: test-plugin-2 -Plugin-Provider: Decebal Suiu -Created-By: Apache Maven 3.0.5 -Build-Jdk: 1.8.0_45 -Specification-Version: 0.10.0-SNAPSHOT - diff --git a/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF deleted file mode 100644 index 9ab8968..0000000 --- a/pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,14 +0,0 @@ -Manifest-Version: 1.0 -Implementation-Title: Test Plugin #2 -Implementation-Version: 0.10.0-SNAPSHOT -Archiver-Version: Plexus Archiver -Built-By: Mario Franco -Specification-Title: Test Plugin #2 -Implementation-Vendor-Id: ro.fortsoft.pf4j.demo -Plugin-Id: test-plugin-2 -Plugin-Provider: Decebal Suiu -Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin -Created-By: Apache Maven 3.0.5 -Build-Jdk: 1.8.0_45 -Specification-Version: 0.10.0-SNAPSHOT - diff --git a/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF b/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF deleted file mode 100644 index b271753..0000000 --- a/pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,13 +0,0 @@ -Manifest-Version: 1.0 -Implementation-Title: Test Plugin #2 -Implementation-Version: 0.10.0-SNAPSHOT -Archiver-Version: Plexus Archiver -Built-By: Mario Franco -Specification-Title: Test Plugin #2 -Implementation-Vendor-Id: ro.fortsoft.pf4j.demo -Plugin-Provider: Decebal Suiu -Plugin-Class: ro.fortsoft.pf4j.plugin.TestPlugin -Created-By: Apache Maven 3.0.5 -Build-Jdk: 1.8.0_45 -Specification-Version: 0.10.0-SNAPSHOT -