source: trunk/quest-plugin-core-test/src/test/java/de/ugoe/cs/quest/plugin/PluginLoaderTest.java @ 531

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