KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > client > MiscTest


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/tests/com/sun/enterprise/management/client/MiscTest.java,v 1.5 2006/03/09 20:30:52 llc Exp $
26  * $Revision: 1.5 $
27  * $Date: 2006/03/09 20:30:52 $
28  */

29 package com.sun.enterprise.management.client;
30
31 import java.io.IOException JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import javax.management.ObjectName JavaDoc;
37 import javax.management.MBeanInfo JavaDoc;
38 import javax.management.InstanceNotFoundException JavaDoc;
39
40 import com.sun.appserv.management.base.AMX;
41 import com.sun.appserv.management.base.QueryMgr;
42 import com.sun.appserv.management.config.DASConfig;
43 import com.sun.appserv.management.base.XTypes;
44 import com.sun.appserv.management.base.Util;
45 import com.sun.appserv.management.base.NotificationService;
46 import com.sun.appserv.management.base.NotificationServiceMgr;
47 import com.sun.appserv.management.config.PropertiesAccess;
48
49 import com.sun.appserv.management.util.misc.ExceptionUtil;
50
51
52 import com.sun.enterprise.management.AMXTestBase;
53 import com.sun.enterprise.management.Capabilities;
54
55
56 /**
57  */

58 public final class MiscTest extends AMXTestBase
59 {
60         public
61     MiscTest( )
62         throws IOException JavaDoc
63     {
64     }
65     
66         public void
67     testMBeanInfo()
68     {
69         final MBeanInfo JavaDoc info = new MBeanInfo JavaDoc(
70             "foo.bar",
71             null,
72             null,
73             null,
74             null,
75             null );
76         
77         assert( info.getNotifications() != null );
78         assert( info.getOperations() != null );
79         assert( info.getAttributes() != null );
80         assert( info.getConstructors() != null );
81     }
82     
83         public static Capabilities
84     getCapabilities()
85     {
86         return getOfflineCapableCapabilities( true );
87     }
88     
89     /**
90         Hangs were occuring in getPropertyNames(). Repeatedly invoke it to see if the hang
91         can be reproduced.
92         public void
93     testGetPropertyNames()
94         throws ClassNotFoundException
95     {
96         final Set s = getQueryMgr().queryInterfaceSet( PropertiesAccess.class.getName(), null );
97         
98         for( int i = 0; i < 5000; ++i )
99         {
100             final Iterator iter = s.iterator();
101             while ( iter.hasNext() )
102             {
103                 final PropertiesAccess pa = (PropertiesAccess)iter.next();
104                 
105                 pa.getPropertyNames();
106             }
107         }
108     }
109      */

110
111
112     /**
113         Verify that when an MBean is removed, the proxy
114         throws an InstanceNotFoundException. This test is included here because
115         it otherwise causes problems when running other unit tests that want to operate
116         on all MBeans--this test creates and removes one, which causes the other
117         tests to fail.
118      */

119         public void
120     testProxyDetectsMBeanRemoved()
121         throws InstanceNotFoundException JavaDoc
122     {
123         // use the NotificationServiceMgr as a convenient way of making
124
// an MBean (a NotificationService) come and go.
125
final NotificationServiceMgr mgr = getDomainRoot().getNotificationServiceMgr();
126         
127         final NotificationService ns = mgr.createNotificationService( "UserData", 10 );
128         assert( ns.getUserData().equals( "UserData" ) );
129         final ObjectName JavaDoc nsObjectName = Util.getObjectName( ns );
130         
131         mgr.removeNotificationService( ns.getName() );
132         try
133         {
134             // all calls should fail
135
Util.getObjectName( ns );
136             ns.getName();
137             ns.getUserData();
138             failure( "expecting exception due to missing MBean" );
139         }
140         catch( Exception JavaDoc e )
141         {
142             // root cause should be an InstanceNotFoundException containing the ObjectName
143
final Throwable JavaDoc t = ExceptionUtil.getRootCause( e );
144             assert( t instanceof InstanceNotFoundException JavaDoc );
145             final InstanceNotFoundException JavaDoc inf = (InstanceNotFoundException JavaDoc)t;
146             
147             final String JavaDoc msg = inf.getMessage();
148             final int objectNameStart = msg.indexOf( "amx:" );
149             final String JavaDoc objectNameString = msg.substring( objectNameStart, msg.length() );
150             
151             final ObjectName JavaDoc on = Util.newObjectName( objectNameString );
152             
153             assert( on.equals( nsObjectName ) );
154         }
155     }
156     
157
158
159 }
160
161
162
Popular Tags