1 45 package org.exolab.jms.net.invoke; 46 47 import java.util.HashMap ; 48 import java.util.Map ; 49 50 import org.apache.commons.logging.Log; 51 import org.apache.commons.logging.LogFactory; 52 import junit.framework.TestCase; 53 54 import org.exolab.jms.common.security.BasicPrincipal; 55 import org.exolab.jms.net.connector.Authenticator; 56 import org.exolab.jms.net.orb.ORB; 57 import org.exolab.jms.net.orb.ORBFactory; 58 import org.exolab.jms.net.registry.Registry; 59 import org.exolab.jms.net.util.SSLUtil; 60 61 62 69 public abstract class ORBTestCase extends TestCase { 70 71 74 private ORB _orb; 75 76 79 private ORB _client; 80 81 84 private String _uri; 85 86 89 private String _routeURI; 90 91 95 private final Map _connectionProps; 96 97 101 private final Map _acceptorProps; 102 103 106 private static final Log _log = LogFactory.getLog(ORBTestCase.class); 107 108 109 115 public ORBTestCase(String name, String uri) { 116 this(name, uri, null, null); 117 } 118 119 126 public ORBTestCase(String name, String uri, Map properties) { 127 this(name, uri, null, properties); 128 } 129 130 137 public ORBTestCase(String name, String uri, String routeURI) { 138 this(name, uri, routeURI, null, null); 139 } 140 141 149 public ORBTestCase(String name, String uri, String routeURI, 150 Map properties) { 151 this(name, uri, routeURI, properties, properties); 152 } 153 154 163 public ORBTestCase(String name, String uri, String routeURI, 164 Map connectionProps, Map acceptorProps) { 165 super(name); 166 _uri = uri; 167 _routeURI = routeURI; 168 _connectionProps = connectionProps; 169 _acceptorProps = acceptorProps; 170 } 171 172 180 protected Map getConnectionProperties(BasicPrincipal principal) 181 throws Exception { 182 Map properties = getConnectionProperties(); 183 if (principal != null) { 184 properties.put(ORB.SECURITY_PRINCIPAL, principal.getName()); 185 properties.put(ORB.SECURITY_CREDENTIALS, principal.getPassword()); 186 } 187 return properties; 188 } 189 190 198 protected Map getConnectionProperties() throws Exception { 199 Map properties = new HashMap (); 200 properties.put(ORB.PROVIDER_URI, getServerURI()); 201 if (_connectionProps != null) { 202 properties.putAll(_connectionProps); 203 } 204 return properties; 205 } 206 207 213 protected Map getClientProperties() { 214 return null; 215 } 216 217 224 protected Map getAcceptorProperties() throws Exception { 225 Map properties = new HashMap (); 226 properties.put(ORB.PROVIDER_URI, _uri); 227 if (_acceptorProps != null) { 228 properties.putAll(_acceptorProps); 229 } else if (_connectionProps != null) { 230 properties.putAll(_connectionProps); 231 } 232 return properties; 233 } 234 235 241 protected synchronized ORB getORB() throws Exception { 242 if (_orb == null) { 243 createORB(null); 244 } 245 return _orb; 246 } 247 248 254 protected synchronized ORB createORB(Authenticator authenticator) 255 throws Exception { 256 if (authenticator != null) { 257 _orb 258 = ORBFactory.createORB(authenticator, 259 getAcceptorProperties()); 260 } else { 261 _orb = ORBFactory.createORB(getAcceptorProperties()); 262 } 263 if (_routeURI != null) { 264 _orb.addRoute(_uri, _routeURI); 265 } 266 return _orb; 267 } 268 269 274 protected String getExportURI() { 275 return _uri; 276 } 277 278 283 protected String getServerURI() { 284 return (_routeURI != null) ? _routeURI : _uri; 285 } 286 287 292 protected ORB getClientORB() { 293 return _client; 294 } 295 296 303 protected Registry getRegistry(BasicPrincipal principal) 304 throws Exception { 305 return _client.getRegistry(getConnectionProperties(principal)); 306 } 307 308 313 protected Registry getRegistry() throws Exception { 314 return _client.getRegistry(getConnectionProperties()); 315 } 316 317 322 protected void setUp() throws Exception { 323 _log.debug("setUp() [test=" + getName() + ", URI=" + _uri + "]"); 324 325 _client = ORBFactory.createORB(getClientProperties()); 327 } 328 329 334 protected void tearDown() throws Exception { 335 _log.debug("tearDown() [test=" + getName() + ", URI=" + _uri + "]"); 336 if (_orb != null) { 337 _orb.shutdown(); 338 } 339 _client.shutdown(); 340 341 SSLUtil.clearProperties(); 343 } 344 345 } 346 | Popular Tags |