1 45 package org.openejb.test.entity.cmp; 46 47 import java.rmi.RemoteException ; 48 import java.util.StringTokenizer ; 49 50 import javax.ejb.EJBException ; 51 import javax.ejb.EntityContext ; 52 import javax.ejb.RemoveException ; 53 import javax.naming.InitialContext ; 54 55 import junit.framework.Assert; 56 import junit.framework.AssertionFailedError; 57 58 import org.openejb.test.TestFailureException; 59 import org.openejb.test.stateful.BasicStatefulHome; 60 import org.openejb.test.stateful.BasicStatefulObject; 61 import org.openejb.test.stateless.BasicStatelessHome; 62 import org.openejb.test.stateless.BasicStatelessObject; 63 64 69 public class EncCmpBean implements javax.ejb.EntityBean { 70 71 public static int key = 20; 72 73 public int primaryKey; 74 public String firstName; 75 public String lastName; 76 public EntityContext ejbContext; 77 78 82 90 public Integer ejbCreate(String name) 91 throws javax.ejb.CreateException { 92 StringTokenizer st = new StringTokenizer (name, " "); 93 firstName = st.nextToken(); 94 lastName = st.nextToken(); 95 this.primaryKey = key++; 96 return null; 97 } 98 99 public void ejbPostCreate(String name) 100 throws javax.ejb.CreateException { 101 } 102 103 104 108 109 113 114 public void lookupEntityBean() throws TestFailureException{ 115 try{ 116 try{ 117 InitialContext ctx = new InitialContext (); 118 Assert.assertNotNull("The InitialContext is null", ctx ); 119 120 BasicCmpHome home = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/cmp/beanReferences/cmp_entity"), BasicCmpHome.class ); 121 Assert.assertNotNull("The EJBHome looked up is null",home); 122 123 BasicCmpObject object = home.create("Enc Bean"); 124 Assert.assertNotNull("The EJBObject is null", object ); 125 } catch (Exception e){ 126 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 127 } 128 } catch (AssertionFailedError afe){ 129 throw new TestFailureException(afe); 130 } 131 } 132 133 public void lookupStatefulBean() throws TestFailureException{ 134 try{ 135 try{ 136 InitialContext ctx = new InitialContext (); 137 Assert.assertNotNull("The InitialContext is null", ctx ); 138 139 BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/cmp/beanReferences/stateful"), BasicStatefulHome.class ); 140 Assert.assertNotNull("The EJBHome looked up is null",home); 141 142 BasicStatefulObject object = home.create("Enc Bean"); 143 Assert.assertNotNull("The EJBObject is null", object ); 144 } catch (Exception e){ 145 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 146 } 147 } catch (AssertionFailedError afe){ 148 throw new TestFailureException(afe); 149 } 150 } 151 152 public void lookupStatelessBean() throws TestFailureException{ 153 try{ 154 try{ 155 InitialContext ctx = new InitialContext (); 156 Assert.assertNotNull("The InitialContext is null", ctx ); 157 158 BasicStatelessHome home = (BasicStatelessHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/cmp/beanReferences/stateless"), BasicStatelessHome.class ); 159 Assert.assertNotNull("The EJBHome looked up is null",home); 160 161 BasicStatelessObject object = home.create(); 162 Assert.assertNotNull("The EJBObject is null", object ); 163 } catch (Exception e){ 164 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 165 } 166 } catch (AssertionFailedError afe){ 167 throw new TestFailureException(afe); 168 } 169 } 170 171 public void lookupStringEntry() throws TestFailureException{ 172 try{ 173 try{ 174 InitialContext ctx = new InitialContext (); 175 Assert.assertNotNull("The InitialContext is null", ctx ); 176 177 String expected = new String ("1"); 178 String actual = (String )ctx.lookup("java:comp/env/entity/cmp/references/String"); 179 180 Assert.assertNotNull("The String looked up is null", actual ); 181 Assert.assertEquals(expected, actual ); 182 183 } catch (Exception e){ 184 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 185 } 186 } catch (AssertionFailedError afe){ 187 throw new TestFailureException(afe); 188 } 189 } 190 191 public void lookupDoubleEntry() throws TestFailureException{ 192 try{ 193 try{ 194 InitialContext ctx = new InitialContext (); 195 Assert.assertNotNull("The InitialContext is null", ctx ); 196 197 Double expected = new Double (1.0D); 198 Double actual = (Double )ctx.lookup("java:comp/env/entity/cmp/references/Double"); 199 200 Assert.assertNotNull("The Double looked up is null", actual ); 201 Assert.assertEquals(expected, actual ); 202 203 } catch (Exception e){ 204 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 205 } 206 } catch (AssertionFailedError afe){ 207 throw new TestFailureException(afe); 208 } 209 } 210 211 public void lookupLongEntry() throws TestFailureException{ 212 try{ 213 try{ 214 InitialContext ctx = new InitialContext (); 215 Assert.assertNotNull("The InitialContext is null", ctx ); 216 217 Long expected = new Long (1L); 218 Long actual = (Long )ctx.lookup("java:comp/env/entity/cmp/references/Long"); 219 220 Assert.assertNotNull("The Long looked up is null", actual ); 221 Assert.assertEquals(expected, actual ); 222 223 } catch (Exception e){ 224 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 225 } 226 } catch (AssertionFailedError afe){ 227 throw new TestFailureException(afe); 228 } 229 } 230 231 public void lookupFloatEntry() throws TestFailureException{ 232 try{ 233 try{ 234 InitialContext ctx = new InitialContext (); 235 Assert.assertNotNull("The InitialContext is null", ctx ); 236 237 Float expected = new Float (1.0F); 238 Float actual = (Float )ctx.lookup("java:comp/env/entity/cmp/references/Float"); 239 240 Assert.assertNotNull("The Float looked up is null", actual ); 241 Assert.assertEquals(expected, actual ); 242 243 } catch (Exception e){ 244 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 245 } 246 } catch (AssertionFailedError afe){ 247 throw new TestFailureException(afe); 248 } 249 } 250 251 public void lookupIntegerEntry() throws TestFailureException{ 252 try{ 253 try{ 254 InitialContext ctx = new InitialContext (); 255 Assert.assertNotNull("The InitialContext is null", ctx ); 256 257 Integer expected = new Integer (1); 258 Integer actual = (Integer )ctx.lookup("java:comp/env/entity/cmp/references/Integer"); 259 260 Assert.assertNotNull("The Integer looked up is null", actual ); 261 Assert.assertEquals(expected, actual ); 262 263 } catch (Exception e){ 264 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 265 } 266 } catch (AssertionFailedError afe){ 267 throw new TestFailureException(afe); 268 } 269 } 270 271 public void lookupShortEntry() throws TestFailureException{ 272 try{ 273 try{ 274 InitialContext ctx = new InitialContext (); 275 Assert.assertNotNull("The InitialContext is null", ctx ); 276 277 Short expected = new Short ((short)1); 278 Short actual = (Short )ctx.lookup("java:comp/env/entity/cmp/references/Short"); 279 280 Assert.assertNotNull("The Short looked up is null", actual ); 281 Assert.assertEquals(expected, actual ); 282 283 } catch (Exception e){ 284 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 285 } 286 } catch (AssertionFailedError afe){ 287 throw new TestFailureException(afe); 288 } 289 } 290 291 public void lookupBooleanEntry() throws TestFailureException{ 292 try{ 293 try{ 294 InitialContext ctx = new InitialContext (); 295 Assert.assertNotNull("The InitialContext is null", ctx ); 296 297 Boolean expected = new Boolean (true); 298 Boolean actual = (Boolean )ctx.lookup("java:comp/env/entity/cmp/references/Boolean"); 299 300 Assert.assertNotNull("The Boolean looked up is null", actual ); 301 Assert.assertEquals(expected, actual ); 302 303 } catch (Exception e){ 304 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 305 } 306 } catch (AssertionFailedError afe){ 307 throw new TestFailureException(afe); 308 } 309 } 310 311 public void lookupByteEntry() throws TestFailureException{ 312 try{ 313 try{ 314 InitialContext ctx = new InitialContext (); 315 Assert.assertNotNull("The InitialContext is null", ctx ); 316 317 Byte expected = new Byte ((byte)1); 318 Byte actual = (Byte )ctx.lookup("java:comp/env/entity/cmp/references/Byte"); 319 320 Assert.assertNotNull("The Byte looked up is null", actual ); 321 Assert.assertEquals(expected, actual ); 322 323 } catch (Exception e){ 324 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 325 } 326 } catch (AssertionFailedError afe){ 327 throw new TestFailureException(afe); 328 } 329 } 330 331 public void lookupResource() throws TestFailureException{ 332 try{ 333 try{ 334 InitialContext ctx = new InitialContext (); 335 Assert.assertNotNull("The InitialContext is null", ctx ); 336 } catch (Exception e){ 337 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage()); 338 } 339 } catch (AssertionFailedError afe){ 340 throw new TestFailureException(afe); 341 } 342 } 343 347 348 352 357 public void ejbLoad() throws EJBException ,RemoteException { 358 } 359 360 364 public void setEntityContext(EntityContext ctx) throws EJBException ,RemoteException { 365 ejbContext = ctx; 366 } 367 368 372 public void unsetEntityContext() throws EJBException ,RemoteException { 373 } 374 375 380 public void ejbStore() throws EJBException ,RemoteException { 381 } 382 383 391 public void ejbRemove() throws RemoveException ,EJBException ,RemoteException { 392 } 393 394 400 public void ejbActivate() throws EJBException ,RemoteException { 401 } 402 403 409 public void ejbPassivate() throws EJBException ,RemoteException { 410 } 411 } 415 | Popular Tags |