1 22 package org.jboss.ejb3.test.reference21_30.unit; 23 24 import javax.ejb.EJBException ; 25 import javax.ejb.EJBHome ; 26 import javax.ejb.EJBMetaData ; 27 import javax.ejb.EJBObject ; 28 import javax.ejb.Handle ; 29 import javax.ejb.HomeHandle ; 30 import javax.naming.InitialContext ; 31 import org.jboss.ejb3.test.reference21_30.Session21; 32 import org.jboss.ejb3.test.reference21_30.Session30; 33 import org.jboss.ejb3.test.reference21_30.Session30Home; 34 import org.jboss.ejb3.test.reference21_30.StatefulSession30; 35 import org.jboss.ejb3.test.reference21_30.StatefulSession30Home; 36 import org.jboss.logging.Logger; 37 import org.jboss.test.JBossTestCase; 38 import junit.framework.Test; 39 40 46 public class ReferenceTestCase 47 extends JBossTestCase { 48 49 private static final Logger log = Logger 50 .getLogger(ReferenceTestCase.class); 51 52 public ReferenceTestCase(String name) 53 { 54 super(name); 55 } 56 57 public void testSession21() throws Exception 58 { 59 InitialContext jndiContext = new InitialContext (); 60 61 Session21 session = (Session21)jndiContext.lookup("Session21"); 62 String access = session.access(); 63 assertEquals("Session21", access); 64 access = session.access30(); 65 assertEquals("Session30", access); 66 } 67 68 public void testSession30() throws Exception 69 { 70 InitialContext jndiContext = new InitialContext (); 71 72 Session30 session = (Session30) jndiContext.lookup("Session30"); 73 String access = session.access(); 74 assertEquals("Session30", access); 75 access = session.access21(); 76 assertEquals("Session21", access); 77 } 78 79 public void testSessionHome30() throws Exception 80 { 81 InitialContext jndiContext = new InitialContext (); 82 83 Session30 session = (Session30) jndiContext.lookup("Session30"); 84 assertNotNull(session); 85 String access = session.access(); 86 assertEquals("Session30", access); 87 88 Session30Home home = (Session30Home) jndiContext.lookup("Session30Home"); 89 assertNotNull(home); 90 session = (Session30)home.create(); 91 assertNotNull(session); 92 access = session.access(); 93 assertEquals("Session30", access); 94 } 95 96 public void testStatefulRemove() throws Exception 97 { 98 InitialContext jndiContext = new InitialContext (); 99 100 StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home"); 101 assertNotNull(home); 102 StatefulSession30 session = (StatefulSession30)home.create(); 103 assertNotNull(session); 104 session.setValue("123"); 105 String value = session.getValue(); 106 assertEquals("123", value); 107 108 EJBObject ejbObject = (EJBObject )session; 109 110 Handle handle = session.getHandle(); 111 assertNotNull(handle); 112 113 home.remove(handle); 114 115 try { 116 session.getValue(); 117 assertTrue(false); 118 } catch (EJBException e) 119 { 120 assertTrue(e instanceof EJBException ); 121 } 122 123 session = (StatefulSession30)home.create(); 124 assertNotNull(session); 125 session.setValue("123"); 126 value = session.getValue(); 127 assertEquals("123", value); 128 129 session.remove(); 130 131 try { 132 session.getValue(); 133 assertTrue(false); 134 } catch (EJBException e) 135 { 136 assertTrue(e instanceof EJBException ); 137 } 138 } 139 140 public void testStatefulSessionHome30() throws Exception 141 { 142 InitialContext jndiContext = new InitialContext (); 143 144 StatefulSession30 session = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 145 assertNotNull(session); 146 session.setValue("testing"); 147 String value = session.getValue(); 148 assertEquals("testing", value); 149 150 StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home"); 151 assertNotNull(home); 152 session = (StatefulSession30)home.create(); 153 assertNotNull(session); 154 session.setValue("123"); 155 value = session.getValue(); 156 assertEquals("123", value); 157 158 session = (StatefulSession30)home.create("456"); 159 assertNotNull(session); 160 value = session.getValue(); 161 assertEquals("456", value); 162 163 session = (StatefulSession30)home.create("combined", new Integer ("789")); 164 assertNotNull(session); 165 value = session.getValue(); 166 assertEquals("combined789", value); 167 } 168 169 public void testRemoteHomeAnnotation() throws Exception 170 { 171 InitialContext jndiContext = new InitialContext (); 172 173 StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("HomedStatefulSession30Home"); 174 assertNotNull(home); 175 StatefulSession30 session = (StatefulSession30)home.create(); 176 assertNotNull(session); 177 session.setValue("123"); 178 String value = session.getValue(); 179 assertEquals("123", value); 180 181 session = (StatefulSession30)home.create("456"); 182 assertNotNull(session); 183 value = session.getValue(); 184 assertEquals("456", value); 185 186 session = (StatefulSession30)home.create("combined", new Integer ("789")); 187 assertNotNull(session); 188 value = session.getValue(); 189 assertEquals("combined789", value); 190 } 191 192 public void testLocalHomeAnnotation() throws Exception 193 { 194 InitialContext jndiContext = new InitialContext (); 195 196 StatefulSession30 session = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 197 198 String access = session.accessLocalHome(); 199 assertEquals("LocalHome", access); 200 } 201 202 public void testLocalHome() throws Exception 203 { 204 InitialContext jndiContext = new InitialContext (); 205 206 StatefulSession30 statefulSession = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 207 assertNotNull(statefulSession); 208 String access = statefulSession.accessLocalStateless(); 209 assertEquals("Session30", access); 210 211 Session30 session = (Session30) jndiContext.lookup("Session30"); 212 assertNotNull(session); 213 access = session.accessLocalStateful(); 214 assertEquals("default", access); 215 216 access = session.accessLocalStateful("testing"); 217 assertEquals("testing", access); 218 219 access = session.accessLocalStateful("testing", new Integer (123)); 220 assertEquals("testing123", access); 221 } 222 223 public void testStatefulState() throws Exception 224 { 225 InitialContext jndiContext = new InitialContext (); 226 227 StatefulSession30 session1 = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 228 assertNotNull(session1); 229 session1.setValue("testing"); 230 assertEquals("testing", session1.getValue()); 231 232 StatefulSession30 session2 = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 233 assertNotNull(session2); 234 assertEquals("default", session2.getValue()); 235 236 StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home"); 237 assertNotNull(home); 238 StatefulSession30 session3 = (StatefulSession30)home.create(); 239 assertNotNull(session3); 240 session3.setValue("123"); 241 assertEquals("123", session3.getValue()); 242 243 StatefulSession30 session4 = (StatefulSession30)home.create(); 244 assertNotNull(session4); 245 assertEquals("default", session4.getValue()); 246 assertEquals("default", session4.getValue()); 247 248 StatefulSession30 session5 = (StatefulSession30)home.create("init"); 249 assertNotNull(session5); 250 assertEquals("init", session5.getValue()); 251 252 StatefulSession30 session6 = (StatefulSession30)home.create("init", new Integer (123)); 253 assertNotNull(session6); 254 assertEquals("init123", session6.getValue()); 255 256 StatefulSession30 session7 = (StatefulSession30)home.create("secondinit"); 257 assertNotNull(session7); 258 assertEquals("secondinit", session7.getValue()); 259 260 StatefulSession30 session8 = (StatefulSession30) jndiContext.lookup("StatefulSession30"); 261 assertNotNull(session8); 262 assertEquals("default", session8.getValue()); 263 264 assertEquals("testing", session1.getValue()); 265 assertEquals("default", session2.getValue()); 266 assertEquals("123", session3.getValue()); 267 assertEquals("default", session4.getValue()); 268 assertEquals("init", session5.getValue()); 269 assertEquals("init123", session6.getValue()); 270 assertEquals("secondinit", session7.getValue()); 271 } 272 273 public void testStateful21Interfaces() throws Exception 274 { 275 InitialContext jndiContext = new InitialContext (); 276 277 StatefulSession30Home home = (StatefulSession30Home) jndiContext.lookup("StatefulSession30Home"); 278 assertNotNull(home); 279 280 EJBMetaData metadata = home.getEJBMetaData(); 281 assertNotNull(metadata); 282 assertEquals("org.jboss.ejb3.test.reference21_30.StatefulSession30",metadata.getRemoteInterfaceClass().getName()); 283 284 HomeHandle homeHandle = home.getHomeHandle(); 285 assertNotNull(homeHandle); 286 287 EJBHome ejbHome = homeHandle.getEJBHome(); 288 assertNotNull(ejbHome); 289 metadata = ejbHome.getEJBMetaData(); 290 assertNotNull(metadata); 291 assertEquals("org.jboss.ejb3.test.reference21_30.StatefulSession30",metadata.getRemoteInterfaceClass().getName()); 292 293 StatefulSession30 session = (StatefulSession30)home.create(); 294 assertNotNull(session); 295 ejbHome = session.getEJBHome(); 296 assertNotNull(ejbHome); 297 Object primaryKey = session.getPrimaryKey(); 298 assertNotNull(primaryKey); 299 300 Handle handle = session.getHandle(); 301 assertNotNull(handle); 302 303 EJBObject ejbObject = handle.getEJBObject(); 304 assertNotNull(ejbObject); 305 306 ejbHome = ejbObject.getEJBHome(); 307 assertNotNull(ejbHome); 308 309 Handle handle1 = ejbObject.getHandle(); 310 assertNotNull(handle1); 311 312 StatefulSession30 session1 = (StatefulSession30)home.create(); 313 assertFalse(session.isIdentical(session1)); 314 assertTrue(session.isIdentical(session)); 315 } 316 317 public void testStateless21Interfaces() throws Exception 318 { 319 InitialContext jndiContext = new InitialContext (); 320 321 Session30Home home = (Session30Home) jndiContext.lookup("Session30Home"); 322 assertNotNull(home); 323 324 EJBMetaData metadata = home.getEJBMetaData(); 325 assertNotNull(metadata); 326 assertEquals("org.jboss.ejb3.test.reference21_30.Session30",metadata.getRemoteInterfaceClass().getName()); 327 328 HomeHandle homeHandle = home.getHomeHandle(); 329 assertNotNull(homeHandle); 330 331 EJBHome ejbHome = homeHandle.getEJBHome(); 332 assertNotNull(ejbHome); 333 metadata = ejbHome.getEJBMetaData(); 334 assertNotNull(metadata); 335 assertEquals("org.jboss.ejb3.test.reference21_30.Session30",metadata.getRemoteInterfaceClass().getName()); 336 337 Session30 session = (Session30)home.create(); 338 assertNotNull(session); 339 ejbHome = session.getEJBHome(); 340 assertNotNull(ejbHome); 341 Object primaryKey = session.getPrimaryKey(); 342 assertNull(primaryKey); 343 344 Handle handle = session.getHandle(); 345 assertNotNull(handle); 346 347 EJBObject ejbObject = handle.getEJBObject(); 348 assertNotNull(ejbObject); 349 350 ejbHome = ejbObject.getEJBHome(); 351 assertNotNull(ejbHome); 352 353 Handle handle1 = ejbObject.getHandle(); 354 assertNotNull(handle1); 355 356 Session30 session1 = (Session30)home.create(); 357 assertFalse(session.isIdentical(session1)); 358 } 359 360 protected void setUp() throws Exception 361 { 362 } 363 364 public static Test suite() throws Exception 365 { 366 return getDeploySetup(ReferenceTestCase.class, "reference.jar"); 367 } 368 } 369 | Popular Tags |