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