1 22 package org.jboss.test.cmp2.optimisticlock.test; 23 24 import javax.naming.InitialContext ; 25 import javax.naming.NamingException ; 26 27 import javax.rmi.PortableRemoteObject ; 28 29 import junit.framework.Test; 30 import org.jboss.test.JBossTestCase; 31 import org.jboss.test.cmp2.optimisticlock.interfaces.FacadeHome; 32 import org.jboss.test.cmp2.optimisticlock.interfaces.Facade; 33 import org.jboss.test.cmp2.optimisticlock.bug1006723.testsession.TestSessionRemoteHome; 34 import org.jboss.test.cmp2.optimisticlock.bug1006723.testsession.TestSessionRemote; 35 36 37 42 public class OptimisticLockUnitTestCase 43 extends JBossTestCase 44 { 45 private static final String ENTITY_GROUP_LOCKING = "local/EntityGroupLocking"; 47 private static final String ENTITY_MODIFIED_LOCKING = "local/EntityModifiedLocking"; 48 private static final String ENTITY_READ_LOCKING = "local/EntityReadLocking"; 49 private static final String ENTITY_VERSION_LOCKING = "local/EntityVersionLocking"; 50 private static final String ENTITY_EXPLICIT_VERSION_LOCKING = "local/EntityExplicitVersionLocking"; 51 private static final String ENTITY_TIMESTAMP_LOCKING = "local/EntityTimestampLocking"; 52 private static final String ENTITY_KEYGEN_LOCKING = "local/EntityKeyGeneratorLocking"; 53 54 private FacadeHome facadeHome; 56 59 private static final Integer id = new Integer (1); 60 61 public OptimisticLockUnitTestCase(String name) 63 { 64 super(name); 65 } 66 67 public static Test suite() throws Exception 69 { 70 return JBossTestCase.getDeploySetup(OptimisticLockUnitTestCase.class, "cmp2-optimisticlock.jar"); 71 } 72 73 public void testBug1006723() throws Exception 75 { 76 InitialContext ctx = new InitialContext (); 77 TestSessionRemoteHome testSessionRemoteHome = (TestSessionRemoteHome) 78 PortableRemoteObject.narrow(ctx.lookup("ejb/TestSession"), TestSessionRemoteHome.class); 79 TestSessionRemote testSessionRemote = testSessionRemoteHome.create(); 80 Long oID = testSessionRemote.setup(); 81 testSessionRemote.test(oID); 82 } 83 84 public void testNullLockedFields() throws Exception 85 { 86 Facade facade = getFacadeHome().create(); 87 facade.createCmpEntity(ENTITY_MODIFIED_LOCKING, id, 88 null, new Integer (1), null, "str2", null, new Double (2.2)); 89 try 90 { 91 facade.testNullLockedFields(ENTITY_MODIFIED_LOCKING, id); 92 } 93 finally 94 { 95 tearDown(ENTITY_MODIFIED_LOCKING); 96 } 97 } 98 99 public void testKeygenStrategyPass() throws Exception 100 { 101 setup(ENTITY_KEYGEN_LOCKING); 102 Facade facade = getFacadeHome().create(); 103 try 104 { 105 facade.testKeygenStrategyPass(ENTITY_KEYGEN_LOCKING, id); 106 } 107 finally 108 { 109 tearDown(ENTITY_KEYGEN_LOCKING); 110 } 111 } 112 113 public void testKeygenStrategyFail() throws Exception 114 { 115 setup(ENTITY_KEYGEN_LOCKING); 116 Facade facade = getFacadeHome().create(); 117 try 118 { 119 facade.testKeygenStrategyFail(ENTITY_KEYGEN_LOCKING, id); 120 fail("Should have failed to update."); 121 } 122 catch(Exception e) 123 { 124 } 125 finally 126 { 127 tearDown(ENTITY_KEYGEN_LOCKING); 128 } 129 } 130 131 public void testTimestampStrategyPass() throws Exception 132 { 133 setup(ENTITY_TIMESTAMP_LOCKING); 134 Facade facade = getFacadeHome().create(); 135 try 136 { 137 facade.testTimestampStrategyPass(ENTITY_TIMESTAMP_LOCKING, id); 138 } 139 finally 140 { 141 tearDown(ENTITY_TIMESTAMP_LOCKING); 142 } 143 } 144 145 public void testTimestampStrategyFail() throws Exception 146 { 147 setup(ENTITY_TIMESTAMP_LOCKING); 148 Facade facade = getFacadeHome().create(); 149 try 150 { 151 facade.testTimestampStrategyFail(ENTITY_TIMESTAMP_LOCKING, id); 152 fail("Should have failed to update."); 153 } 154 catch(Exception e) 155 { 156 } 157 finally 158 { 159 tearDown(ENTITY_TIMESTAMP_LOCKING); 160 } 161 } 162 163 public void testVersionStrategyPass() throws Exception 164 { 165 setup(ENTITY_VERSION_LOCKING); 166 Facade facade = getFacadeHome().create(); 167 try 168 { 169 facade.testVersionStrategyPass(ENTITY_VERSION_LOCKING, id); 170 } 171 finally 172 { 173 tearDown(ENTITY_VERSION_LOCKING); 174 } 175 } 176 177 public void testVerionStrategyFail() throws Exception 178 { 179 setup(ENTITY_VERSION_LOCKING); 180 Facade facade = getFacadeHome().create(); 181 try 182 { 183 facade.testVersionStrategyFail(ENTITY_VERSION_LOCKING, id); 184 fail("Should have failed to update."); 185 } 186 catch(Exception e) 187 { 188 } 189 finally 190 { 191 tearDown(ENTITY_VERSION_LOCKING); 192 } 193 } 194 195 public void testExplicitVersionStrategyPass() throws Exception 196 { 197 setup(ENTITY_EXPLICIT_VERSION_LOCKING); 198 Facade facade = getFacadeHome().create(); 199 try 200 { 201 facade.testVersionStrategyPass(ENTITY_EXPLICIT_VERSION_LOCKING, id); 202 } 203 finally 204 { 205 tearDown(ENTITY_EXPLICIT_VERSION_LOCKING); 206 } 207 } 208 209 public void testExplicitVerionStrategyFail() throws Exception 210 { 211 setup(ENTITY_EXPLICIT_VERSION_LOCKING); 212 Facade facade = getFacadeHome().create(); 213 try 214 { 215 facade.testVersionStrategyFail(ENTITY_EXPLICIT_VERSION_LOCKING, id); 216 fail("Should have failed to update."); 217 } 218 catch(Exception e) 219 { 220 } 221 finally 222 { 223 tearDown(ENTITY_EXPLICIT_VERSION_LOCKING); 224 } 225 } 226 227 public void testExplicitVersionUpdateOnSync() throws Exception 228 { 229 setup(ENTITY_EXPLICIT_VERSION_LOCKING); 230 Facade facade = getFacadeHome().create(); 231 try 232 { 233 facade.testExplicitVersionUpdateOnSync(ENTITY_EXPLICIT_VERSION_LOCKING, id); 234 } 235 catch(Exception e) 236 { 237 fail("Locked fields are not updated on sync: " + e.getMessage()); 238 } 239 finally 240 { 241 tearDown(ENTITY_EXPLICIT_VERSION_LOCKING); 242 } 243 } 244 245 public void testGroupStrategyPass() throws Exception 246 { 247 setup(ENTITY_GROUP_LOCKING); 248 Facade facade = getFacadeHome().create(); 249 try 250 { 251 facade.testGroupStrategyPass(ENTITY_GROUP_LOCKING, id); 252 } 253 finally 254 { 255 tearDown(ENTITY_GROUP_LOCKING); 256 } 257 } 258 259 public void testGroupStrategyFail() throws Exception 260 { 261 setup(ENTITY_GROUP_LOCKING); 262 Facade facade = getFacadeHome().create(); 263 try 264 { 265 facade.testGroupStrategyFail(ENTITY_GROUP_LOCKING, id); 266 fail("Should have failed to update!"); 267 } 268 catch(Exception e) 269 { 270 } 271 finally 272 { 273 tearDown(ENTITY_GROUP_LOCKING); 274 } 275 } 276 277 public void testReadStrategyPass() throws Exception 278 { 279 setup(ENTITY_READ_LOCKING); 280 Facade facade = getFacadeHome().create(); 281 try 282 { 283 facade.testReadStrategyPass(ENTITY_READ_LOCKING, id); 284 } 285 finally 286 { 287 tearDown(ENTITY_READ_LOCKING); 288 } 289 } 290 291 public void testReadStrategyFail() throws Exception 292 { 293 setup(ENTITY_READ_LOCKING); 294 Facade facade = getFacadeHome().create(); 295 try 296 { 297 facade.testReadStrategyFail(ENTITY_READ_LOCKING, id); 298 fail("Should have failed to update."); 299 } 300 catch(Exception e) 301 { 302 } 303 finally 304 { 305 tearDown(ENTITY_READ_LOCKING); 306 } 307 } 308 309 public void testModifiedStrategyPass() throws Exception 310 { 311 setup(ENTITY_MODIFIED_LOCKING); 312 Facade facade = getFacadeHome().create(); 313 try 314 { 315 facade.testModifiedStrategyPass(ENTITY_MODIFIED_LOCKING, id); 316 } 317 finally 318 { 319 tearDown(ENTITY_MODIFIED_LOCKING); 320 } 321 } 322 323 public void testModifiedStrategyFail() throws Exception 324 { 325 setup(ENTITY_MODIFIED_LOCKING); 326 Facade facade = getFacadeHome().create(); 327 try 328 { 329 facade.testModifiedStrategyFail(ENTITY_MODIFIED_LOCKING, id); 330 fail("Should have failed to update!"); 331 } 332 catch(Exception e) 333 { 334 } 336 finally 337 { 338 tearDown(ENTITY_MODIFIED_LOCKING); 339 } 340 } 341 342 public void testUpdateLockOnSync() throws Exception 343 { 344 setup(ENTITY_VERSION_LOCKING); 345 Facade facade = getFacadeHome().create(); 346 try 347 { 348 facade.testUpdateLockOnSync(ENTITY_VERSION_LOCKING, id); 349 } 350 catch(Exception e) 351 { 352 fail("Locked fields are not updated on sync!"); 353 } 354 finally 355 { 356 tearDown(ENTITY_VERSION_LOCKING); 357 } 358 } 359 360 362 private void setup(String jndiName) throws Exception 363 { 364 Facade facade = getFacadeHome().create(); 365 facade.createCmpEntity(jndiName, id, 366 "str1", new Integer (1), new Double (1.1), 367 "str2", new Integer (2), new Double (2.2)); 368 } 369 370 private void tearDown(String jndiName) throws Exception 371 { 372 Facade facade = getFacadeHome().create(); 373 facade.safeRemove(jndiName, id); 374 } 375 376 private FacadeHome getFacadeHome() 377 throws NamingException 378 { 379 if(facadeHome == null) 380 { 381 InitialContext ic = new InitialContext (); 382 Object ref = ic.lookup(FacadeHome.JNDI_NAME); 383 facadeHome = (FacadeHome) PortableRemoteObject.narrow(ref, FacadeHome.class); 384 } 385 return facadeHome; 386 } 387 } 388 | Popular Tags |