source: trunk/autoquest-plugin-core-test/src/test/java/de/ugoe/cs/autoquest/plugin/PluginLoaderTest.java

Last change on this file was 2260, checked in by pharms, 5 years ago

Update to java 11

  • Property svn:mime-type set to text/plain
File size: 6.5 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin;
16
17import java.io.File;
18import java.util.Arrays;
19import java.util.Collection;
20
21import org.junit.*;
22
23import de.ugoe.cs.autoquest.plugin.PluginLoader;
24import de.ugoe.cs.autoquest.plugin.PluginLoaderException;
25import de.ugoe.cs.autoquest.plugin.AutoQUESTPlugin;
26import 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 */
35public class PluginLoaderTest {
36       
37        @Test
38        public void testPluginLoader_1() throws Exception {
39                PluginLoader loader = new PluginLoader(new File("."));
40                assertNotNull(loader);
41        }
42       
43        @Test(expected = java.lang.IllegalArgumentException.class)
44        public void testPluginLoader_2() throws Exception {
45                new PluginLoader(null);
46        }
47       
48        @Test(expected = java.lang.IllegalArgumentException.class)
49        public void testPluginLoader_3() throws Exception {
50                new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar"));
51        }
52               
53        @Test
54        public void testCheckNameConformity_1() throws Exception {
55                PluginLoader loader = new PluginLoader(new File("."));
56                String filename = "autoquest-plugin-jfc-1.0.jar";
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("."));
67                String filename = "autoquest-plugin-jf-c-1.0.jar";
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("."));
78                String filename = "autoquest-plugin-jfc.jar";
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("."));
89                String filename = "autoquest-plugi-jfc-1.0.jar";
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("."));
100                String filename = "autoquest-pluginjfc-1.0.jar";
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("."));
111                String filename = "autoquest-plugin-jfc-1-0.jar";
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       
152        /*@Test
153        public void testGetClassPathFromJar_1() throws Exception {
154                PluginLoader loader = new PluginLoader(new File("."));
155                File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jfcmonitor.jar");
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("."));
167                File jarFile = new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest/jmi.jar");
168               
169                String[] expected = new String[]{ };
170                               
171                String[] result = loader.getClassPathFromJar(jarFile);
172               
173                ArrayAssert.assertEquivalenceArrays(expected, result);
174        }*/
175       
176        @Test
177        public void testLoad_1() throws Exception {
178                PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTest"));
179               
180                loader.load();
181               
182                Collection<AutoQUESTPlugin> plugins = loader.getPlugins();
183               
184                assertEquals(1, plugins.size());
185                AutoQUESTPlugin plugin = plugins.iterator().next();
186                assertNotNull(plugin);
187                assertEquals("Mock Plugin", plugin.getTitle());
188                assertEquals(Arrays.asList(new String[]{"de.ugoe.cs.autoquest.plugin.mock.commands"}), plugin.getCommandPackages());
189        }
190       
191        @Test
192        public void testLoad_2() throws Exception {
193                PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_1"));
194               
195                try {
196                        loader.load();
197                } catch(PluginLoaderException e) {
198                        assertTrue(e.getMessage().endsWith("not instance of AutoQUESTPlugin"));
199                }
200        }
201       
202        @Test
203        public void testLoad_3() throws Exception {
204                PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_2"));
205               
206                try {
207                        loader.load();
208                } catch(PluginLoaderException e) {
209                        assertTrue(e.getMessage().startsWith("No class"));
210                }
211        }
212       
213        @Test
214        public void testLoad_4() throws Exception {
215                PluginLoader loader = new PluginLoader(new File("testdata/de.ugoe.cs.autoquest.plugin.PluginLoaderTestInvalid_3"));
216               
217                try {
218                        loader.load();
219                } catch(PluginLoaderException e) {
220                        assertTrue(e.getMessage().endsWith("Could not access"));
221                }
222        }
223
224}
Note: See TracBrowser for help on using the repository browser.