diff options
author | Jan Høydahl <janhoy@users.noreply.github.com> | 2017-04-01 07:39:43 +0200 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2017-04-01 08:39:43 +0300 |
commit | 9f284467b3660298de7786be448f27577769b0b2 (patch) | |
tree | 92354424c2a62d6d23b67ab35a9660449034cedf /pf4j/src/test | |
parent | d7d1eec24e94857b0821add2c20674e503a256f8 (diff) | |
download | pf4j-9f284467b3660298de7786be448f27577769b0b2.tar.gz pf4j-9f284467b3660298de7786be448f27577769b0b2.zip |
Refactor validation of PluginDescriptors (#130)
Diffstat (limited to 'pf4j/src/test')
3 files changed, 60 insertions, 45 deletions
diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginManagerTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginManagerTest.java new file mode 100644 index 0000000..cde124b --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginManagerTest.java @@ -0,0 +1,60 @@ +/* + * 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 org.junit.Before; +import org.junit.Test; + +public class DefaultPluginManagerTest { + private PluginDescriptor pd1 = null; + private DefaultPluginManager pluginManager = new DefaultPluginManager(); + + @Before + public void init() { + pd1 = new PluginDescriptor(); + pd1.setPluginId("myPlugin"); + pd1.setPluginVersion(Version.valueOf("1.2.3")); + pd1.setPluginClass("foo"); + pd1.setPluginDescription("My plugin"); + pd1.setDependencies("bar, baz"); + pd1.setProvider("Me"); + pd1.setRequires("5.0.0"); + } + + @Test + public void validateOK() throws PluginException { + pluginManager.validatePluginDescriptor(pd1); + } + + @Test(expected = PluginException.class) + public void validateFailsOnId() throws PluginException { + pd1.setPluginId(""); + pluginManager.validatePluginDescriptor(pd1); + } + + @Test(expected = PluginException.class) + public void validateFailsOnVersion() throws PluginException { + pd1.setPluginVersion(null); + pluginManager.validatePluginDescriptor(pd1); + } + + @Test(expected = PluginException.class) + public void validateFailsOnClass() throws PluginException { + pd1.setPluginClass(null); + pluginManager.validatePluginDescriptor(pd1); + } +} diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java index 1ccaa22..b76b50e 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java @@ -111,33 +111,6 @@ public class ManifestPluginDescriptorFinderTest { instance.find(getPluginsRoot().resolve("test-plugin-3")); } - /** - * Test of {@link DefaultPluginDescriptorFinder#find(Path)} method. - */ - @Test(expected = PluginException.class) - public void testFindMissingPluginClass() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-4")); - } - - /** - * Test of {@link DefaultPluginDescriptorFinder#find(Path)} method. - */ - @Test(expected = PluginException.class) - public void testFindMissingPluginVersion() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-5")); - } - - /** - * Test of {@link DefaultPluginDescriptorFinder#find(Path)} method. - */ - @Test(expected = PluginException.class) - public void testFindMissingPluginId() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-6")); - } - private List<String> getPlugin1Manifest() { String[] lines = new String[] { "Manifest-Version: 1.0\n" diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java index 9afb636..ca62770 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/PropertiesPluginDescriptorFinderTest.java @@ -96,24 +96,6 @@ public class PropertiesPluginDescriptorFinderTest { instance.find(getPluginsRoot().resolve("test-plugin-3")); } - @Test(expected = PluginException.class) - public void testFindMissingPluginClass() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-4")); - } - - @Test(expected = PluginException.class) - public void testFindMissingPluginVersion() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-5")); - } - - @Test(expected = PluginException.class) - public void testFindMissingPluginId() throws Exception { - PluginDescriptorFinder instance = new DefaultPluginDescriptorFinder(new DefaultPluginClasspath()); - instance.find(getPluginsRoot().resolve("test-plugin-6")); - } - private List<String> getPlugin1Properties() { String[] lines = new String[] { "plugin.id=test-plugin-1\n" |