KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > webservice > WebServiceManagerTest


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

23
24 package com.rift.coad.lib.deployment.webservice;
25
26 // java imports
27
import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 // axis includes
34
import org.apache.axis.AxisEngine;
35 import org.apache.axis.server.AxisServer;
36 import org.apache.axis.management.ServiceAdmin;
37 import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
38 import org.apache.axis.EngineConfiguration;
39
40 // junit imports
41
import junit.framework.*;
42
43 // coadunation imports
44
import com.rift.coad.lib.thirdparty.axis.AxisManager;
45 import com.rift.coad.lib.deployment.DeploymentLoader;
46 import com.rift.coad.lib.deployment.DeploymentLoader;
47 import com.rift.coad.lib.thirdparty.axis.AxisManager;
48 import com.rift.coad.lib.interceptor.InterceptorFactory;
49 import com.rift.coad.lib.naming.NamingDirector;
50 import com.rift.coad.lib.security.RoleManager;
51 import com.rift.coad.lib.security.SessionManager;
52 import com.rift.coad.lib.security.ThreadPermissionSession;
53 import com.rift.coad.lib.security.ThreadsPermissionContainer;
54 import com.rift.coad.lib.security.UserSession;
55 import com.rift.coad.lib.security.login.LoginManager;
56 import com.rift.coad.lib.security.user.UserSessionManager;
57 import com.rift.coad.lib.security.user.UserStoreManager;
58 import com.rift.coad.lib.thread.CoadunationThreadGroup;
59 import com.rift.coad.lib.transaction.TransactionDirector;
60
61 /**
62  *
63  * @author Brett Chaldecott
64  */

65 public class WebServiceManagerTest extends TestCase {
66     
67     public WebServiceManagerTest(String JavaDoc testName) {
68         super(testName);
69     }
70
71     protected void setUp() throws Exception JavaDoc {
72     }
73
74     protected void tearDown() throws Exception JavaDoc {
75     }
76
77     public static Test suite() {
78         TestSuite suite = new TestSuite(WebServiceManagerTest.class);
79         
80         return suite;
81     }
82
83     /**
84      * Test of class com.rift.coad.lib.deployment.webservice.WebServiceManager.
85      */

86     public void testWebServiceManager() throws Exception JavaDoc {
87         System.out.println("testWebServiceManager");
88         
89         // init the session information
90
ThreadsPermissionContainer permissions = new ThreadsPermissionContainer();
91         SessionManager.init(permissions);
92         UserStoreManager userStoreManager = new UserStoreManager();
93         UserSessionManager sessionManager = new UserSessionManager(permissions,
94                 userStoreManager);
95         LoginManager.init(sessionManager,userStoreManager);
96         // instanciate the thread manager
97
CoadunationThreadGroup threadGroup = new CoadunationThreadGroup(sessionManager,
98             userStoreManager);
99         
100         // add a user to the session for the current thread
101
RoleManager.getInstance();
102         
103         InterceptorFactory.init(permissions,sessionManager,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         permissions.putSession(new Long JavaDoc(Thread.currentThread().getId()),
110                 new ThreadPermissionSession(
111                 new Long JavaDoc(Thread.currentThread().getId()),user));
112         
113         // init the naming director
114
NamingDirector.init(threadGroup);
115         
116         // instanciate the transaction director
117
TransactionDirector transactionDirector = TransactionDirector.init();
118         
119         // instanciate the deployment loader
120
DeploymentLoader deploymentLoader = new DeploymentLoader(
121                 new java.io.File JavaDoc(System.getProperty("test.jar")));
122         
123         // instanciate the axis engine
124
AxisManager.init();
125         
126         // instanciate the web service manager
127
WebServiceManager instance = new WebServiceManager();
128         
129         // load the files
130
instance.load(deploymentLoader);
131         
132         // retrieve the keys
133
Set JavaDoc paths = instance.getServices();
134         if (paths.size() != 1) {
135             fail("There should be one path there are [" + paths.size() + "]");
136         }
137         
138         if (paths.contains("/WebServiceTest") == false) {
139             fail("There should be one path [/WebServiceTest]");
140         }
141         
142         // retrieve the service reference
143
if (instance.getService("/WebServiceTest") == null) {
144             fail("Failed to retrieve the service reference.");
145         }
146         
147         // unload the service
148
instance.unLoad(deploymentLoader);
149         
150         paths = instance.getServices();
151         if (paths.size() != 0) {
152             fail("There should be zero paths there are [" + paths.size() + "]");
153         }
154     }
155     
156 }
157
Popular Tags