001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.ha.jmx.test;
023:
024: import java.util.EmptyStackException;
025:
026: import javax.management.AttributeChangeNotification;
027: import javax.management.Notification;
028:
029: import junit.framework.TestCase;
030:
031: import org.jboss.test.ha.jmx.HAServiceMBeanSupportTester;
032:
033: /**
034: *
035: * @author Ivelin Ivanov <ivelin@jboss.org>
036: *
037: */
038: public class HAServiceMBeanSupportUnitTestCase extends TestCase {
039:
040: private HAServiceMBeanSupportTester haServiceMBeanSupportTester_ = null;
041:
042: public HAServiceMBeanSupportUnitTestCase(String name) {
043: super (name);
044: }
045:
046: public void setUp() {
047: haServiceMBeanSupportTester_ = new HAServiceMBeanSupportTester();
048: }
049:
050: public void tearDown() {
051: haServiceMBeanSupportTester_ = null;
052: }
053:
054: /**
055: *
056: * messages should be sent out to both remote and local listeners.
057: *
058: */
059: public void testSendNotificationBroadcastsToClusterAndLocally() {
060: Notification notification = new Notification(
061: "test.notification", "some:name=tester", 1);
062: haServiceMBeanSupportTester_.sendNotification(notification);
063:
064: assertEquals(
065: "sendNotificationToLocalListeners() was not handed the original notification",
066: haServiceMBeanSupportTester_.__invokationStack__.pop(),
067: notification);
068:
069: assertEquals("method not invoked as expected",
070: haServiceMBeanSupportTester_.__invokationStack__.pop(),
071: "sendNotificationToLocalListeners");
072:
073: assertEquals(
074: "sendNotificationRemote() was not handed the original notification",
075: haServiceMBeanSupportTester_.__invokationStack__.pop(),
076: notification);
077:
078: assertEquals("method not invoked as expected",
079: haServiceMBeanSupportTester_.__invokationStack__.pop(),
080: "sendNotificationRemote");
081: }
082:
083: /**
084: *
085: * Even if the message cannot be sent out to the cluster,
086: * it should still be delivered to local listeners.
087: *
088: */
089: public void testSendNotificationAfterClusterFailureContinueWithLocal() {
090: haServiceMBeanSupportTester_.__shouldSendNotificationRemoteFail__ = true;
091:
092: Notification notification = new Notification(
093: "test.notification", "some:name=tester", 1);
094: haServiceMBeanSupportTester_.sendNotification(notification);
095:
096: assertEquals(
097: "sendNotificationToLocalListeners() was not handed the original notification",
098: haServiceMBeanSupportTester_.__invokationStack__.pop(),
099: notification);
100:
101: assertEquals("method not invoked as expected",
102: haServiceMBeanSupportTester_.__invokationStack__.pop(),
103: "sendNotificationToLocalListeners");
104: }
105:
106: public void testSendLifecycleNotifications() {
107: Notification notification = new AttributeChangeNotification(
108: haServiceMBeanSupportTester_, 1, System
109: .currentTimeMillis(), "test", "State",
110: "java.lang.Integer", new Integer(0), new Integer(1));
111:
112: haServiceMBeanSupportTester_
113: .setSendRemoteLifecycleNotifications(false);
114:
115: haServiceMBeanSupportTester_.sendNotification(notification);
116:
117: assertEquals(
118: "sendNotificationToLocalListeners() was handed the original notification",
119: haServiceMBeanSupportTester_.__invokationStack__.pop(),
120: notification);
121:
122: assertEquals("method invoked as expected",
123: haServiceMBeanSupportTester_.__invokationStack__.pop(),
124: "sendNotificationToLocalListeners");
125:
126: try {
127: haServiceMBeanSupportTester_.__invokationStack__.pop();
128: fail("sendNotificationRemote() was not handed the original notification");
129: } catch (EmptyStackException good) {
130: }
131:
132: haServiceMBeanSupportTester_
133: .setSendRemoteLifecycleNotifications(true);
134: haServiceMBeanSupportTester_
135: .setSendLocalLifecycleNotifications(false);
136:
137: haServiceMBeanSupportTester_.sendNotification(notification);
138:
139: assertEquals(
140: "sendNotificationRemote() was handed the original notification",
141: haServiceMBeanSupportTester_.__invokationStack__.pop(),
142: notification);
143:
144: assertEquals("method invoked as expected",
145: haServiceMBeanSupportTester_.__invokationStack__.pop(),
146: "sendNotificationRemote");
147:
148: try {
149: haServiceMBeanSupportTester_.__invokationStack__.pop();
150: fail("sendNotificationToLocalListeners() was not handed the original notification");
151: } catch (EmptyStackException good) {
152: }
153: }
154:
155: }
|