KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfox > test > kernel > FrameworkTest


1 /*
2  * JFox - The most lightweight Java EE Application Server!
3  * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
4  *
5  * JFox is licenced and re-distributable under GNU LGPL.
6  */

7 package jfox.test.kernel;
8
9 import java.io.File JavaDoc;
10
11 import org.jfox.framework.Framework;
12 import org.jfox.framework.ComponentId;
13 import org.jfox.framework.component.Module;
14 import org.jfox.framework.component.Component;
15 import org.junit.BeforeClass;
16 import org.junit.AfterClass;
17 import org.junit.Before;
18 import org.junit.After;
19 import org.junit.Test;
20 import junit.framework.Assert;
21
22 /**
23  * @author <a HREF="mailto:jfox.young@gmail.com">Young Yang</a>
24  */

25 public class FrameworkTest {
26
27     private static Framework framework;
28
29     private final static String JavaDoc module1 = "Test";
30     private final static String JavaDoc module2 = "Test2";
31
32     @BeforeClass
33     public static void setUp() throws Exception JavaDoc {
34 // PlaceholderUtils.loadGlobalProperty(Constants.GLOBAL_PROPERTIES);
35
framework = new Framework();
36         Module test1Module = framework.loadModule(new File JavaDoc("MODULES/Test"));
37         Module test2Module = framework.loadModule(new File JavaDoc("MODULES/Test2"));
38         Module petstoreModule = framework.loadModule(new File JavaDoc("MODULES/petstore"));
39 // test1Module.start();
40
// test2Module.start();
41
// petstoreModule.start();
42
framework.start();
43     }
44
45     @AfterClass
46     public static void tearDown() throws Exception JavaDoc {
47         framework = null;
48     }
49
50     @Before
51     public void beforeMethod() throws Exception JavaDoc {
52
53     }
54
55     @After
56     public void afterMethod() throws Exception JavaDoc {
57
58     }
59
60
61     @Test
62     public void loadModule() throws Exception JavaDoc {
63
64     }
65
66     @Test
67     public void invokeComponent() throws Exception JavaDoc {
68         Component component = framework.getModule(module1).getComponent(new ComponentId("User1"));
69         System.out.println("Hello, " + component.getClass().getMethod("getName").invoke(component) + " !");
70
71         Component component2 = framework.getModule(module2).getComponent(new ComponentId("User2"));
72         System.out.println("Hello, " + component2.getClass().getMethod("getName").invoke(component2) + " : " + component2.getClass().getMethod("getPassword").invoke(component2) + " !");
73
74         Component component3 = framework.getModule(module1).getComponent(new ComponentId("UserManager"));
75         System.out.println("Hello, " + component3.getClass().getMethod("listUsers").invoke(component3) + " !");
76
77     }
78
79     @Test
80     public void unloadModule() throws Exception JavaDoc {
81         framework.unloadModule(module2);
82         Assert.assertNull(framework.getModule(module2));
83     }
84
85     @Test
86     public void reloadModule() throws Exception JavaDoc {
87         Thread.sleep(10000);
88         Module test2Module = framework.loadModule(new File JavaDoc("MODULES/Test2"));
89         test2Module.start();
90         Component component2 = framework.getModule(module2).getComponent(new ComponentId("User2"));
91         System.out.println("Hello, " + component2.getClass().getMethod("getName").invoke(component2) + " : " + component2.getClass().getMethod("getPassword").invoke(component2) + " !");
92
93         Component component3 = framework.getModule(module1).getComponent("UserManager");
94         System.out.println("Hello, " + component3.getClass().getMethod("listUsers").invoke(component3) + " !");
95
96     }
97
98 }
99
Popular Tags