KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > LockDefinitionTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.object.config;
6
7 import junit.framework.TestCase;
8
9 /**
10  * Unit test for LockDefinition
11  */

12 public class LockDefinitionTest extends TestCase {
13
14   private String JavaDoc 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 JavaDoc ld3LockName;
22   private ConfigLockLevel ld3LockType;
23
24   public void setUp() throws Exception JavaDoc {
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 JavaDoc e) {
41       // expected
42
}
43     try {
44       ld1.getLockLevel();
45       fail("Expected IllegalStateException.");
46     } catch (IllegalStateException JavaDoc e) {
47       // expected
48
}
49
50     try {
51       ld1.getLockName();
52       fail("Expected IllegalStateException.");
53     } catch (IllegalStateException JavaDoc e) {
54       // expected
55
}
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 JavaDoc e) {
66       // expected.
67
}
68
69     try {
70       ld1.setLockLevel(null);
71       fail("Expected IllegalStateException.");
72     } catch (IllegalStateException JavaDoc e) {
73       // expected
74
}
75
76     try {
77       ld4.setLockName("ldkfaj;kdjf");
78       fail("Expected IllegalStateException.");
79     } catch (IllegalStateException JavaDoc e) {
80       // expected.
81
}
82
83     try {
84       ld4.setLockLevel(null);
85       fail("Expected IllegalStateException.");
86     } catch (IllegalStateException JavaDoc e) {
87       // expected
88
}
89   }
90
91   public void testEquals() throws Exception JavaDoc {
92     assertEquals(ld1, ld2);
93     assertFalse(ld1.equals(ld3));
94     assertFalse(ld1.equals(ld4));
95   }
96
97   public void testHashCode() throws Exception JavaDoc {
98     assertEquals(ld1.hashCode(), ld2.hashCode());
99   }
100
101   public void testIsAutolock() throws Exception JavaDoc {
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