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