1 17 18 package org.sape.carbon.services.ejb.remote.test; 19 20 21 import javax.ejb.EJBHome ; 22 import javax.naming.Context ; 23 import javax.naming.NamingException ; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 29 import org.sape.carbon.core.component.Lookup; 30 import org.sape.carbon.core.config.Config; 31 32 import org.sape.carbon.services.ejb.HomeFactoryException; 33 import org.sape.carbon.services.ejb.remote.RemoteHomeFactory; 34 import org.sape.carbon.services.jndi.InitialContextFactory; 35 import org.sape.carbon.services.jndi.InitialContextFactoryConfiguration; 36 37 public class RemoteHomeFactoryTest extends TestCase { 38 39 42 public static final String TEST_REMOTE_HOME_FACTORY = 43 "/ejb/test/RemoteHomeFactoryTest"; 44 45 46 49 public static final String TEST_RMIIIOP_DISABLED_HOME_FACTORY = 50 "/ejb/test/RmiIiopDisabledRemoteHomeFactoryTest"; 51 52 56 public static final String TEST_MISCAST_HOME_FACTORY = 57 "/ejb/test/MiscastRemoteHomeFactoryTest"; 58 59 62 public static final String TEST_INITIAL_CONTEXT_FACTORY = 63 "/ejb/test/TestInitialContextFactory"; 64 65 66 69 public static final String TEST_REMOTE_EJB = 70 "org.sape.carbon.services.ejb.remote.test.Tester"; 71 72 73 77 public static final String TEST_NONEXISTANT_EJB = 78 "org.sape.carbon.services.ejb.test.Nonexistant"; 79 80 81 public RemoteHomeFactoryTest(String name) { 82 super(name); 83 } 84 85 86 public static void main(String args[]) throws Exception { 87 } 88 89 90 95 public void testRemoteHomeFactoryClassCastException() { 96 97 EJBHome ejbHome = null; 98 99 try { 101 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 102 Lookup.getInstance().fetchComponent(TEST_MISCAST_HOME_FACTORY); 103 104 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB); 105 106 fail("Lookup for: " 107 + TEST_REMOTE_EJB 108 + " failed to intercept HomeFactoryClassCastException"); 109 } catch (HomeFactoryException hfe) { 110 } 112 } 113 114 115 119 public void testRemoteHomeFactoryNamingException() { 120 121 EJBHome ejbHome = null; 122 123 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 124 Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY); 125 126 try { 128 129 ejbHome = homeFactory.lookup(TEST_NONEXISTANT_EJB); 130 131 fail("Lookup for: " 132 + TEST_NONEXISTANT_EJB 133 + " failed to intercept HomeFactoryNamingException"); 134 } catch (HomeFactoryException hfe) { 135 } 137 } 138 139 140 143 public void testRemoteHomeFactoryLookup() throws Exception { 144 145 TesterHome ejbHome = null; 146 147 try { 148 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 149 Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY); 150 151 ejbHome = (TesterHome) homeFactory.lookup(TEST_REMOTE_EJB); 152 153 ejbHome.create().testMe(); 154 } catch (HomeFactoryException hfe) { 155 fail("Failed to lookup home interface for EJB with logical name: " 156 + TEST_REMOTE_EJB 157 + " due to: " 158 + hfe); 159 } 160 } 161 162 163 167 public void testRemoteHomeFactoryLookupWithoutRmiIiop() { 168 169 EJBHome ejbHome = null; 170 171 try { 172 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 173 Lookup.getInstance().fetchComponent( 174 TEST_RMIIIOP_DISABLED_HOME_FACTORY); 175 176 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB); 177 } catch (HomeFactoryException hfe) { 178 fail("Failed to lookup home interface for EJB with logical name: " 179 + TEST_REMOTE_EJB 180 + " due to: " 181 + hfe); 182 } 183 } 184 185 186 190 public void testRemoteHomeFactoryLookupWithContext() { 191 192 EJBHome ejbHome = null; 193 194 try { 195 InitialContextFactory factory = (InitialContextFactory) 196 Lookup.getInstance().fetchComponent(TEST_INITIAL_CONTEXT_FACTORY); 197 Context context = factory.getContext(); 198 199 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 200 Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY); 201 202 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB, context); 203 } catch (HomeFactoryException hfe) { 204 fail("Failed to lookup home interface for EJB with logical name: " 205 + TEST_REMOTE_EJB 206 + " due to: " 207 + hfe); 208 } catch (NamingException ne) { 209 fail("Failed to lookup home interface for EJB with logical name: " 210 + TEST_REMOTE_EJB 211 + " due to: " 212 + ne); 213 } 214 } 215 216 217 221 public void testRemoteHomeFactoryLookupWithCredentials() { 222 223 EJBHome ejbHome = null; 224 225 try { 226 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 227 Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY); 228 229 InitialContextFactoryConfiguration factoryConfig = 230 (InitialContextFactoryConfiguration) 231 Config.getInstance().fetchConfiguration(TEST_INITIAL_CONTEXT_FACTORY); 232 233 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB, 234 factoryConfig.getEnvironment(Context.SECURITY_PRINCIPAL), 235 factoryConfig.getEnvironment(Context.SECURITY_CREDENTIALS)); 236 237 } catch (HomeFactoryException hfe) { 238 fail("Failed to lookup home interface for EJB with logical name: " 239 + TEST_REMOTE_EJB 240 + " due to: " 241 + hfe); 242 } 243 } 244 245 246 250 public static Test suite() { 251 252 TestSuite test = new TestSuite(); 253 254 test.addTest(new RemoteHomeFactoryTest( 255 "testRemoteHomeFactoryClassCastException")); 256 test.addTest(new RemoteHomeFactoryTest( 257 "testRemoteHomeFactoryNamingException")); 258 test.addTest(new RemoteHomeFactoryTest( 259 "testRemoteHomeFactoryLookup")); 260 test.addTest(new RemoteHomeFactoryTest( 261 "testRemoteHomeFactoryLookupWithoutRmiIiop")); 262 test.addTest(new RemoteHomeFactoryTest( 263 "testRemoteHomeFactoryLookupWithContext")); 264 test.addTest(new RemoteHomeFactoryTest( 265 "testRemoteHomeFactoryLookupWithCredentials")); 266 267 return test; 268 } 269 } 270 | Popular Tags |