1 45 package org.openejb.test.stateless; 46 47 import java.rmi.RemoteException ; 48 49 import javax.ejb.EJBException ; 50 import javax.ejb.SessionContext ; 51 import javax.naming.InitialContext ; 52 53 import junit.framework.Assert; 54 import junit.framework.AssertionFailedError; 55 56 import org.openejb.test.TestFailureException; 57 import org.openejb.test.entity.bmp.BasicBmpHome; 58 import org.openejb.test.entity.bmp.BasicBmpObject; 59 import org.openejb.test.stateful.BasicStatefulHome; 60 import org.openejb.test.stateful.BasicStatefulObject; 61 62 67 public class EncStatelessBean implements javax.ejb.SessionBean { 68 69 private String name; 70 private SessionContext ejbContext; 71 72 73 80 81 public void lookupEntityBean() throws TestFailureException{ 85 try{ 86 try{ 87 InitialContext ctx = new InitialContext (); 88 Assert.assertNotNull("The InitialContext is null", ctx ); 89 90 BasicBmpHome home = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/bmp_entity"), BasicBmpHome.class ); 91 Assert.assertNotNull("The EJBHome looked up is null",home); 92 93 BasicBmpObject object = home.create("Enc Bean"); 94 Assert.assertNotNull("The EJBObject is null", object ); 95 } catch (Exception e){ 96 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 97 } 98 } catch (AssertionFailedError afe){ 99 throw new TestFailureException(afe); 100 } 101 } 102 103 public void lookupStatefulBean() throws TestFailureException{ 104 try{ 105 try{ 106 InitialContext ctx = new InitialContext (); 107 Assert.assertNotNull("The InitialContext is null", ctx ); 108 109 BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateful"), BasicStatefulHome.class ); 110 Assert.assertNotNull("The EJBHome looked up is null",home); 111 112 BasicStatefulObject object = home.create("Enc Bean"); 113 Assert.assertNotNull("The EJBObject is null", object ); 114 } catch (Exception e){ 115 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 116 } 117 } catch (AssertionFailedError afe){ 118 throw new TestFailureException(afe); 119 } 120 } 121 122 public void lookupStatelessBean() throws TestFailureException{ 123 try{ 124 try{ 125 InitialContext ctx = new InitialContext (); 126 Assert.assertNotNull("The InitialContext is null", ctx ); 127 128 BasicStatelessHome home = (BasicStatelessHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateless"), BasicStatelessHome.class ); 129 Assert.assertNotNull("The EJBHome looked up is null",home); 130 131 BasicStatelessObject object = home.create(); 132 Assert.assertNotNull("The EJBObject is null", object ); 133 } catch (Exception e){ 134 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 135 } 136 } catch (AssertionFailedError afe){ 137 throw new TestFailureException(afe); 138 } 139 } 140 141 public void lookupStringEntry() throws TestFailureException{ 142 try{ 143 try{ 144 InitialContext ctx = new InitialContext (); 145 Assert.assertNotNull("The InitialContext is null", ctx ); 146 147 String expected = new String ("1"); 148 String actual = (String )ctx.lookup("java:comp/env/stateless/references/String"); 149 150 Assert.assertNotNull("The String looked up is null", actual ); 151 Assert.assertEquals(expected, actual ); 152 153 } catch (Exception e){ 154 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 155 } 156 } catch (AssertionFailedError afe){ 157 throw new TestFailureException(afe); 158 } 159 } 160 161 public void lookupDoubleEntry() throws TestFailureException{ 162 try{ 163 try{ 164 InitialContext ctx = new InitialContext (); 165 Assert.assertNotNull("The InitialContext is null", ctx ); 166 167 Double expected = new Double (1.0D); 168 Double actual = (Double )ctx.lookup("java:comp/env/stateless/references/Double"); 169 170 Assert.assertNotNull("The Double looked up is null", actual ); 171 Assert.assertEquals(expected, actual ); 172 173 } catch (Exception e){ 174 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 175 } 176 } catch (AssertionFailedError afe){ 177 throw new TestFailureException(afe); 178 } 179 } 180 181 public void lookupLongEntry() throws TestFailureException{ 182 try{ 183 try{ 184 InitialContext ctx = new InitialContext (); 185 Assert.assertNotNull("The InitialContext is null", ctx ); 186 187 Long expected = new Long (1L); 188 Long actual = (Long )ctx.lookup("java:comp/env/stateless/references/Long"); 189 190 Assert.assertNotNull("The Long looked up is null", actual ); 191 Assert.assertEquals(expected, actual ); 192 193 } catch (Exception e){ 194 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 195 } 196 } catch (AssertionFailedError afe){ 197 throw new TestFailureException(afe); 198 } 199 } 200 201 public void lookupFloatEntry() throws TestFailureException{ 202 try{ 203 try{ 204 InitialContext ctx = new InitialContext (); 205 Assert.assertNotNull("The InitialContext is null", ctx ); 206 207 Float expected = new Float (1.0F); 208 Float actual = (Float )ctx.lookup("java:comp/env/stateless/references/Float"); 209 210 Assert.assertNotNull("The Float looked up is null", actual ); 211 Assert.assertEquals(expected, actual ); 212 213 } catch (Exception e){ 214 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 215 } 216 } catch (AssertionFailedError afe){ 217 throw new TestFailureException(afe); 218 } 219 } 220 221 public void lookupIntegerEntry() throws TestFailureException{ 222 try{ 223 try{ 224 InitialContext ctx = new InitialContext (); 225 Assert.assertNotNull("The InitialContext is null", ctx ); 226 227 Integer expected = new Integer (1); 228 Integer actual = (Integer )ctx.lookup("java:comp/env/stateless/references/Integer"); 229 230 Assert.assertNotNull("The Integer looked up is null", actual ); 231 Assert.assertEquals(expected, actual ); 232 233 } catch (Exception e){ 234 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 235 } 236 } catch (AssertionFailedError afe){ 237 throw new TestFailureException(afe); 238 } 239 } 240 241 public void lookupShortEntry() throws TestFailureException{ 242 try{ 243 try{ 244 InitialContext ctx = new InitialContext (); 245 Assert.assertNotNull("The InitialContext is null", ctx ); 246 247 Short expected = new Short ((short)1); 248 Short actual = (Short )ctx.lookup("java:comp/env/stateless/references/Short"); 249 250 Assert.assertNotNull("The Short looked up is null", actual ); 251 Assert.assertEquals(expected, actual ); 252 253 } catch (Exception e){ 254 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 255 } 256 } catch (AssertionFailedError afe){ 257 throw new TestFailureException(afe); 258 } 259 } 260 261 public void lookupBooleanEntry() throws TestFailureException{ 262 try{ 263 try{ 264 InitialContext ctx = new InitialContext (); 265 Assert.assertNotNull("The InitialContext is null", ctx ); 266 267 Boolean expected = new Boolean (true); 268 Boolean actual = (Boolean )ctx.lookup("java:comp/env/stateless/references/Boolean"); 269 270 Assert.assertNotNull("The Boolean looked up is null", actual ); 271 Assert.assertEquals(expected, actual ); 272 273 } catch (Exception e){ 274 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 275 } 276 } catch (AssertionFailedError afe){ 277 throw new TestFailureException(afe); 278 } 279 } 280 281 public void lookupByteEntry() throws TestFailureException{ 282 try{ 283 try{ 284 InitialContext ctx = new InitialContext (); 285 Assert.assertNotNull("The InitialContext is null", ctx ); 286 287 Byte expected = new Byte ((byte)1); 288 Byte actual = (Byte )ctx.lookup("java:comp/env/stateless/references/Byte"); 289 290 Assert.assertNotNull("The Byte looked up is null", actual ); 291 Assert.assertEquals(expected, actual ); 292 293 } catch (Exception e){ 294 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 295 } 296 } catch (AssertionFailedError afe){ 297 throw new TestFailureException(afe); 298 } 299 } 300 301 public void lookupResource() throws TestFailureException{ 302 try{ 303 try{ 304 InitialContext ctx = new InitialContext (); 305 Assert.assertNotNull("The InitialContext is null", ctx ); 306 } catch (Exception e){ 307 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 308 } 309 } catch (AssertionFailedError afe){ 310 throw new TestFailureException(afe); 311 } 312 } 313 314 318 319 326 public void setSessionContext(SessionContext ctx) throws EJBException ,RemoteException { 327 ejbContext = ctx; 328 } 329 334 public void ejbCreate() throws javax.ejb.CreateException { 335 this.name = "nameless automaton"; 336 } 337 343 public void ejbRemove() throws EJBException ,RemoteException { 344 } 345 346 351 public void ejbActivate() throws EJBException ,RemoteException { 352 } 354 359 public void ejbPassivate() throws EJBException ,RemoteException { 360 } 362 363 } 367 | Popular Tags |