KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > ConfigMgrTestBase


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/config/ConfigMgrTestBase.java,v 1.7 2006/03/09 20:30:53 llc Exp $
26  * $Revision: 1.7 $
27  * $Date: 2006/03/09 20:30:53 $
28  */

29 package com.sun.enterprise.management.config;
30
31 import java.util.Map JavaDoc;
32 import java.util.Collections JavaDoc;
33 import java.io.Serializable JavaDoc;
34
35 import java.io.IOException JavaDoc;
36 import java.io.Serializable JavaDoc;
37 import java.lang.reflect.Method JavaDoc;
38
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.AttributeList JavaDoc;
41 import javax.management.MBeanServerConnection JavaDoc;
42 import javax.management.Notification JavaDoc;
43 import javax.management.NotificationListener JavaDoc;
44
45 import com.sun.appserv.management.util.jmx.JMXUtil;
46 import com.sun.appserv.management.util.misc.ExceptionUtil;
47 import com.sun.appserv.management.util.misc.ClassUtil;
48 import com.sun.appserv.management.util.misc.MapUtil;
49
50 import com.sun.appserv.management.base.AMX;
51 import com.sun.appserv.management.base.Container;
52 import com.sun.appserv.management.base.Util;
53
54 import com.sun.appserv.management.config.AMXConfig;
55
56 import com.sun.appserv.management.client.ProxyFactory;
57
58
59 import com.sun.enterprise.management.AMXTestBase;
60 import com.sun.enterprise.management.Capabilities;
61 import com.sun.enterprise.management.CreateRemoveListener;
62
63 /**
64  */

65 public abstract class ConfigMgrTestBase extends AMXTestBase
66 {
67         protected
68     ConfigMgrTestBase()
69     {
70         super();
71     }
72     
73     
74         protected String JavaDoc
75     getProgenyTestName()
76     {
77         return( "test-" + ClassUtil.stripPackageName( this.getClass().getName() ) );
78     }
79     
80     
81     protected abstract AMXConfig createProgeny(String JavaDoc name, Map JavaDoc<String JavaDoc,String JavaDoc> options );
82     protected abstract Container getProgenyContainer();
83     protected abstract String JavaDoc getProgenyJ2EEType();
84     protected abstract void removeProgeny( String JavaDoc name );
85     
86     protected static final Map JavaDoc<String JavaDoc,String JavaDoc> ILLEGAL_OPTIONS =
87         Collections.unmodifiableMap( MapUtil.newMap( new String JavaDoc[]
88     {
89         "IllegalParam1", "IllegalValue1",
90         "IllegalParam2", "IllegalValue2",
91     }));
92     
93         public final synchronized void
94     testIllegalCreate()
95         throws Exception JavaDoc
96     {
97         if ( ! checkNotOffline( "testIllegalCreate" ) )
98         {
99             return;
100         }
101         
102         final String JavaDoc name = getProgenyTestName() + "-Illegal";
103         
104         try
105         {
106             final AMXConfig proxy = createProgeny( name, ILLEGAL_OPTIONS );
107             fail( "Expecting failure from createProgenyIllegal for progeny type: " + getProgenyJ2EEType() );
108         }
109         catch( Exception JavaDoc e )
110         {
111             final Throwable JavaDoc rootCause = ExceptionUtil.getRootCause( e );
112             if ( ! ( rootCause instanceof IllegalArgumentException JavaDoc ) )
113             {
114                 warning( "expecting IllegalArgumentException, got: " + rootCause.getClass().getName() +
115                 ", msg = " + rootCause.getMessage() );
116                 rootCause.printStackTrace();
117             }
118         }
119     }
120     
121         public final synchronized void
122     testCreateRemove()
123         throws Exception JavaDoc
124     {
125         if ( ! checkNotOffline( "testCreateRemove" ) )
126         {
127             return;
128         }
129         
130         final long start = now();
131         
132         String JavaDoc name = getProgenyTestName();
133         
134         final String JavaDoc progenyJ2EEType = getProgenyJ2EEType();
135         
136         AMXConfig proxy = getProgeny( name );
137         if ( proxy != null )
138         {
139             final ObjectName JavaDoc objectName = Util.getExtra( proxy ).getObjectName();
140             remove( name );
141             waitUnregistered( objectName );
142             assert( ! getConnection().isRegistered( objectName ) );
143             assert( getProgeny( name ) == null );
144             proxy = null;
145         }
146         
147         final Container container = getProgenyContainer();
148         final CreateRemoveListener listener =
149             new CreateRemoveListener( container, progenyJ2EEType, name );
150         
151         // create it
152
try
153         {
154             proxy = createProgeny( name, null );
155         }
156         catch( Exception JavaDoc e )
157         {
158             trace( getStackTrace( ExceptionUtil.getRootCause(e) ) );
159             failure( "Can't create item of j2eeType=" + progenyJ2EEType +
160                 ",name=" + name );
161         }
162         assert( proxy.getName().equals( name ) );
163         final ObjectName JavaDoc objectName = Util.getObjectName( proxy );
164         assert( getConnection().isRegistered( objectName ) );
165         assert( container.getContainee( progenyJ2EEType, name) != null );
166         assert( container.getContainee( progenyJ2EEType, name) == proxy );
167         final AMXConfig progeny = getProgeny( name );
168         assert( progeny == proxy );
169
170         // remove it
171
final ProxyFactory factory = Util.getExtra( proxy ).getProxyFactory();
172         assert( name.equals( progeny.getName() ) );
173         remove( name );
174         waitUnregistered( objectName );
175         assert( ! getConnection().isRegistered( objectName ) );
176         waitProxyGone( factory, objectName );
177         assert( getProgeny( name ) == null );
178         
179         listener.waitNotifs();
180         
181         printElapsed( "testCreateRemove: created/remove/listen for: " + progenyJ2EEType, start );
182     }
183
184
185         public AMXConfig
186     getProgeny( final String JavaDoc name )
187     {
188         final Container container = getProgenyContainer();
189         final String JavaDoc progenyType = getProgenyJ2EEType();
190         
191         //trace( "getProgeny: " + progenyType + "=" + name );
192
final Object JavaDoc progeny = container.getContainee( progenyType, name );
193         
194         if ( progeny != null && ! (progeny instanceof AMXConfig) )
195         {
196             assert( progeny instanceof AMX );
197             failure(
198                 "getProgeny: " + progenyType + "=" + name + " not an AMXConfig, interface = " +
199                 Util.getExtra( Util.asAMX(progeny )).getInterfaceName() );
200         }
201         
202         return( (AMXConfig)progeny );
203     }
204
205
206     
207         protected void
208     remove( final String JavaDoc name)
209     {
210         removeProgeny( name );
211     }
212
213     
214         void
215     removeEx(String JavaDoc name)
216     {
217         final AMX proxy = getProgeny( name );
218         if ( proxy != null )
219         {
220             assert( proxy.getName().equals( name ) );
221             final ObjectName JavaDoc objectName = Util.getObjectName( proxy );
222             
223             try
224             {
225                 remove(name);
226             
227                 final MBeanServerConnection JavaDoc conn = getConnection();
228                 while ( conn.isRegistered( objectName ) )
229                 {
230                     trace( "waiting for mbean to be unregistered: " + objectName );
231                 }
232             }
233             catch(Exception JavaDoc e)
234             {
235                 trace( "error removing MBean: " +
236                     objectName + " = " + ExceptionUtil.getRootCause( e ).getMessage() );
237             }
238         }
239         else
240         {
241             // trace( "ConfigMgrTestBase.removeEx: " + name + " does not exist." );
242
}
243     }
244 }
245
246
247
Popular Tags