KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.magnet.test;
2
3 import java.util.ArrayList JavaDoc;
4 import junit.framework.TestCase;
5 import junit.textui.TestRunner;
6
7 import org.apache.log4j.BasicConfigurator;
8
9 import org.sapia.magnet.MagnetRenderer;
10 import org.sapia.magnet.domain.Launcher;
11 import org.sapia.magnet.domain.Magnet;
12 import org.sapia.magnet.domain.Param;
13 import org.sapia.magnet.domain.Parameters;
14 import org.sapia.magnet.domain.Profile;
15 import org.sapia.magnet.domain.system.SystemLauncher;
16 import org.sapia.magnet.domain.system.Environment;
17 import org.sapia.magnet.domain.system.Variable;
18
19
20 /**
21  * @author Jean-Cedric Desrochers
22  *
23  * <dl>
24  * <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>
25  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
26  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
27  * </dl>
28  */

29 public class MagnetRendererTest extends TestCase {
30
31   public static void main(String JavaDoc[] args) {
32     TestRunner.run(MagnetRendererTest.class);
33   }
34
35   public MagnetRendererTest(String JavaDoc aName) {
36     super(aName);
37   }
38
39   public void testSimpleMagnet() throws Exception JavaDoc {
40     BasicConfigurator.configure();
41     Magnet aMagnet = createSimpleMagnet();
42     ArrayList JavaDoc aList = new ArrayList JavaDoc(1);
43     aList.add(aMagnet);
44     new MagnetRenderer().render(aList, "dev");
45     System.out.println(aMagnet);
46
47     ((Launcher) aMagnet.getLaunchers().iterator().next()).execute("dev");
48   }
49
50
51   private Magnet createSimpleMagnet() {
52     Magnet aMagnet = new Magnet();
53     aMagnet.setName("simpleMagnet");
54     aMagnet.setDescription("A test magnet");
55
56     Parameters aParameters = new Parameters();
57     aMagnet.addParameters(aParameters);
58     aParameters.addParam(new Param("protocol", "http"));
59     aParameters.addParam(new Param("host", "www.opensap.org"));
60     aParameters.addParam(new Param("key", "${protocol}-key"));
61
62     aParameters = new Parameters("test");
63     aMagnet.addParameters(aParameters);
64     aParameters.addParam(new Param("host", "test.sapia.org"));
65     aParameters.addParam(new Param("value", "${protocol}-value"));
66     aParameters.addParam(new Param("base", "${host}/index.html"));
67
68     Launcher aLauncher = new Launcher();
69     aLauncher.setType("system");
70     aMagnet.addLauncher(aLauncher);
71     SystemLauncher aLauncherHandler = (SystemLauncher) aLauncher.getLaunchHandler();
72     aLauncherHandler.setName("SapiaHomePage");
73     aLauncherHandler.setCommand("cmd /C call explorer.exe D:\\");
74     aLauncherHandler.setWorkingDirectory("C:\\");
75
76     Profile aProfile = new Profile();
77     aProfile.setName("dev");
78     aParameters = new Parameters();
79     aProfile.setParameters(aParameters);
80     aParameters.addParam(new Param("url", "${protocol}://${host}"));
81     Environment anEnv = new Environment();
82     Variable aVar = new Variable();
83     aVar.setName("path");
84     aVar.setValue("C:\\Windows");
85     anEnv.addVariable(aVar);
86     aProfile.handleObject("Environment", anEnv);
87     aLauncherHandler.addProfile(aProfile);
88
89     aProfile = new Profile();
90     aProfile.setName("test");
91     aParameters = new Parameters();
92     aProfile.setParameters(aParameters);
93     aParameters.addParam(new Param("url", "${protocol}://${base}?query=${value}"));
94     aLauncherHandler.addProfile(aProfile);
95
96     return aMagnet;
97   }
98 }
Popular Tags