KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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