KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > util > MonitoringRegistrationHelperTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 /*
30  * MonitoringRegistrationHelperTest.java
31  * JUnit based test
32  *
33  * Created on July 31, 2003, 3:19 PM
34  */

35
36 package com.sun.enterprise.admin.monitor.util;
37
38 import junit.framework.*;
39 import javax.management.j2ee.statistics.*;
40 import javax.management.*;
41
42 /**
43  * Unit test for MonitoringRegistrationHelper class.
44  * @author Shreedhar Ganapathy
45  */

46 public class MonitoringRegistrationHelperTest extends TestCase {
47     //public void testRegisterIIOPServiceStats(){
48
// mrh.registerIIOPServiceStats()
49
//}
50
/*public void testRegisterJVMStats(){
51         Stats jvmStats = new JVMStatsImpl();
52         mrh.registerJVMStats(jvmStats);
53         assertEquals(true, mrh.isRegistered(jvmStats));
54     }*/

55     
56     public void testRegisteredMBean(){
57         Stats stats = new S1ASJVMStatsImplMock();
58         try{
59             boolean done = mrh.registerStats(stats, "JVMStats");
60             assertTrue(done);
61             MBeanServer server = (MBeanServer) (MBeanServerFactory.findMBeanServer(null)).get(0);
62             assertNotNull(server);
63             ObjectName obj = new ObjectName("defaultDomain:name=JVMStats,type=statsMonitor");
64             MBeanInfo mInfo = (MBeanInfo)server.getMBeanInfo(obj);
65             assertNotNull(mInfo);
66             MBeanAttributeInfo[] attrInfo = mInfo.getAttributes();
67             assertNotNull(attrInfo);
68             for(int i=0; i<attrInfo.length;i++){
69                 String JavaDoc attr = attrInfo[i].getName();
70                 System.out.println("getting attribute:"+attr);
71                 Object JavaDoc n = server.getAttribute(obj,attr);
72                 try{
73                     assertEquals(Long JavaDoc.class, n.getClass());
74                 }
75                 catch(Error JavaDoc ex){
76                         ex.getLocalizedMessage();
77                         assertEquals(String JavaDoc.class, n.getClass());
78                 }
79                 catch(Exception JavaDoc e){
80                     assertNull(n);
81                 }
82             }
83         }
84         catch(Exception JavaDoc ex){
85             ex.printStackTrace();
86             assertEquals(NullPointerException JavaDoc.class, ex.getClass());
87         }
88     }
89         
90     public void testUnregisterStats(){
91         Stats stats = new S1ASJVMStatsImplMock();
92         try{
93             boolean done = mrh.registerStats(stats, "JVMStats");
94             assertTrue(done);
95             done = mrh.unregisterStats("JVMStats");
96             assertTrue(done);
97         }catch(Exception JavaDoc e){
98             e.getLocalizedMessage();
99         }
100     }
101     
102     public void testRegisterStats(){
103         Stats stats = new S1ASJVMStatsImplMock();
104         try{
105             boolean done = mrh.registerStats(stats, "JVMStats");
106             assertTrue(done);
107         }catch(Exception JavaDoc e){
108             e.getLocalizedMessage();
109         }
110     }
111     
112     public void testCreation(){
113         assertNotNull(mrh);
114     }
115     
116     public MonitoringRegistrationHelperTest(java.lang.String JavaDoc testName) {
117         super(testName);
118     }
119     
120     MonitoringRegistration mrh;
121     protected void setUp() {
122         mrh = MonitoringRegistrationHelper.getInstance();
123     }
124     
125     protected void tearDown() {
126         
127     }
128     public static Test suite() {
129         TestSuite suite = new TestSuite(MonitoringRegistrationHelperTest.class);
130         return suite;
131     }
132     
133     public static void main(String JavaDoc[] args){
134         junit.textui.TestRunner.run(suite());
135     }
136 }
137
Popular Tags