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] 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