001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.buslifecycle;
019:
020: import org.easymock.EasyMock;
021: import org.easymock.IMocksControl;
022: import org.junit.Assert;
023: import org.junit.Test;
024:
025: public class CXFBusLifeCycleManagerTest extends Assert {
026:
027: @Test
028: public void testListenerNotRegistered() {
029:
030: BusLifeCycleListener listener1 = EasyMock
031: .createMock(BusLifeCycleListener.class);
032: CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
033:
034: EasyMock.reset(listener1);
035: EasyMock.replay(listener1);
036: mgr.initComplete();
037: EasyMock.verify(listener1);
038:
039: EasyMock.reset(listener1);
040: EasyMock.replay(listener1);
041: mgr.preShutdown();
042: EasyMock.verify(listener1);
043:
044: EasyMock.reset(listener1);
045: EasyMock.replay(listener1);
046: mgr.postShutdown();
047: EasyMock.verify(listener1);
048: }
049:
050: @Test
051: public void testSingleListenerRegistration() {
052:
053: BusLifeCycleListener listener1 = EasyMock
054: .createMock(BusLifeCycleListener.class);
055: CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
056:
057: mgr.registerLifeCycleListener(listener1);
058:
059: EasyMock.reset(listener1);
060: listener1.initComplete();
061: EasyMock.replay(listener1);
062: mgr.initComplete();
063: EasyMock.verify(listener1);
064:
065: EasyMock.reset(listener1);
066: listener1.preShutdown();
067: EasyMock.replay(listener1);
068: mgr.preShutdown();
069: EasyMock.verify(listener1);
070:
071: EasyMock.reset(listener1);
072: listener1.postShutdown();
073: EasyMock.replay(listener1);
074: mgr.postShutdown();
075: EasyMock.verify(listener1);
076: }
077:
078: @Test
079: public void testDuplicateRegistration() {
080:
081: BusLifeCycleListener listener1 = EasyMock
082: .createMock(BusLifeCycleListener.class);
083: CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
084:
085: mgr.registerLifeCycleListener(listener1);
086: mgr.registerLifeCycleListener(listener1);
087:
088: EasyMock.reset(listener1);
089: listener1.initComplete();
090: EasyMock.expectLastCall().times(2);
091: EasyMock.replay(listener1);
092: mgr.initComplete();
093: EasyMock.verify(listener1);
094:
095: EasyMock.reset(listener1);
096: listener1.preShutdown();
097: EasyMock.expectLastCall().times(2);
098: EasyMock.replay(listener1);
099: mgr.preShutdown();
100: EasyMock.verify(listener1);
101:
102: EasyMock.reset(listener1);
103: listener1.postShutdown();
104: EasyMock.expectLastCall().times(2);
105: EasyMock.replay(listener1);
106: mgr.postShutdown();
107: EasyMock.verify(listener1);
108: }
109:
110: @Test
111: public void testMultipleListeners() {
112:
113: IMocksControl ctrl = EasyMock.createStrictControl();
114:
115: BusLifeCycleListener listener1 = ctrl
116: .createMock(BusLifeCycleListener.class);
117: BusLifeCycleListener listener2 = ctrl
118: .createMock(BusLifeCycleListener.class);
119: CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
120:
121: mgr.registerLifeCycleListener(listener1);
122: mgr.registerLifeCycleListener(listener2);
123:
124: ctrl.reset();
125: listener1.initComplete();
126: listener2.initComplete();
127: ctrl.replay();
128: mgr.initComplete();
129: ctrl.verify();
130:
131: ctrl.reset();
132: listener1.preShutdown();
133: listener2.preShutdown();
134: ctrl.replay();
135: mgr.preShutdown();
136: ctrl.verify();
137:
138: ctrl.reset();
139: listener1.postShutdown();
140: listener2.postShutdown();
141: ctrl.replay();
142: mgr.postShutdown();
143: ctrl.verify();
144: }
145:
146: @Test
147: public void testDeregistration() {
148:
149: IMocksControl ctrl = EasyMock.createStrictControl();
150:
151: BusLifeCycleListener listener1 = ctrl
152: .createMock(BusLifeCycleListener.class);
153: BusLifeCycleListener listener2 = ctrl
154: .createMock(BusLifeCycleListener.class);
155: CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
156:
157: mgr.registerLifeCycleListener(listener2);
158: mgr.registerLifeCycleListener(listener1);
159: mgr.unregisterLifeCycleListener(listener2);
160:
161: ctrl.reset();
162: listener1.initComplete();
163: ctrl.replay();
164: mgr.initComplete();
165: ctrl.verify();
166:
167: ctrl.reset();
168: listener1.preShutdown();
169: ctrl.replay();
170: mgr.preShutdown();
171: ctrl.verify();
172:
173: ctrl.reset();
174: listener1.postShutdown();
175: ctrl.replay();
176: mgr.postShutdown();
177: ctrl.verify();
178: }
179: }
|