1 23 24 package com.rift.coad.lib.httpd; 26 27 import java.lang.reflect.InvocationHandler ; 29 import java.lang.reflect.Method ; 30 import java.lang.reflect.Proxy ; 31 import java.util.Vector ; 32 33 import junit.framework.*; 35 36 import org.apache.log4j.Logger; 38 import org.apache.log4j.BasicConfigurator; 39 import org.apache.log4j.ConsoleAppender; 40 import org.apache.log4j.Priority; 41 42 import com.rift.coad.lib.thread.BasicThread; 44 import com.rift.coad.lib.thread.CoadunationThreadGroup; 45 import com.rift.coad.lib.thread.ThreadStateMonitor; 46 import com.rift.coad.lib.configuration.Configuration; 47 import com.rift.coad.lib.configuration.ConfigurationFactory; 48 import com.rift.coad.lib.security.RoleManager; 49 import com.rift.coad.lib.security.SessionManager; 50 import com.rift.coad.lib.security.ThreadsPermissionContainer; 51 import com.rift.coad.lib.security.user.UserStoreManager; 52 import com.rift.coad.lib.security.user.UserSessionManager; 53 import com.rift.coad.lib.security.login.LoginManager; 54 55 59 public class HttpRequestManagerTest extends TestCase { 60 61 public class TestHandler implements InvocationHandler { 62 63 private int numTests = 0; 65 private int countTests = 0; 66 67 68 71 public TestHandler() { 72 73 } 74 75 80 public TestHandler(int numTests) { 81 this.numTests = numTests * 2; 82 } 83 84 85 88 public Object invoke(Object proxy, Method method, Object [] args) { 89 System.out.println("Handler has been called"); 90 synchronized (this) { 91 countTests++; 92 notify(); 93 } 94 return null; 95 } 96 97 98 103 public synchronized void waitOnTest() throws Exception { 104 while (countTests < numTests) { 105 wait(); 106 } 107 } 108 } 109 110 public HttpRequestManagerTest(String testName) { 111 super(testName); 112 BasicConfigurator.configure(); 113 } 114 115 protected void setUp() throws Exception { 116 } 117 118 protected void tearDown() throws Exception { 119 } 120 121 public static Test suite() { 122 TestSuite suite = new TestSuite(HttpRequestManagerTest.class); 123 124 return suite; 125 } 126 127 130 public void testAddRequest() throws Exception { 131 System.out.println("addRequest"); 132 133 ThreadsPermissionContainer permissionContainer = 135 new ThreadsPermissionContainer(); 136 SessionManager.init(permissionContainer); 137 UserStoreManager userStoreManager = new UserStoreManager(); 138 UserSessionManager sessionManager = new UserSessionManager( 139 permissionContainer,userStoreManager); 140 LoginManager.init(sessionManager,userStoreManager); 141 142 RoleManager.getInstance(); 144 145 CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(sessionManager, 147 userStoreManager); 148 149 150 HttpRequestManager instance = new HttpRequestManager(threadGroup); 151 152 TestHandler testHandler = new TestHandler(100); 154 for (int index = 0; index < 100; index++) { 155 RequestInterface requestInterface = 157 (RequestInterface)Proxy.newProxyInstance( 158 RequestInterface.class.getClassLoader(), 159 new Class [] {RequestInterface.class}, 160 testHandler); 161 System.out.println("Add entry to request [" + (index + 1) + "]"); 162 instance.addRequest(requestInterface); 163 } 164 165 System.out.println("Wait on the test."); 166 testHandler.waitOnTest(); 167 } 168 169 } 170 | Popular Tags |