]> source.dussan.org Git - pf4j.git/commitdiff
Generate Manifest content for testing 61/head
authorMário Franco <mario.ffranco@gmail.com>
Wed, 9 Sep 2015 11:00:01 +0000 (12:00 +0100)
committerMário Franco <mario.ffranco@gmail.com>
Wed, 9 Sep 2015 11:02:27 +0000 (12:02 +0100)
pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java
pf4j/src/test/java/ro/fortsoft/pf4j/ManifestPluginDescriptorFinderTest.java
pf4j/src/test/resources/test-plugin-1/classes/META-INF/MANIFEST.MF [deleted file]
pf4j/src/test/resources/test-plugin-2/classes/META-INF/MANIFEST.MF [deleted file]
pf4j/src/test/resources/test-plugin-3/empty.txt [deleted file]
pf4j/src/test/resources/test-plugin-4/classes/META-INF/MANIFEST.MF [deleted file]
pf4j/src/test/resources/test-plugin-5/classes/META-INF/MANIFEST.MF [deleted file]
pf4j/src/test/resources/test-plugin-6/classes/META-INF/MANIFEST.MF [deleted file]

index e32b4dce4db930d65ba57735728e2c2670f71a35..0c0009bce182aaab19d000123c9b89a56f2bc925 100644 (file)
@@ -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;
index 459d123eb8cbe0e32c3566c79f5a1d12a5e100b7..593c12635dca3d7f9cfa3eda08a239475628c621 100644 (file)
@@ -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<String> 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<String> 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<String> 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<String> 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<String> 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 (file)
index b5e48da..0000000
+++ /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 (file)
index 4cca6ac..0000000
+++ /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 (file)
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 (file)
index 95d8b81..0000000
+++ /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 (file)
index 9ab8968..0000000
+++ /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 (file)
index b271753..0000000
+++ /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
-