001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.config;
006:
007: import junit.framework.TestCase;
008:
009: /**
010: * Unit test for LockDefinition
011: */
012: public class LockDefinitionTest extends TestCase {
013:
014: private String lockName;
015: private ConfigLockLevel lockType;
016: private LockDefinition ld1;
017: private LockDefinition ld2;
018: private LockDefinition ld3;
019: private LockDefinition ld4;
020: private LockDefinition autolock;
021: private String ld3LockName;
022: private ConfigLockLevel ld3LockType;
023:
024: public void setUp() throws Exception {
025: lockName = "myLockName";
026: lockType = ConfigLockLevel.WRITE;
027: ld1 = new LockDefinitionImpl(lockName, lockType);
028: ld2 = new LockDefinitionImpl(lockName, lockType);
029: ld3LockName = "ld3LockName";
030: ld3LockType = ConfigLockLevel.READ;
031: ld3 = new LockDefinitionImpl(ld3LockName, ld3LockType);
032: autolock = new LockDefinitionImpl(
033: LockDefinition.TC_AUTOLOCK_NAME, lockType);
034: ld4 = new LockDefinitionImpl(lockName,
035: ConfigLockLevel.SYNCHRONOUS_WRITE);
036: }
037:
038: public void testReadBeforeCommit() {
039: try {
040: ld1.getLockName();
041: fail("Expected IllegalStateException.");
042: } catch (IllegalStateException e) {
043: // expected
044: }
045: try {
046: ld1.getLockLevel();
047: fail("Expected IllegalStateException.");
048: } catch (IllegalStateException e) {
049: // expected
050: }
051:
052: try {
053: ld1.getLockName();
054: fail("Expected IllegalStateException.");
055: } catch (IllegalStateException e) {
056: // expected
057: }
058: }
059:
060: public void testWriteAfterCommit() {
061: ld1.commit();
062: ld4.commit();
063:
064: try {
065: ld1.setLockName("ldkfaj;kdjf");
066: fail("Expected IllegalStateException.");
067: } catch (IllegalStateException e) {
068: // expected.
069: }
070:
071: try {
072: ld1.setLockLevel(null);
073: fail("Expected IllegalStateException.");
074: } catch (IllegalStateException e) {
075: // expected
076: }
077:
078: try {
079: ld4.setLockName("ldkfaj;kdjf");
080: fail("Expected IllegalStateException.");
081: } catch (IllegalStateException e) {
082: // expected.
083: }
084:
085: try {
086: ld4.setLockLevel(null);
087: fail("Expected IllegalStateException.");
088: } catch (IllegalStateException e) {
089: // expected
090: }
091: }
092:
093: public void testEquals() throws Exception {
094: assertEquals(ld1, ld2);
095: assertFalse(ld1.equals(ld3));
096: assertFalse(ld1.equals(ld4));
097: }
098:
099: public void testHashCode() throws Exception {
100: assertEquals(ld1.hashCode(), ld2.hashCode());
101: }
102:
103: public void testIsAutolock() throws Exception {
104: autolock.commit();
105: ld1.commit();
106: ld2.commit();
107: ld3.commit();
108: ld4.commit();
109: assertTrue(autolock.isAutolock());
110: assertFalse(ld1.isAutolock());
111: assertFalse(ld2.isAutolock());
112: assertFalse(ld3.isAutolock());
113: assertFalse(ld4.isAutolock());
114: }
115: }
|