01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.internal.services;
16:
17: import static org.easymock.EasyMock.contains;
18: import static org.easymock.EasyMock.same;
19:
20: import org.apache.commons.logging.Log;
21: import org.apache.tapestry.ioc.internal.IOCInternalTestCase;
22: import org.apache.tapestry.ioc.services.RegistryShutdownListener;
23: import org.testng.annotations.Test;
24:
25: public class RegistryShutdownHubImplTest extends IOCInternalTestCase {
26:
27: @Test
28: public void add_and_notify() {
29: RegistryShutdownListener l1 = mockListener();
30: RegistryShutdownListener l2 = mockListener();
31: Log log = mockLog();
32:
33: l1.registryDidShutdown();
34: l2.registryDidShutdown();
35:
36: replay();
37:
38: RegistryShutdownHubImpl hub = new RegistryShutdownHubImpl(log);
39:
40: hub.addRegistryShutdownListener(l1);
41: hub.addRegistryShutdownListener(l2);
42:
43: hub.fireRegistryDidShutdown();
44:
45: verify();
46: }
47:
48: /**
49: * Shows that multiple listener will be notified, and that an error in one doesn't prevent
50: * others from being notified.
51: */
52: @Test
53: public void notification_error() {
54: RegistryShutdownListener l1 = mockListener();
55: RegistryShutdownListener l2 = mockListener();
56: RegistryShutdownListener l3 = mockListener();
57:
58: Log log = mockLog();
59:
60: Throwable t = new RuntimeException("Shutdown failure.");
61:
62: l1.registryDidShutdown();
63: l2.registryDidShutdown();
64: setThrowable(t);
65:
66: log.error(contains("Shutdown failure."), same(t));
67:
68: l3.registryDidShutdown();
69:
70: replay();
71:
72: RegistryShutdownHubImpl hub = new RegistryShutdownHubImpl(log);
73:
74: hub.addRegistryShutdownListener(l1);
75: hub.addRegistryShutdownListener(l2);
76: hub.addRegistryShutdownListener(l3);
77:
78: hub.fireRegistryDidShutdown();
79:
80: verify();
81: }
82:
83: private RegistryShutdownListener mockListener() {
84: return newMock(RegistryShutdownListener.class);
85: }
86: }
|