KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ha > jmx > test > HAServiceMBeanSupportUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 package org.jboss.test.ha.jmx.test;
24
25 import java.util.EmptyStackException JavaDoc;
26
27 import javax.management.AttributeChangeNotification JavaDoc;
28 import javax.management.Notification JavaDoc;
29
30 import junit.framework.TestCase;
31
32 import org.jboss.test.ha.jmx.HAServiceMBeanSupportTester;
33
34 /**
35  *
36  * @author Ivelin Ivanov <ivelin@apache.org>
37  *
38  */

39 public class HAServiceMBeanSupportUnitTestCase extends TestCase
40 {
41
42   private HAServiceMBeanSupportTester haServiceMBeanSupportTester_ = null;
43
44   public HAServiceMBeanSupportUnitTestCase(String JavaDoc name)
45   {
46     super(name);
47   }
48    
49   public void setUp()
50   {
51     haServiceMBeanSupportTester_ = new HAServiceMBeanSupportTester();
52   }
53
54   
55   public void tearDown()
56   {
57     haServiceMBeanSupportTester_ = null;
58   }
59
60
61   /**
62    *
63    * messages should be sent out to both remote and local listeners.
64    *
65    */

66   public void testSendNotificationBroadcastsToClusterAndLocally()
67   {
68     Notification JavaDoc notification = new Notification JavaDoc("test.notification", "some:name=tester", 1);
69     haServiceMBeanSupportTester_.sendNotification( notification );
70
71     assertEquals("sendNotificationToLocalListeners() was not handed the original notification",
72       haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
73
74     assertEquals("method not invoked as expected",
75       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners");
76
77     assertEquals("sendNotificationRemote() was not handed the original notification",
78       haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
79     
80     assertEquals("method not invoked as expected",
81       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationRemote");
82   }
83
84   /**
85    *
86    * Even if the message cannot be sent out to the cluster,
87    * it should still be delivered to local listeners.
88    *
89    */

90   public void testSendNotificationAfterClusterFailureContinueWithLocal()
91   {
92     haServiceMBeanSupportTester_.__shouldSendNotificationRemoteFail__ = true;
93
94     Notification JavaDoc notification = new Notification JavaDoc("test.notification", "some:name=tester", 1);
95     haServiceMBeanSupportTester_.sendNotification( notification );
96     
97     assertEquals("sendNotificationToLocalListeners() was not handed the original notification",
98     haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
99
100     assertEquals("method not invoked as expected",
101       haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners");
102   }
103   
104   public void testSendLifecycleNotifications()
105   {
106      Notification JavaDoc notification = new AttributeChangeNotification JavaDoc(
107            haServiceMBeanSupportTester_,
108            1, System.currentTimeMillis(), "test",
109            "State", "java.lang.Integer",
110            new Integer JavaDoc(0), new Integer JavaDoc(1)
111            );
112      
113      haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(false);
114      
115      haServiceMBeanSupportTester_.sendNotification( notification );
116      
117      assertEquals("sendNotificationToLocalListeners() was handed the original notification",
118                  haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
119
120      assertEquals("method invoked as expected",
121        haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationToLocalListeners");
122
123      try
124      {
125         haServiceMBeanSupportTester_.__invokationStack__.pop();
126         fail("sendNotificationRemote() was not handed the original notification");
127      }
128      catch (EmptyStackException JavaDoc good) {}
129      
130      haServiceMBeanSupportTester_.setSendRemoteLifecycleNotifications(true);
131      haServiceMBeanSupportTester_.setSendLocalLifecycleNotifications(false);
132      
133      haServiceMBeanSupportTester_.sendNotification( notification );
134
135      assertEquals("sendNotificationRemote() was handed the original notification",
136        haServiceMBeanSupportTester_.__invokationStack__.pop(), notification );
137      
138      assertEquals("method invoked as expected",
139        haServiceMBeanSupportTester_.__invokationStack__.pop(), "sendNotificationRemote");
140      
141      try
142      {
143         haServiceMBeanSupportTester_.__invokationStack__.pop();
144         fail("sendNotificationToLocalListeners() was not handed the original notification");
145      }
146      catch (EmptyStackException JavaDoc good) {}
147   }
148
149 }
150
Popular Tags