KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > test > MagnetParserTest


1 package org.sapia.magnet.test;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 import junit.framework.TestCase;
8 import junit.textui.TestRunner;
9
10 import org.apache.log4j.BasicConfigurator;
11 import org.apache.log4j.LogManager;
12 import org.apache.log4j.Level;
13
14 import org.sapia.magnet.MagnetParser;
15 import org.sapia.magnet.MagnetException;
16 import org.sapia.magnet.domain.Exclude;
17 import org.sapia.magnet.domain.Launcher;
18 import org.sapia.magnet.domain.Include;
19 import org.sapia.magnet.domain.Magnet;
20 import org.sapia.magnet.domain.Param;
21 import org.sapia.magnet.domain.Parameters;
22 import org.sapia.magnet.domain.Path;
23 import org.sapia.magnet.domain.Profile;
24 import org.sapia.magnet.domain.Script;
25 import org.sapia.magnet.domain.system.SystemLauncher;
26 import org.sapia.magnet.domain.java.Classpath;
27 import org.sapia.magnet.domain.java.Codebase;
28 import org.sapia.magnet.domain.java.JavaLauncher;
29
30 /**
31  *
32  *
33  * @author Jean-Cedric Desrochers
34  *
35  * <dl>
36  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
37  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
38  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
39  * </dl>
40  */

41 public class MagnetParserTest extends TestCase {
42
43   private static String JavaDoc XML_INVALID =
44       "<magnet>";
45
46   private static String JavaDoc XML_EMPTY_MAGNET =
47       "<magnet xmlns=\"http://schemas.sapia.org/magnet\" />";
48
49   private static String JavaDoc XML_SIMPLE_MAGNET =
50       "<MAGNET:magnet xmlns:MAGNET=\"http://schemas.sapia.org/magnet\" name=\"testMagnet\" description=\"A test magnet\">" +
51 // " <MAGNET:extend magnetFile=\"abstractMagnet.xml\">" +
52
// " <MAGNET:path dir=\"../parent\"/>" +
53
// " </MAGNET:extend>" +
54
" <MAGNET:script type=\"java\" profile=\"prod\" isAbortingOnError=\"true\">" +
55       " System.out.println(\"Production Mode\");" +
56       " </MAGNET:script>" +
57       " <MAGNET:parameters>" +
58       " <MAGNET:param name=\"param1\" value=\"value1\" />" +
59       " <MAGNET:param name=\"param2\" value=\"value2\" />" +
60       " </MAGNET:parameters>" +
61       " <MAGNET:parameters profile=\"dev\">" +
62       " <MAGNET:param name=\"param3\" value=\"value_dev\" />" +
63       " </MAGNET:parameters>" +
64       " <MAGNET:parameters profile=\"prod\">" +
65       " <MAGNET:param name=\"param3\" value=\"value_prod\" />" +
66       " </MAGNET:parameters>" +
67       " <MAGNET:launcher type=\"system\" name=\"SapiaHomePage\" command=\"iexplore ${url}\">" +
68       " <MAGNET:profile name=\"dev\">" +
69       " <MAGNET:parameters>" +
70       " <MAGNET:param name=\"url\" value=\"http://dev.sapia.org\" />" +
71       " </MAGNET:parameters>" +
72       " </MAGNET:profile>" +
73       " </MAGNET:launcher>" +
74       "</MAGNET:magnet>";
75
76   private static String JavaDoc XML_INVALID_LAUNCHER =
77       "<MAGNET:magnet xmlns:MAGNET=\"http://schemas.sapia.org/magnet\" name=\"testMagnet\" description=\"A test magnet\">" +
78       " <MAGNET:parameters>" +
79       " <MAGNET:param name=\"param1\" value=\"value1\" />" +
80       " <MAGNET:param name=\"param2\" value=\"value2\" />" +
81       " </MAGNET:parameters>" +
82       " <MAGNET:launcher type=\"invalid\" name=\"SapiaHomePage\">" +
83       " </MAGNET:launcher>" +
84       "</MAGNET:magnet>";
85
86   private static String JavaDoc XML_JAVA_LAUNCHER =
87       "<MAGNET:magnet xmlns:MAGNET=\"http://schemas.sapia.org/magnet\" name=\"testMagnet\" description=\"A test magnet\">" +
88       " <MAGNET:codebase id=\"remote\">" +
89       " <MAGNET:path protocol=\"http\" host=\"dev.sapia.org\" dir=\"/codebase/lib\">" +
90       " <MAGNET:include pattern=\"interfaces.jar\" />" +
91       " </MAGNET:path>" +
92       " </MAGNET:codebase>" +
93       " <MAGNET:classpath id=\"main\">" +
94       " <MAGNET:path dir=\"/lib/common\">" +
95       " <MAGNET:include pattern=\"*.jar\" />" +
96       " </MAGNET:path>" +
97       " </MAGNET:classpath>" +
98       " <MAGNET:classpath id=\"interface\" parent=\"main\">" +
99       " <MAGNET:path dir=\"/lib\">" +
100       " <MAGNET:include pattern=\"*.jar\" />" +
101       " <MAGNET:exclude pattern=\"common/*.jar\" />" +
102       " </MAGNET:path>" +
103       " </MAGNET:classpath>" +
104       " <MAGNET:launcher type=\"java\" name=\"HelloWorld\" default=\"dev\" " +
105       " mainClass=\"org.sapia.magnet.testClass\" args=\"${app.args}\" isDaemon=\"true\" >" +
106       " <MAGNET:profile name=\"dev\">" +
107       " <MAGNET:parameters>" +
108       " <MAGNET:param name=\"app.args\" value=\"HelloWorld\" />" +
109       " </MAGNET:parameters>" +
110       " </MAGNET:profile>" +
111       " </MAGNET:launcher>" +
112       "</MAGNET:magnet>";
113
114   private static String JavaDoc XML_JAVA_PROFILE =
115       "<MAGNET:magnet xmlns:MAGNET=\"http://schemas.sapia.org/magnet\" name=\"testMagnet\" description=\"A test magnet\">" +
116       " <MAGNET:codebase id=\"remote\">" +
117       " <MAGNET:path protocol=\"http\" host=\"dev.sapia.org\" dir=\"/codebase/lib\">" +
118       " <MAGNET:include pattern=\"interfaces.jar\" />" +
119       " </MAGNET:path>" +
120       " </MAGNET:codebase>" +
121       " <MAGNET:classpath id=\"main\">" +
122       " <MAGNET:path dir=\"/lib/common\">" +
123       " <MAGNET:include pattern=\"*.jar\" />" +
124       " </MAGNET:path>" +
125       " </MAGNET:classpath>" +
126       " <MAGNET:launcher type=\"java\" name=\"HelloWorld\" default=\"dev\" " +
127       " mainClass=\"org.sapia.magnet.testClass\" args=\"${app.args}\" isDaemon=\"true\" >" +
128       " <MAGNET:profile name=\"dev\">" +
129       " <MAGNET:parameters>" +
130       " <MAGNET:param name=\"app.args\" value=\"HelloWorld\" />" +
131       " </MAGNET:parameters>" +
132       " <MAGNET:codebase parent=\"remote\" />" +
133       " <MAGNET:classpath parent=\"main\">" +
134       " <MAGNET:path dir=\"/lib\">" +
135       " <MAGNET:include pattern=\"*.jar\" />" +
136       " <MAGNET:exclude pattern=\"common/*.jar\" />" +
137       " </MAGNET:path>" +
138       " </MAGNET:classpath>" +
139       " </MAGNET:profile>" +
140       " </MAGNET:launcher>" +
141       "</MAGNET:magnet>";
142
143
144   public static void main(String JavaDoc[] args) {
145     BasicConfigurator.configure();
146     TestRunner.run(MagnetParserTest.class);
147   }
148
149   public MagnetParserTest(String JavaDoc aName) {
150     super(aName);
151   }
152
153   public void testInvalidXml() throws Exception JavaDoc {
154     Level aLevel = LogManager.getRootLogger().getLevel();
155     LogManager.getRootLogger().setLevel(Level.OFF);
156     try {
157       ByteArrayInputStream JavaDoc anInputStream =
158               new ByteArrayInputStream JavaDoc(XML_INVALID.getBytes());
159       List JavaDoc someMagnets = new MagnetParser().parse(anInputStream);
160       fail("Should not be able to parse an invalid xml");
161     } catch (MagnetException de) {
162     } finally {
163       LogManager.getRootLogger().setLevel(aLevel);
164     }
165   }
166
167   public void testEmptyMagnet() throws Exception JavaDoc {
168     ByteArrayInputStream JavaDoc anInputStream =
169             new ByteArrayInputStream JavaDoc(XML_EMPTY_MAGNET.getBytes());
170     List JavaDoc someMagnets = new MagnetParser().parse(anInputStream);
171     Magnet aMagnet = (Magnet) someMagnets.get(0);
172
173     assertNotNull("The result magnet is null", aMagnet);
174     assertNull("The magnet name is invalid", aMagnet.getName());
175     assertNull("The magnet description is invalid", aMagnet.getDescription());
176   }
177
178   public void testSimpleMagnet() throws Exception JavaDoc {
179     ByteArrayInputStream JavaDoc anInputStream =
180             new ByteArrayInputStream JavaDoc(XML_SIMPLE_MAGNET.getBytes());
181     List JavaDoc someMagnets = new MagnetParser().parse(anInputStream);
182     Magnet aMagnet = (Magnet) someMagnets.get(0);
183
184     assertNotNull("The result magnet is null", aMagnet);
185     assertEquals("The magnet name is invalid", "testMagnet", aMagnet.getName());
186     assertEquals("The magnet description is invalid", "A test magnet", aMagnet.getDescription());
187
188 // assertNotNull("The extend of the magnet is invalid", aMagnet.getExtend());
189
// assertEquals("The magnet file of the extend is invalid", "abstractMagnet.xml", aMagnet.getExtend().getMagnetFile());
190
// assertNotNull("The path element of the extend is invalid", aMagnet.getExtend().getPath());
191
// assertEquals("The protocol of the path is invalid", "file", aMagnet.getExtend().getPath().getProtocol());
192
// assertEquals("The directory of the path is invalid", "../parent", aMagnet.getExtend().getPath().getDirectory());
193
// assertEquals("The size of the exlude pattern list is invalid", 0, aMagnet.getExtend().getPath().getExcludes().size());
194
// assertEquals("The size of the include pattern list is invalid", 0, aMagnet.getExtend().getPath().getIncludes().size());
195

196     assertEquals("The size of the scripts list is invalid ", 1, aMagnet.getScripts().size());
197     Iterator JavaDoc someScripts = aMagnet.getScripts().iterator();
198     Script aScript = (Script) someScripts.next();
199     assertEquals("The type of the script is invalid", "java", aScript.getType());
200     assertEquals("The profile of the script is invalid", "prod", aScript.getProfile());
201     assertEquals("The abort on error flag of the script is invalid", true, aScript.isAbortingOnError());
202     assertEquals("The code of the script is invalid", "System.out.println(\"Production Mode\");", aScript.getCode());
203
204     assertEquals("The size of the parameters list is invalid ", 3, aMagnet.getParameters().size());
205     Iterator JavaDoc someParameters = aMagnet.getParameters().iterator();
206
207     Parameters aParameters = (Parameters) someParameters.next();
208     assertEquals("The profile of the parameters is invalid", "prod", aParameters.getProfile());
209     assertEquals("The size of the params list is invalid ", 1, aParameters.getParams().size());
210     Iterator JavaDoc someParams = aParameters.getParams().iterator();
211     Param aParam = (Param) someParams.next();
212     assertEquals("The name of the param is invalid", "param3", aParam.getName());
213     assertEquals("The value of the param is invalid", "value_prod", aParam.getValue());
214
215     aParameters = (Parameters) someParameters.next();
216     assertNull("The profile of the parameters is invalid", aParameters.getProfile());
217     assertEquals("The size of the params list is invalid ", 2, aParameters.getParams().size());
218     someParams = aParameters.getParams().iterator();
219     aParam = (Param) someParams.next();
220     assertEquals("The name of the param is invalid", "param1", aParam.getName());
221     assertEquals("The value of the param is invalid", "value1", aParam.getValue());
222     aParam = (Param) someParams.next();
223     assertEquals("The name of the param is invalid", "param2", aParam.getName());
224     assertEquals("The value of the param is invalid", "value2", aParam.getValue());
225
226     aParameters = (Parameters) someParameters.next();
227     assertEquals("The profile of the parameters is invalid", "dev", aParameters.getProfile());
228     assertEquals("The size of the params list is invalid ", 1, aParameters.getParams().size());
229     someParams = aParameters.getParams().iterator();
230     aParam = (Param) someParams.next();
231     assertEquals("The name of the param is invalid", "param3", aParam.getName());
232     assertEquals("The value of the param is invalid", "value_dev", aParam.getValue());
233
234     assertEquals("The size of the launcher list is invalid ", 1, aMagnet.getLaunchers().size());
235     Launcher aLauncher = (Launcher) aMagnet.getLaunchers().iterator().next();
236     assertEquals("The type of the launcher is invalid", "system", aLauncher.getType());
237
238     assertTrue("The class of the launch handler is invalid", aLauncher.getLaunchHandler() instanceof SystemLauncher);
239     SystemLauncher aSystemLauncher = (SystemLauncher) aLauncher.getLaunchHandler();
240     assertEquals("The type of the system launcher is invalid", "system", aSystemLauncher.getType());
241     assertEquals("The name of the system launcher is invalid", "SapiaHomePage", aSystemLauncher.getName());
242     assertEquals("The default of the launcher is invalid", "iexplore ${url}", aSystemLauncher.getCommand());
243
244     assertEquals("The size of the profile list is invalid ", 1, aSystemLauncher.getProfiles().size());
245     Profile aProfile = (Profile) aSystemLauncher.getProfiles().iterator().next();
246     assertEquals("The name of the profile is invalid", "dev", aProfile.getName());
247
248     aParameters = (Parameters) aProfile.getParameters();
249     assertNull("The profile of the parameters is invalid", aParameters.getProfile());
250     assertEquals("The size of the params list is invalid", 1, aParameters.getParams().size());
251     someParams = aParameters.getParams().iterator();
252     aParam = (Param) someParams.next();
253     assertEquals("The name of the param is invalid", "url", aParam.getName());
254     assertEquals("The value of the param is invalid", "http://dev.sapia.org", aParam.getValue());
255   }
256
257   public void testInvalidLauncher() throws Exception JavaDoc {
258     Level aLevel = LogManager.getRootLogger().getLevel();
259     LogManager.getRootLogger().setLevel(Level.OFF);
260     try {
261       ByteArrayInputStream JavaDoc anInputStream =
262               new ByteArrayInputStream JavaDoc(XML_INVALID_LAUNCHER.getBytes());
263       List JavaDoc aList = new MagnetParser().parse(anInputStream);
264 // fail("Should not parse a launcher of type invalid");
265
} catch (MagnetException de) {
266     } finally {
267       LogManager.getRootLogger().setLevel(aLevel);
268     }
269   }
270
271   public void testJavaLauncher() throws Exception JavaDoc {
272     ByteArrayInputStream JavaDoc anInputStream =
273             new ByteArrayInputStream JavaDoc(XML_JAVA_LAUNCHER.getBytes());
274     List JavaDoc someMagnets = new MagnetParser().parse(anInputStream);
275     Magnet aMagnet = (Magnet) someMagnets.get(0);
276
277     assertNotNull("The result magnet is null", aMagnet);
278     assertEquals("The magnet name is invalid", "testMagnet", aMagnet.getName());
279     assertEquals("The magnet description is invalid", "A test magnet", aMagnet.getDescription());
280     assertNull("The extend of the magnet is invalid", aMagnet.getExtends());
281     assertEquals("The size of the script list is invalid", 0, aMagnet.getScripts().size());
282     assertEquals("The size of the parameters list is invalid", 0, aMagnet.getParameters().size());
283
284     assertEquals("The size of the codebase list is invalid", 1, aMagnet.getObjectsFor("Codebase").size());
285     Iterator JavaDoc someCodebases = aMagnet.getObjectsFor("Codebase").iterator();
286     Codebase aCodebase = (Codebase) someCodebases.next();
287
288     assertEquals("The id of the codebase is invalid", "remote", aCodebase.getId());
289     assertNull("The parent of the codebase is invalid", aCodebase.getParent());
290     assertEquals("The protocol of the path is invalid", "http", ((Path) aCodebase.getPaths().get(0)).getProtocol());
291     assertEquals("The host of the path is invalid", "dev.sapia.org", ((Path) aCodebase.getPaths().get(0)).getHost());
292     assertEquals("The directory of the path is invalid", "/codebase/lib", ((Path) aCodebase.getPaths().get(0)).getDirectory());
293     assertEquals("The size of the exclude list is invalid", 0, ((Path) aCodebase.getPaths().get(0)).getExcludes().size());
294     assertEquals("The size of the include list is invalid", 1, ((Path) aCodebase.getPaths().get(0)).getIncludes().size());
295     Include anInclude = (Include) ((Path) aCodebase.getPaths().get(0)).getIncludes().iterator().next();
296     assertEquals("The pattern of the include is invalid", "interfaces.jar", anInclude.getPattern());
297
298     assertEquals("The size of the classpath list is invalid", 2, aMagnet.getObjectsFor("Classpath").size());
299     Iterator JavaDoc someClasspaths = aMagnet.getObjectsFor("Classpath").iterator();
300     Classpath aClasspath = (Classpath) someClasspaths.next();
301
302     assertEquals("The id of the classpath is invalid", "main", aClasspath.getId());
303     assertNull("The parent of the classpath is invalid", aClasspath.getParent());
304     assertEquals("The protocol of the path is invalid", "file", ((Path) aClasspath.getPaths().get(0)).getProtocol());
305     assertEquals("The host of the path is invalid", "localhost", ((Path) aClasspath.getPaths().get(0)).getHost());
306     assertEquals("The directory of the path is invalid", "/lib/common", ((Path) aClasspath.getPaths().get(0)).getDirectory());
307     assertEquals("The size of the exclude list is invalid", 0, ((Path) aClasspath.getPaths().get(0)).getExcludes().size());
308     assertEquals("The size of the include list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getIncludes().size());
309     anInclude = (Include) ((Path) aClasspath.getPaths().get(0)).getIncludes().iterator().next();
310     assertEquals("The pattern of the include is invalid", "*.jar", anInclude.getPattern());
311
312     aClasspath = (Classpath) someClasspaths.next();
313     assertEquals("The id of the classpath is invalid", "interface", aClasspath.getId());
314     assertEquals("The parent of the classpath is invalid", "main", aClasspath.getParent());
315     assertEquals("The protocol of the path is invalid", "file", ((Path) aClasspath.getPaths().get(0)).getProtocol());
316     assertEquals("The host of the path is invalid", "localhost", ((Path) aClasspath.getPaths().get(0)).getHost());
317     assertEquals("The directory of the path is invalid", "/lib", ((Path) aClasspath.getPaths().get(0)).getDirectory());
318     assertEquals("The size of the exclude list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getExcludes().size());
319     Exclude anExclude = (Exclude) ((Path) aClasspath.getPaths().get(0)).getExcludes().iterator().next();
320     assertEquals("The pattern of the exclude is invalid", "common/*.jar", anExclude.getPattern());
321     assertEquals("The size of the include list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getIncludes().size());
322     anInclude = (Include) ((Path) aClasspath.getPaths().get(0)).getIncludes().iterator().next();
323     assertEquals("The pattern of the include is invalid", "*.jar", anInclude.getPattern());
324
325     assertEquals("The size of the parameters list is invalid", 1, aMagnet.getLaunchers().size());
326     Launcher aLauncher = (Launcher) aMagnet.getLaunchers().iterator().next();
327     assertEquals("The type of the launcher is invalid", "java", aLauncher.getType());
328
329     assertTrue("The class of the launch handler is invalid", aLauncher.getLaunchHandler() instanceof JavaLauncher);
330     JavaLauncher aJavaLauncher = (JavaLauncher) aLauncher.getLaunchHandler();
331     assertEquals("The type of the java launcher is invalid", "java", aJavaLauncher.getType());
332     assertEquals("The name of the java launcher is invalid", "HelloWorld", aJavaLauncher.getName());
333     assertEquals("The default of the java launcher is invalid", "dev", aJavaLauncher.getDefault());
334     assertEquals("The main class of the java launcher is invalid", "org.sapia.magnet.testClass", aJavaLauncher.getMainClass());
335     assertEquals("The args of the java launcher is invalid", "${app.args}", aJavaLauncher.getArgs());
336     assertTrue("The daemon indicator of the java launcher is invalid", aJavaLauncher.isDaemon());
337
338     assertEquals("The size of the profile list is invalid ", 1, aJavaLauncher.getProfiles().size());
339     Profile aProfile = (Profile) aJavaLauncher.getProfiles().iterator().next();
340     assertEquals("The name of the profile is invalid", "dev", aProfile.getName());
341
342     Parameters aParameters = (Parameters) aProfile.getParameters();
343     assertNull("The profile of the parameters is invalid", aParameters.getProfile());
344     assertEquals("The size of the params list is invalid", 1, aParameters.getParams().size());
345     Iterator JavaDoc someParams = aParameters.getParams().iterator();
346     Param aParam = (Param) someParams.next();
347     assertEquals("The name of the param is invalid", "app.args", aParam.getName());
348     assertEquals("The value of the param is invalid", "HelloWorld", aParam.getValue());
349  }
350
351   public void testJavaProfile() throws Exception JavaDoc {
352     ByteArrayInputStream JavaDoc anInputStream =
353             new ByteArrayInputStream JavaDoc(XML_JAVA_PROFILE.getBytes());
354     List JavaDoc someMagnets = new MagnetParser().parse(anInputStream);
355     Magnet aMagnet = (Magnet) someMagnets.get(0);
356
357     assertNotNull("The result magnet is null", aMagnet);
358     assertEquals("The magnet name is invalid", "testMagnet", aMagnet.getName());
359     assertEquals("The magnet description is invalid", "A test magnet", aMagnet.getDescription());
360     assertNull("The extend of the magnet is invalid", aMagnet.getExtends());
361     assertEquals("The size of the script list is invalid", 0, aMagnet.getScripts().size());
362     assertEquals("The size of the parameters list is invalid", 0, aMagnet.getParameters().size());
363
364     assertEquals("The size of the codebase list is invalid", 1, aMagnet.getObjectsFor("Codebase").size());
365     Iterator JavaDoc someCodebases = aMagnet.getObjectsFor("Codebase").iterator();
366     Codebase aCodebase = (Codebase) someCodebases.next();
367
368     assertEquals("The id of the codebase is invalid", "remote", aCodebase.getId());
369     assertNull("The parent of the codebase is invalid", aCodebase.getParent());
370     assertEquals("The protocol of the path is invalid", "http", ((Path) aCodebase.getPaths().get(0)).getProtocol());
371     assertEquals("The host of the path is invalid", "dev.sapia.org", ((Path) aCodebase.getPaths().get(0)).getHost());
372     assertEquals("The directory of the path is invalid", "/codebase/lib", ((Path) aCodebase.getPaths().get(0)).getDirectory());
373     assertEquals("The size of the exclude list is invalid", 0, ((Path) aCodebase.getPaths().get(0)).getExcludes().size());
374     assertEquals("The size of the include list is invalid", 1, ((Path) aCodebase.getPaths().get(0)).getIncludes().size());
375     Include anInclude = (Include) ((Path) aCodebase.getPaths().get(0)).getIncludes().iterator().next();
376     assertEquals("The pattern of the include is invalid", "interfaces.jar", anInclude.getPattern());
377
378     assertEquals("The size of the classpath list is invalid", 1, aMagnet.getObjectsFor("Classpath").size());
379     Iterator JavaDoc someClasspaths = aMagnet.getObjectsFor("Classpath").iterator();
380     Classpath aClasspath = (Classpath) someClasspaths.next();
381
382     assertEquals("The id of the classpath is invalid", "main", aClasspath.getId());
383     assertNull("The parent of the classpath is invalid", aClasspath.getParent());
384     assertEquals("The protocol of the path is invalid", "file", ((Path) aClasspath.getPaths().get(0)).getProtocol());
385     assertEquals("The host of the path is invalid", "localhost", ((Path) aClasspath.getPaths().get(0)).getHost());
386     assertEquals("The directory of the path is invalid", "/lib/common", ((Path) aClasspath.getPaths().get(0)).getDirectory());
387     assertEquals("The size of the exclude list is invalid", 0, ((Path) aClasspath.getPaths().get(0)).getExcludes().size());
388     assertEquals("The size of the include list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getIncludes().size());
389     anInclude = (Include) ((Path) aClasspath.getPaths().get(0)).getIncludes().iterator().next();
390     assertEquals("The pattern of the include is invalid", "*.jar", anInclude.getPattern());
391
392     assertEquals("The size of the launcher list is invalid", 1, aMagnet.getLaunchers().size());
393     Launcher aLauncher = (Launcher) aMagnet.getLaunchers().iterator().next();
394     assertEquals("The type of the launcher is invalid", "java", aLauncher.getType());
395
396     assertTrue("The class of the launch handler is invalid", aLauncher.getLaunchHandler() instanceof JavaLauncher);
397     JavaLauncher aJavaLauncher = (JavaLauncher) aLauncher.getLaunchHandler();
398     assertEquals("The type of the java launcher is invalid", "java", aJavaLauncher.getType());
399     assertEquals("The name of the java launcher is invalid", "HelloWorld", aJavaLauncher.getName());
400     assertEquals("The default of the java launcher is invalid", "dev", aJavaLauncher.getDefault());
401     assertEquals("The main class of the java launcher is invalid", "org.sapia.magnet.testClass", aJavaLauncher.getMainClass());
402     assertEquals("The args of the java launcher is invalid", "${app.args}", aJavaLauncher.getArgs());
403     assertTrue("The daemon indicator of the java launcher is invalid", aJavaLauncher.isDaemon());
404
405     assertEquals("The size of the profile list is invalid ", 1, aJavaLauncher.getProfiles().size());
406     Profile aProfile = (Profile) aJavaLauncher.getProfiles().iterator().next();
407     assertEquals("The name of the profile is invalid", "dev", aProfile.getName());
408
409     Parameters aParameters = (Parameters) aProfile.getParameters();
410     assertNull("The profile of the parameters is invalid", aParameters.getProfile());
411     assertEquals("The size of the params list is invalid", 1, aParameters.getParams().size());
412     Iterator JavaDoc someParams = aParameters.getParams().iterator();
413     Param aParam = (Param) someParams.next();
414     assertEquals("The name of the param is invalid", "app.args", aParam.getName());
415     assertEquals("The value of the param is invalid", "HelloWorld", aParam.getValue());
416
417     assertEquals("The size of the codebase list is invalid", 1, aProfile.getObjectsFor("Codebase").size());
418     someCodebases = aProfile.getObjectsFor("Codebase").iterator();
419     aCodebase = (Codebase) someCodebases.next();
420
421     assertNull("The id of the codebase is invalid", aCodebase.getId());
422     assertEquals("The parent of the codebase is invalid", "remote", aCodebase.getParent());
423     assertEquals("The protocol of the path is invalid", 0, aCodebase.getPaths().size());
424
425     assertEquals("The size of the classpath list is invalid", 1, aProfile.getObjectsFor("Classpath").size());
426     aClasspath = (Classpath) aProfile.getObjectsFor("Classpath").iterator().next();
427     assertNull("The id of the classpath is invalid", aClasspath.getId());
428     assertEquals("The parent of the classpath is invalid", "main", aClasspath.getParent());
429     assertEquals("The protocol of the path is invalid", "file", ((Path) aClasspath.getPaths().get(0)).getProtocol());
430     assertEquals("The host of the path is invalid", "localhost", ((Path) aClasspath.getPaths().get(0)).getHost());
431     assertEquals("The directory of the path is invalid", "/lib", ((Path) aClasspath.getPaths().get(0)).getDirectory());
432     assertEquals("The size of the exclude list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getExcludes().size());
433     Exclude anExclude = (Exclude) ((Path) aClasspath.getPaths().get(0)).getExcludes().iterator().next();
434     assertEquals("The pattern of the exclude is invalid", "common/*.jar", anExclude.getPattern());
435     assertEquals("The size of the include list is invalid", 1, ((Path) aClasspath.getPaths().get(0)).getIncludes().size());
436     anInclude = (Include) ((Path) aClasspath.getPaths().get(0)).getIncludes().iterator().next();
437     assertEquals("The pattern of the include is invalid", "*.jar", anInclude.getPattern());
438
439   }
440
441 }
Popular Tags