[922] | 1 | package de.ugoe.cs.autoquest.plugin; |
---|
[511] | 2 | |
---|
| 3 | import java.io.File; |
---|
[772] | 4 | import java.util.Arrays; |
---|
[531] | 5 | import java.util.Collection; |
---|
[511] | 6 | |
---|
| 7 | import junitx.framework.ArrayAssert; |
---|
| 8 | |
---|
| 9 | import org.junit.*; |
---|
[922] | 10 | |
---|
| 11 | import de.ugoe.cs.autoquest.plugin.PluginLoader; |
---|
| 12 | import de.ugoe.cs.autoquest.plugin.PluginLoaderException; |
---|
| 13 | import de.ugoe.cs.autoquest.plugin.QuestPlugin; |
---|
[511] | 14 | import static org.junit.Assert.*; |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * The class <code>PluginLoaderTest</code> contains tests for the class |
---|
| 18 | * <code>{@link PluginLoader}</code>. |
---|
| 19 | * |
---|
| 20 | * @author Steffen Herbold |
---|
| 21 | * @version 1.0 |
---|
| 22 | */ |
---|
| 23 | public class PluginLoaderTest { |
---|
| 24 | |
---|
| 25 | @Test |
---|
| 26 | public void testPluginLoader_1() throws Exception { |
---|
| 27 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 28 | assertNotNull(loader); |
---|
| 29 | } |
---|
| 30 | |
---|
[766] | 31 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
[511] | 32 | public void testPluginLoader_2() throws Exception { |
---|
| 33 | new PluginLoader(null); |
---|
| 34 | } |
---|
| 35 | |
---|
[766] | 36 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
[511] | 37 | public void testPluginLoader_3() throws Exception { |
---|
[922] | 38 | new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar")); |
---|
[511] | 39 | } |
---|
| 40 | |
---|
| 41 | @Test |
---|
| 42 | public void testCheckNameConformity_1() throws Exception { |
---|
| 43 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 44 | String filename = "quest-plugin-jfc-1.0.jar"; |
---|
| 45 | boolean expected = true; |
---|
| 46 | |
---|
| 47 | boolean result = loader.checkNameConformity(filename); |
---|
| 48 | |
---|
| 49 | assertEquals(expected, result); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | @Test |
---|
| 53 | public void testCheckNameConformity_2() throws Exception { |
---|
| 54 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 55 | String filename = "quest-plugin-jf-c-1.0.jar"; |
---|
| 56 | boolean expected = false; |
---|
| 57 | |
---|
| 58 | boolean result = loader.checkNameConformity(filename); |
---|
| 59 | |
---|
| 60 | assertEquals(expected, result); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | @Test |
---|
| 64 | public void testCheckNameConformity_3() throws Exception { |
---|
| 65 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 66 | String filename = "quest-plugin-jfc.jar"; |
---|
| 67 | boolean expected = false; |
---|
| 68 | |
---|
| 69 | boolean result = loader.checkNameConformity(filename); |
---|
| 70 | |
---|
| 71 | assertEquals(expected, result); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | @Test |
---|
| 75 | public void testCheckNameConformity_4() throws Exception { |
---|
| 76 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 77 | String filename = "quest-plugi-jfc-1.0.jar"; |
---|
| 78 | boolean expected = false; |
---|
| 79 | |
---|
| 80 | boolean result = loader.checkNameConformity(filename); |
---|
| 81 | |
---|
| 82 | assertEquals(expected, result); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | @Test |
---|
| 86 | public void testCheckNameConformity_5() throws Exception { |
---|
| 87 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 88 | String filename = "quest-pluginjfc-1.0.jar"; |
---|
| 89 | boolean expected = false; |
---|
| 90 | |
---|
| 91 | boolean result = loader.checkNameConformity(filename); |
---|
| 92 | |
---|
| 93 | assertEquals(expected, result); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | @Test |
---|
| 97 | public void testCheckNameConformity_6() throws Exception { |
---|
| 98 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 99 | String filename = "quest-plugin-jfc-1-0.jar"; |
---|
| 100 | boolean expected = false; |
---|
| 101 | |
---|
| 102 | boolean result = loader.checkNameConformity(filename); |
---|
| 103 | |
---|
| 104 | assertEquals(expected, result); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | @Test |
---|
| 108 | public void testCheckNameConformity_7() throws Exception { |
---|
| 109 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 110 | String filename = "quest-plugin-jfc-1.0.nojar"; |
---|
| 111 | boolean expected = false; |
---|
| 112 | |
---|
| 113 | boolean result = loader.checkNameConformity(filename); |
---|
| 114 | |
---|
| 115 | assertEquals(expected, result); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | @Test |
---|
| 119 | public void testCheckNameConformity_8() throws Exception { |
---|
| 120 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 121 | String filename = null; |
---|
| 122 | boolean expected = false; |
---|
| 123 | |
---|
| 124 | boolean result = loader.checkNameConformity(filename); |
---|
| 125 | |
---|
| 126 | assertEquals(expected, result); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | @Test |
---|
| 130 | public void testCheckNameConformity_9() throws Exception { |
---|
| 131 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 132 | String filename = ""; |
---|
| 133 | boolean expected = false; |
---|
| 134 | |
---|
| 135 | boolean result = loader.checkNameConformity(filename); |
---|
| 136 | |
---|
| 137 | assertEquals(expected, result); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | @Test |
---|
| 141 | public void testGetClassPathFromJar_1() throws Exception { |
---|
| 142 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[922] | 143 | File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar"); |
---|
[511] | 144 | |
---|
| 145 | String[] expected = new String[]{ "file:" + jarFile.getParentFile().getAbsolutePath()+"/javahelperlib.jar" }; |
---|
| 146 | |
---|
| 147 | String[] result = loader.getClassPathFromJar(jarFile); |
---|
| 148 | |
---|
| 149 | ArrayAssert.assertEquivalenceArrays(expected, result); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | @Test |
---|
| 153 | public void testGetClassPathFromJar_2() throws Exception { |
---|
| 154 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[922] | 155 | File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jmi.jar"); |
---|
[511] | 156 | |
---|
| 157 | String[] expected = new String[]{ }; |
---|
| 158 | |
---|
| 159 | String[] result = loader.getClassPathFromJar(jarFile); |
---|
| 160 | |
---|
| 161 | ArrayAssert.assertEquivalenceArrays(expected, result); |
---|
| 162 | } |
---|
[531] | 163 | |
---|
| 164 | @Test |
---|
| 165 | public void testLoad_1() throws Exception { |
---|
[922] | 166 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest")); |
---|
[531] | 167 | |
---|
| 168 | loader.load(); |
---|
| 169 | |
---|
| 170 | Collection<QuestPlugin> plugins = loader.getPlugins(); |
---|
| 171 | |
---|
| 172 | assertEquals(1, plugins.size()); |
---|
| 173 | QuestPlugin plugin = plugins.iterator().next(); |
---|
| 174 | assertNotNull(plugin); |
---|
| 175 | assertEquals("Mock Plugin", plugin.getTitle()); |
---|
[922] | 176 | assertEquals(Arrays.asList(new String[]{"de.ugoe.cs.autoquest.plugin.mock.commands"}), plugin.getCommandPackages()); |
---|
[531] | 177 | } |
---|
| 178 | |
---|
| 179 | @Test |
---|
| 180 | public void testLoad_2() throws Exception { |
---|
[922] | 181 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_1")); |
---|
[531] | 182 | |
---|
| 183 | try { |
---|
| 184 | loader.load(); |
---|
| 185 | } catch(PluginLoaderException e) { |
---|
| 186 | e.getMessage().endsWith("not instance of QuestPlugin"); |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | @Test |
---|
| 191 | public void testLoad_3() throws Exception { |
---|
[922] | 192 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_2")); |
---|
[531] | 193 | |
---|
| 194 | try { |
---|
| 195 | loader.load(); |
---|
| 196 | } catch(PluginLoaderException e) { |
---|
| 197 | e.getMessage().startsWith("No class"); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | @Test |
---|
| 202 | public void testLoad_4() throws Exception { |
---|
[922] | 203 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_3")); |
---|
[531] | 204 | |
---|
| 205 | try { |
---|
| 206 | loader.load(); |
---|
| 207 | } catch(PluginLoaderException e) { |
---|
| 208 | e.getMessage().endsWith("Could not access"); |
---|
| 209 | } |
---|
| 210 | } |
---|
[511] | 211 | |
---|
| 212 | } |
---|