KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BeanConnectorTest.java
20  *
21  * JUnit based test
22  */

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

57 public class BeanConnectorTest extends TestCase {
58     
59     public BeanConnectorTest(String JavaDoc testName) {
60         super(testName);
61     }
62
63     protected void setUp() throws Exception JavaDoc {
64     }
65
66     protected void tearDown() throws Exception JavaDoc {
67     }
68
69     public static Test suite() {
70         TestSuite suite = new TestSuite(BeanConnectorTest.class);
71         
72         return suite;
73     }
74
75     /**
76      * Test of init method, of class com.rift.coad.lib.deployment.bean.BeanConnector.
77      */

78     public void testBeanConnector() throws Exception JavaDoc {
79         System.out.println("testBeanConnector");
80         
81         System.out.println("Jar path : " + System.getProperty("test.jar"));
82         
83         // instanciate the deployment loader
84
ThreadsPermissionContainer permissionContainer =
85                 new ThreadsPermissionContainer();
86         
87         // initialize the thread permissions
88
SessionManager.init(permissionContainer);
89         UserStoreManager userStoreManager = new UserStoreManager();
90         UserSessionManager sessionManager = new UserSessionManager(
91                 permissionContainer,userStoreManager);
92         LoginManager.init(sessionManager,userStoreManager);
93         
94         // add a user to the session for the current thread
95
RoleManager.getInstance();
96         
97         // instanciate the thread manager
98
CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(sessionManager,
99             userStoreManager);
100         
101         // setup the interceptor factory
102
InterceptorFactory.init(permissionContainer,sessionManager,
103                 userStoreManager);
104         
105         // add a new user object and add to the permission
106
Set JavaDoc set = new HashSet JavaDoc();
107         set.add("test");
108         UserSession user = new UserSession("test1", set);
109         permissionContainer.putSession(new Long JavaDoc(Thread.currentThread().getId()),
110                 new ThreadPermissionSession(
111                 new Long JavaDoc(Thread.currentThread().getId()),user));
112         
113         // setup the naming
114
NamingDirector.init(threadGroup);
115         
116         // instanciate the transaction director
117
TransactionDirector transactionDirector = TransactionDirector.init();
118         
119         CacheRegistry.init(threadGroup);
120         
121         BeanManager beanManager = new BeanManager(permissionContainer,threadGroup);
122         
123         BeanConnector.init(beanManager);
124         
125         // load the bean
126
DeploymentLoader deploymentLoader = new DeploymentLoader(
127                 new java.io.File JavaDoc(System.getProperty("test.jar")));
128         
129         // load the bean
130
beanManager.load(deploymentLoader);
131         
132         // retrieve the instance to the bean
133
BeanConnector instance = BeanConnector.getInstance();
134         
135         // retrieve the list of
136
Set JavaDoc keys = instance.getKeys();
137         if ((keys.size() != 2) || (keys.contains("testbean") != true)) {
138             fail("Failed to load the beans");
139         }
140         
141         // retrieve a bean
142
Object JavaDoc bean = instance.getBean("testbean");
143         if (bean == null) {
144             fail("Failed to retrieve the testbean");
145         }
146         
147         keys = null;
148         bean = null;
149         
150         // load the bean
151
beanManager.unLoad(deploymentLoader);
152         
153         // retrieve the list of
154
keys = instance.getKeys();
155         if ((keys.size() != 0) || (keys.contains("testbean") != false)) {
156             fail("The bean is still in memory");
157         }
158         
159         CacheRegistry.getInstance().shutdown();
160         
161         NamingDirector.getInstance().shutdown();
162     }
163
164     
165 }
166
Popular Tags