001: package org.objectweb.celtix.bus.busimpl;
002:
003: import junit.framework.TestCase;
004:
005: import org.easymock.EasyMock;
006: import org.easymock.IMocksControl;
007: import org.objectweb.celtix.buslifecycle.BusLifeCycleListener;
008:
009: public class CeltixBusLifeCycleManagerTest extends TestCase {
010:
011: public void testListenerNotRegistered() {
012:
013: BusLifeCycleListener listener1 = EasyMock
014: .createMock(BusLifeCycleListener.class);
015: CeltixBusLifeCycleManager mgr = new CeltixBusLifeCycleManager();
016:
017: EasyMock.reset(listener1);
018: EasyMock.replay(listener1);
019: mgr.initComplete();
020: EasyMock.verify(listener1);
021:
022: EasyMock.reset(listener1);
023: EasyMock.replay(listener1);
024: mgr.preShutdown();
025: EasyMock.verify(listener1);
026:
027: EasyMock.reset(listener1);
028: EasyMock.replay(listener1);
029: mgr.postShutdown();
030: EasyMock.verify(listener1);
031: }
032:
033: public void testSingleListenerRegistration() {
034:
035: BusLifeCycleListener listener1 = EasyMock
036: .createMock(BusLifeCycleListener.class);
037: CeltixBusLifeCycleManager mgr = new CeltixBusLifeCycleManager();
038:
039: mgr.registerLifeCycleListener(listener1);
040:
041: EasyMock.reset(listener1);
042: listener1.initComplete();
043: EasyMock.replay(listener1);
044: mgr.initComplete();
045: EasyMock.verify(listener1);
046:
047: EasyMock.reset(listener1);
048: listener1.preShutdown();
049: EasyMock.replay(listener1);
050: mgr.preShutdown();
051: EasyMock.verify(listener1);
052:
053: EasyMock.reset(listener1);
054: listener1.postShutdown();
055: EasyMock.replay(listener1);
056: mgr.postShutdown();
057: EasyMock.verify(listener1);
058: }
059:
060: public void testDuplicateRegistration() {
061:
062: BusLifeCycleListener listener1 = EasyMock
063: .createMock(BusLifeCycleListener.class);
064: CeltixBusLifeCycleManager mgr = new CeltixBusLifeCycleManager();
065:
066: mgr.registerLifeCycleListener(listener1);
067: mgr.registerLifeCycleListener(listener1);
068:
069: EasyMock.reset(listener1);
070: listener1.initComplete();
071: EasyMock.expectLastCall().times(2);
072: EasyMock.replay(listener1);
073: mgr.initComplete();
074: EasyMock.verify(listener1);
075:
076: EasyMock.reset(listener1);
077: listener1.preShutdown();
078: EasyMock.expectLastCall().times(2);
079: EasyMock.replay(listener1);
080: mgr.preShutdown();
081: EasyMock.verify(listener1);
082:
083: EasyMock.reset(listener1);
084: listener1.postShutdown();
085: EasyMock.expectLastCall().times(2);
086: EasyMock.replay(listener1);
087: mgr.postShutdown();
088: EasyMock.verify(listener1);
089: }
090:
091: public void testMultipleListeners() {
092:
093: IMocksControl ctrl = EasyMock.createStrictControl();
094:
095: BusLifeCycleListener listener1 = ctrl
096: .createMock(BusLifeCycleListener.class);
097: BusLifeCycleListener listener2 = ctrl
098: .createMock(BusLifeCycleListener.class);
099: CeltixBusLifeCycleManager mgr = new CeltixBusLifeCycleManager();
100:
101: mgr.registerLifeCycleListener(listener1);
102: mgr.registerLifeCycleListener(listener2);
103:
104: ctrl.reset();
105: listener1.initComplete();
106: listener2.initComplete();
107: ctrl.replay();
108: mgr.initComplete();
109: ctrl.verify();
110:
111: ctrl.reset();
112: listener1.preShutdown();
113: listener2.preShutdown();
114: ctrl.replay();
115: mgr.preShutdown();
116: ctrl.verify();
117:
118: ctrl.reset();
119: listener1.postShutdown();
120: listener2.postShutdown();
121: ctrl.replay();
122: mgr.postShutdown();
123: ctrl.verify();
124: }
125:
126: public void testDeregistration() {
127:
128: IMocksControl ctrl = EasyMock.createStrictControl();
129:
130: BusLifeCycleListener listener1 = ctrl
131: .createMock(BusLifeCycleListener.class);
132: BusLifeCycleListener listener2 = ctrl
133: .createMock(BusLifeCycleListener.class);
134: CeltixBusLifeCycleManager mgr = new CeltixBusLifeCycleManager();
135:
136: mgr.registerLifeCycleListener(listener2);
137: mgr.registerLifeCycleListener(listener1);
138: mgr.unregisterLifeCycleListener(listener2);
139:
140: ctrl.reset();
141: listener1.initComplete();
142: ctrl.replay();
143: mgr.initComplete();
144: ctrl.verify();
145:
146: ctrl.reset();
147: listener1.preShutdown();
148: ctrl.replay();
149: mgr.preShutdown();
150: ctrl.verify();
151:
152: ctrl.reset();
153: listener1.postShutdown();
154: ctrl.replay();
155: mgr.postShutdown();
156: ctrl.verify();
157: }
158: }
|