KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > registry > spi > 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.registry.spi;
37 import com.sun.enterprise.admin.monitor.registry.*;
38 import junit.framework.*;
39 import javax.management.j2ee.statistics.*;
40 import javax.management.*;
41 import java.util.*;
42
43 /**
44  * Unit test for MonitoringRegistrationHelper class.
45  * @author Shreedhar Ganapathy
46  */

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

56     
57     public void testRegisteredMBean(){
58         try{
59             assertNotNull(server);
60             ObjectName obj = getObjectName();
61             Stats stats = new S1ASJVMStatsImplMock();
62             try{
63                 mrh.registerJVMStats((JVMStats)stats, this);
64             }
65             catch(Exception JavaDoc e){
66                 e.printStackTrace();
67                 assertEquals("MonitoringRegistrationException", e.getClass().getName());
68             }
69             //assertEquals(true, server.isRegistered(obj));
70
MBeanInfo mInfo = (MBeanInfo)server.getMBeanInfo(obj);
71             assertNotNull(mInfo);
72             MBeanAttributeInfo[] attrInfo = mInfo.getAttributes();
73             assertNotNull(attrInfo);
74             for(int i=0; i<attrInfo.length;i++){
75                 String JavaDoc attr = attrInfo[i].getName();
76                 System.out.println("getting attribute:"+attr);
77                 Object JavaDoc n = server.getAttribute(obj,attr);
78                 try{
79                     assertEquals(Long JavaDoc.class, n.getClass());
80                 }
81                 catch(Error JavaDoc ex){
82                         ex.getLocalizedMessage();
83                         assertEquals(String JavaDoc.class, n.getClass());
84                 }
85                 catch(Exception JavaDoc e){
86                     assertNull(n);
87                 }
88             }
89         }
90         catch(Exception JavaDoc ex){
91             ex.printStackTrace();
92             assertEquals(NullPointerException JavaDoc.class, ex.getClass());
93         }
94     }
95
96     public void testUnregisterStats(){
97         try{
98             ObjectName obj = getObjectName();
99             mrh.unregisterJVMStats();
100             assertEquals(false, server.isRegistered(obj));
101             assertEquals(0, server.queryMBeans(obj, null).size());
102         }catch(Exception JavaDoc e){
103             e.getLocalizedMessage();
104         }
105     }
106     
107     public void testRegisterStats(){
108         try{
109             ObjectName obj = getObjectName();
110             Stats stats = new S1ASJVMStatsImplMock();
111             try{
112                 mrh.registerJVMStats((JVMStats)stats, this);
113             }
114             catch(Exception JavaDoc e){
115                 e.printStackTrace();
116                 assertEquals("MonitoringRegistrationException", e.getClass().getName());
117             }
118
119             assertEquals(1, server.getMBeanCount().intValue());
120             assertEquals(true, server.isInstanceOf(obj, "GeneratedMonitoringMBeanImpl"));
121         }catch(Exception JavaDoc e){
122             e.getLocalizedMessage();
123         }
124     }
125   
126     public void testCreation(){
127         assertNotNull(mrh);
128     }
129     
130     public MonitoringRegistrationHelperTest(java.lang.String JavaDoc testName) {
131         super(testName);
132     }
133     
134     MonitoringRegistry mrh;
135     MBeanServer server;
136
137     protected void setUp() {
138         server = (MBeanServer) (MBeanServerFactory.createMBeanServer(null));
139         mrh = MonitoringRegistrationHelper.getInstance();
140     }
141     private ObjectName getObjectName(){
142         ObjectName obj =null;
143         try{
144             obj = new ObjectName("defaultDomain:category=monitor,type=jvm,name=jvm");
145         }catch (Exception JavaDoc e){
146             e.printStackTrace();
147         }
148         return obj;
149     }
150     protected void tearDown() {
151         
152     }
153     public static Test suite() {
154         TestSuite suite = new TestSuite(MonitoringRegistrationHelperTest.class);
155         return suite;
156     }
157     
158     public static void main(String JavaDoc[] args){
159         junit.textui.TestRunner.run(suite());
160     }
161     
162     public void setLevel(MonitoringLevel level) {
163         
164     }
165     
166     public void changeLevel(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType type) {
167     }
168     
169     public void changeLevel(MonitoringLevel from, MonitoringLevel to, javax.management.j2ee.statistics.Stats JavaDoc handback) {
170     }
171     
172 }
173
Popular Tags