KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > bean > BeanLoaderTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * BeanLoaderTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.deployment.bean;
25
26 import com.rift.coad.lib.interceptor.InterceptorFactory;
27 import com.rift.coad.lib.naming.NamingDirector;
28 import com.rift.coad.lib.security.ThreadPermissionSession;
29 import com.rift.coad.lib.security.UserSession;
30 import com.rift.coad.lib.transaction.TransactionDirector;
31 import java.util.HashSet JavaDoc;
32 import java.util.Set JavaDoc;
33 import junit.framework.*;
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import org.apache.log4j.Logger;
37 import com.rift.coad.lib.deployment.DeploymentLoader;
38 import com.rift.coad.lib.deployment.BeanInfo;
39 import org.apache.log4j.BasicConfigurator;
40
41 // coadunation import
42
import com.rift.coad.lib.security.ThreadsPermissionContainer;
43 import com.rift.coad.lib.security.user.UserSessionManager;
44 import com.rift.coad.lib.configuration.ConfigurationFactory;
45 import com.rift.coad.lib.configuration.Configuration;
46 import com.rift.coad.lib.security.user.UserStoreManager;
47 import com.rift.coad.lib.security.ThreadsPermissionContainer;
48 import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
49 import com.rift.coad.lib.security.SessionManager;
50 import com.rift.coad.lib.security.RoleManager;
51 import com.rift.coad.lib.security.Validator;
52 import com.rift.coad.lib.security.login.LoginManager;
53 import com.rift.coad.lib.thread.CoadunationThreadGroup;
54
55 /**
56  *
57  * @author Brett Chaldecott
58  */

59 public class BeanLoaderTest extends TestCase {
60     
61     public BeanLoaderTest(String JavaDoc testName) {
62         super(testName);
63         BasicConfigurator.configure();
64     }
65
66     protected void setUp() throws Exception JavaDoc {
67     }
68
69     protected void tearDown() throws Exception JavaDoc {
70     }
71
72     public static Test suite() {
73         TestSuite suite = new TestSuite(BeanLoaderTest.class);
74         
75         return suite;
76     }
77
78     /**
79      * Test of of class com.rift.coad.lib.deployment.bean.BeanLoader.
80      */

81     public void testBeanLoader() throws Exception JavaDoc {
82         System.out.println("getBeans");
83         System.out.println("Jar path : " + System.getProperty("test.jar"));
84         
85         // instanciate the deployment loader
86
ThreadsPermissionContainer permissionContainer =
87                 new ThreadsPermissionContainer();
88         
89         // initialize the thread permissions
90
SessionManager.init(permissionContainer);
91         UserStoreManager userStoreManager = new UserStoreManager();
92         UserSessionManager sessionManager = new UserSessionManager(permissionContainer,
93                 userStoreManager);
94         LoginManager.init(sessionManager,userStoreManager);
95         
96         // add a user to the session for the current thread
97
RoleManager.getInstance();
98         
99         // instanciate the thread manager
100
CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(sessionManager,
101             userStoreManager);
102         
103         // setup the interceptor factory
104
InterceptorFactory.init(permissionContainer,sessionManager,
105                 userStoreManager);
106         
107         // add a new user object and add to the permission
108
Set JavaDoc set = new HashSet JavaDoc();
109         set.add("test");
110         UserSession user = new UserSession("test1", set);
111         permissionContainer.putSession(new Long JavaDoc(Thread.currentThread().getId()),
112                 new ThreadPermissionSession(
113                 new Long JavaDoc(Thread.currentThread().getId()),user));
114         
115         // setup the naming
116
NamingDirector.init(threadGroup);
117         
118         // instanciate the transaction director
119
TransactionDirector transactionDirector = TransactionDirector.init();
120         
121         DeploymentLoader deploymentLoader = new DeploymentLoader(
122                 new java.io.File JavaDoc(System.getProperty("test.jar")));
123         
124         // instanciate the bean loader
125
BeanLoader instance = new BeanLoader(deploymentLoader,
126                 permissionContainer,threadGroup);
127         instance.setContextClassLoader(deploymentLoader.getClassLoader());
128         threadGroup.addThread(instance,"test");
129         instance.start();
130         instance.join();
131         if (!instance.wasSucessfull()) {
132             throw instance.getException();
133         }
134         
135         // retrieve the list of beans
136
Map JavaDoc beans = instance.getBeans();
137         if (beans.get("testbean") == null) {
138             fail("Failed to load the bean");
139             return;
140         }
141         
142         // unload
143
instance.stopThreads();
144         
145     }
146     
147 }
148
Popular Tags