[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
[922] | 15 | package de.ugoe.cs.autoquest.plugin; |
---|
[511] | 16 | |
---|
| 17 | import java.io.File; |
---|
[772] | 18 | import java.util.Arrays; |
---|
[531] | 19 | import java.util.Collection; |
---|
[511] | 20 | |
---|
| 21 | import org.junit.*; |
---|
[922] | 22 | |
---|
| 23 | import de.ugoe.cs.autoquest.plugin.PluginLoader; |
---|
| 24 | import de.ugoe.cs.autoquest.plugin.PluginLoaderException; |
---|
[929] | 25 | import de.ugoe.cs.autoquest.plugin.AutoQUESTPlugin; |
---|
[511] | 26 | import static org.junit.Assert.*; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * The class <code>PluginLoaderTest</code> contains tests for the class |
---|
| 30 | * <code>{@link PluginLoader}</code>. |
---|
| 31 | * |
---|
| 32 | * @author Steffen Herbold |
---|
| 33 | * @version 1.0 |
---|
| 34 | */ |
---|
| 35 | public class PluginLoaderTest { |
---|
| 36 | |
---|
| 37 | @Test |
---|
| 38 | public void testPluginLoader_1() throws Exception { |
---|
| 39 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 40 | assertNotNull(loader); |
---|
| 41 | } |
---|
| 42 | |
---|
[766] | 43 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
[511] | 44 | public void testPluginLoader_2() throws Exception { |
---|
| 45 | new PluginLoader(null); |
---|
| 46 | } |
---|
| 47 | |
---|
[766] | 48 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
[511] | 49 | public void testPluginLoader_3() throws Exception { |
---|
[922] | 50 | new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar")); |
---|
[511] | 51 | } |
---|
| 52 | |
---|
| 53 | @Test |
---|
| 54 | public void testCheckNameConformity_1() throws Exception { |
---|
| 55 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 56 | String filename = "autoquest-plugin-jfc-1.0.jar"; |
---|
[511] | 57 | boolean expected = true; |
---|
| 58 | |
---|
| 59 | boolean result = loader.checkNameConformity(filename); |
---|
| 60 | |
---|
| 61 | assertEquals(expected, result); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | @Test |
---|
| 65 | public void testCheckNameConformity_2() throws Exception { |
---|
| 66 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 67 | String filename = "autoquest-plugin-jf-c-1.0.jar"; |
---|
[511] | 68 | boolean expected = false; |
---|
| 69 | |
---|
| 70 | boolean result = loader.checkNameConformity(filename); |
---|
| 71 | |
---|
| 72 | assertEquals(expected, result); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | @Test |
---|
| 76 | public void testCheckNameConformity_3() throws Exception { |
---|
| 77 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 78 | String filename = "autoquest-plugin-jfc.jar"; |
---|
[511] | 79 | boolean expected = false; |
---|
| 80 | |
---|
| 81 | boolean result = loader.checkNameConformity(filename); |
---|
| 82 | |
---|
| 83 | assertEquals(expected, result); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | @Test |
---|
| 87 | public void testCheckNameConformity_4() throws Exception { |
---|
| 88 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 89 | String filename = "autoquest-plugi-jfc-1.0.jar"; |
---|
[511] | 90 | boolean expected = false; |
---|
| 91 | |
---|
| 92 | boolean result = loader.checkNameConformity(filename); |
---|
| 93 | |
---|
| 94 | assertEquals(expected, result); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | @Test |
---|
| 98 | public void testCheckNameConformity_5() throws Exception { |
---|
| 99 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 100 | String filename = "autoquest-pluginjfc-1.0.jar"; |
---|
[511] | 101 | boolean expected = false; |
---|
| 102 | |
---|
| 103 | boolean result = loader.checkNameConformity(filename); |
---|
| 104 | |
---|
| 105 | assertEquals(expected, result); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | @Test |
---|
| 109 | public void testCheckNameConformity_6() throws Exception { |
---|
| 110 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[1098] | 111 | String filename = "autoquest-plugin-jfc-1-0.jar"; |
---|
[511] | 112 | boolean expected = false; |
---|
| 113 | |
---|
| 114 | boolean result = loader.checkNameConformity(filename); |
---|
| 115 | |
---|
| 116 | assertEquals(expected, result); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | @Test |
---|
| 120 | public void testCheckNameConformity_7() throws Exception { |
---|
| 121 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 122 | String filename = "quest-plugin-jfc-1.0.nojar"; |
---|
| 123 | boolean expected = false; |
---|
| 124 | |
---|
| 125 | boolean result = loader.checkNameConformity(filename); |
---|
| 126 | |
---|
| 127 | assertEquals(expected, result); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | @Test |
---|
| 131 | public void testCheckNameConformity_8() throws Exception { |
---|
| 132 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 133 | String filename = null; |
---|
| 134 | boolean expected = false; |
---|
| 135 | |
---|
| 136 | boolean result = loader.checkNameConformity(filename); |
---|
| 137 | |
---|
| 138 | assertEquals(expected, result); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | @Test |
---|
| 142 | public void testCheckNameConformity_9() throws Exception { |
---|
| 143 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
| 144 | String filename = ""; |
---|
| 145 | boolean expected = false; |
---|
| 146 | |
---|
| 147 | boolean result = loader.checkNameConformity(filename); |
---|
| 148 | |
---|
| 149 | assertEquals(expected, result); |
---|
| 150 | } |
---|
| 151 | |
---|
[2260] | 152 | /*@Test |
---|
[511] | 153 | public void testGetClassPathFromJar_1() throws Exception { |
---|
| 154 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[922] | 155 | File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar"); |
---|
[511] | 156 | |
---|
| 157 | String[] expected = new String[]{ "file:" + jarFile.getParentFile().getAbsolutePath()+"/javahelperlib.jar" }; |
---|
| 158 | |
---|
| 159 | String[] result = loader.getClassPathFromJar(jarFile); |
---|
| 160 | |
---|
| 161 | ArrayAssert.assertEquivalenceArrays(expected, result); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | @Test |
---|
| 165 | public void testGetClassPathFromJar_2() throws Exception { |
---|
| 166 | PluginLoader loader = new PluginLoader(new File(".")); |
---|
[922] | 167 | File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jmi.jar"); |
---|
[511] | 168 | |
---|
| 169 | String[] expected = new String[]{ }; |
---|
| 170 | |
---|
| 171 | String[] result = loader.getClassPathFromJar(jarFile); |
---|
| 172 | |
---|
| 173 | ArrayAssert.assertEquivalenceArrays(expected, result); |
---|
[2260] | 174 | }*/ |
---|
[531] | 175 | |
---|
| 176 | @Test |
---|
| 177 | public void testLoad_1() throws Exception { |
---|
[922] | 178 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest")); |
---|
[531] | 179 | |
---|
| 180 | loader.load(); |
---|
| 181 | |
---|
[929] | 182 | Collection<AutoQUESTPlugin> plugins = loader.getPlugins(); |
---|
[531] | 183 | |
---|
| 184 | assertEquals(1, plugins.size()); |
---|
[929] | 185 | AutoQUESTPlugin plugin = plugins.iterator().next(); |
---|
[531] | 186 | assertNotNull(plugin); |
---|
| 187 | assertEquals("Mock Plugin", plugin.getTitle()); |
---|
[922] | 188 | assertEquals(Arrays.asList(new String[]{"de.ugoe.cs.autoquest.plugin.mock.commands"}), plugin.getCommandPackages()); |
---|
[531] | 189 | } |
---|
| 190 | |
---|
| 191 | @Test |
---|
| 192 | public void testLoad_2() throws Exception { |
---|
[922] | 193 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_1")); |
---|
[531] | 194 | |
---|
| 195 | try { |
---|
| 196 | loader.load(); |
---|
| 197 | } catch(PluginLoaderException e) { |
---|
[2232] | 198 | assertTrue(e.getMessage().endsWith("not instance of AutoQUESTPlugin")); |
---|
[531] | 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | @Test |
---|
| 203 | public void testLoad_3() throws Exception { |
---|
[922] | 204 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_2")); |
---|
[531] | 205 | |
---|
| 206 | try { |
---|
| 207 | loader.load(); |
---|
| 208 | } catch(PluginLoaderException e) { |
---|
[2232] | 209 | assertTrue(e.getMessage().startsWith("No class")); |
---|
[531] | 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | @Test |
---|
| 214 | public void testLoad_4() throws Exception { |
---|
[922] | 215 | PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_3")); |
---|
[531] | 216 | |
---|
| 217 | try { |
---|
| 218 | loader.load(); |
---|
| 219 | } catch(PluginLoaderException e) { |
---|
[2232] | 220 | assertTrue(e.getMessage().endsWith("Could not access")); |
---|
[531] | 221 | } |
---|
| 222 | } |
---|
[511] | 223 | |
---|
| 224 | } |
---|