1 7 package jfox.test.kernel; 8 9 import java.io.File ; 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 25 public class FrameworkTest { 26 27 private static Framework framework; 28 29 private final static String module1 = "Test"; 30 private final static String module2 = "Test2"; 31 32 @BeforeClass 33 public static void setUp() throws Exception { 34 framework = new Framework(); 36 Module test1Module = framework.loadModule(new File ("MODULES/Test")); 37 Module test2Module = framework.loadModule(new File ("MODULES/Test2")); 38 Module petstoreModule = framework.loadModule(new File ("MODULES/petstore")); 39 framework.start(); 43 } 44 45 @AfterClass 46 public static void tearDown() throws Exception { 47 framework = null; 48 } 49 50 @Before 51 public void beforeMethod() throws Exception { 52 53 } 54 55 @After 56 public void afterMethod() throws Exception { 57 58 } 59 60 61 @Test 62 public void loadModule() throws Exception { 63 64 } 65 66 @Test 67 public void invokeComponent() throws Exception { 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 { 81 framework.unloadModule(module2); 82 Assert.assertNull(framework.getModule(module2)); 83 } 84 85 @Test 86 public void reloadModule() throws Exception { 87 Thread.sleep(10000); 88 Module test2Module = framework.loadModule(new File ("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 |