1 5 package com.tc.object.config; 6 7 import junit.framework.TestCase; 8 9 12 public class LockDefinitionTest extends TestCase { 13 14 private String lockName; 15 private ConfigLockLevel lockType; 16 private LockDefinition ld1; 17 private LockDefinition ld2; 18 private LockDefinition ld3; 19 private LockDefinition ld4; 20 private LockDefinition autolock; 21 private String ld3LockName; 22 private ConfigLockLevel ld3LockType; 23 24 public void setUp() throws Exception { 25 lockName = "myLockName"; 26 lockType = ConfigLockLevel.WRITE; 27 ld1 = new LockDefinition(lockName, lockType); 28 ld2 = new LockDefinition(lockName, lockType); 29 ld3LockName = "ld3LockName"; 30 ld3LockType = ConfigLockLevel.READ; 31 ld3 = new LockDefinition(ld3LockName, ld3LockType); 32 autolock = new LockDefinition(LockDefinition.TC_AUTOLOCK_NAME, lockType); 33 ld4 = new LockDefinition(lockName, ConfigLockLevel.SYNCHRONOUS_WRITE); 34 } 35 36 public void testReadBeforeCommit() { 37 try { 38 ld1.getLockName(); 39 fail("Expected IllegalStateException."); 40 } catch (IllegalStateException e) { 41 } 43 try { 44 ld1.getLockLevel(); 45 fail("Expected IllegalStateException."); 46 } catch (IllegalStateException e) { 47 } 49 50 try { 51 ld1.getLockName(); 52 fail("Expected IllegalStateException."); 53 } catch (IllegalStateException e) { 54 } 56 } 57 58 public void testWriteAfterCommit() { 59 ld1.commit(); 60 ld4.commit(); 61 62 try { 63 ld1.setLockName("ldkfaj;kdjf"); 64 fail("Expected IllegalStateException."); 65 } catch (IllegalStateException e) { 66 } 68 69 try { 70 ld1.setLockLevel(null); 71 fail("Expected IllegalStateException."); 72 } catch (IllegalStateException e) { 73 } 75 76 try { 77 ld4.setLockName("ldkfaj;kdjf"); 78 fail("Expected IllegalStateException."); 79 } catch (IllegalStateException e) { 80 } 82 83 try { 84 ld4.setLockLevel(null); 85 fail("Expected IllegalStateException."); 86 } catch (IllegalStateException e) { 87 } 89 } 90 91 public void testEquals() throws Exception { 92 assertEquals(ld1, ld2); 93 assertFalse(ld1.equals(ld3)); 94 assertFalse(ld1.equals(ld4)); 95 } 96 97 public void testHashCode() throws Exception { 98 assertEquals(ld1.hashCode(), ld2.hashCode()); 99 } 100 101 public void testIsAutolock() throws Exception { 102 autolock.commit(); 103 ld1.commit(); 104 ld2.commit(); 105 ld3.commit(); 106 ld4.commit(); 107 assertTrue(autolock.isAutolock()); 108 assertFalse(ld1.isAutolock()); 109 assertFalse(ld2.isAutolock()); 110 assertFalse(ld3.isAutolock()); 111 assertFalse(ld4.isAutolock()); 112 } 113 } | Popular Tags |