KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 package com.sun.enterprise.management.config;
30
31 import java.util.Map JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Set JavaDoc;
34
35 import javax.management.ObjectName JavaDoc;
36
37 import com.sun.appserv.management.base.AMX;
38 import com.sun.appserv.management.base.Container;
39 import com.sun.appserv.management.base.XTypes;
40 import com.sun.appserv.management.config.AMXConfig;
41 import com.sun.appserv.management.config.AdminServiceConfig;
42 import com.sun.appserv.management.config.DomainConfig;
43 import com.sun.appserv.management.config.ConfigConfig;
44 import com.sun.appserv.management.config.JMXConnectorConfig;
45 import com.sun.appserv.management.config.SSLConfig;
46 import com.sun.appserv.management.config.JMXConnectorConfigKeys;
47 import com.sun.appserv.management.config.PropertiesAccess;
48 import com.sun.appserv.management.config.SecurityServiceConfig;
49 import com.sun.appserv.management.config.AuthRealmConfig;
50
51 import com.sun.appserv.management.util.misc.MapUtil;
52
53
54 import com.sun.enterprise.management.AMXTestBase;
55 import com.sun.enterprise.management.Capabilities;
56
57 /**
58  */

59 public final class JMXConnectorConfigTest extends ConfigMgrTestBase
60 {
61     static final String JavaDoc ADDRESS = "0.0.0.0";
62     static final String JavaDoc TEST_REALM_CLASS = "com.test.DUMMY";
63     static final String JavaDoc DEFAULT_PORT = "17377";
64
65     static final Map JavaDoc<String JavaDoc,String JavaDoc> OPTIONAL = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
66
67     static
68     {
69         OPTIONAL.put( PropertiesAccess.PROPERTY_PREFIX + "xyz", "abc");
70         OPTIONAL.put( JMXConnectorConfigKeys.SECURITY_ENABLED_KEY, "false");
71     }
72
73         public
74     JMXConnectorConfigTest()
75     {
76         if ( checkNotOffline( "ensureDefaultInstance" ) )
77         {
78             ensureDefaultInstance( getConfigConfig().getAdminServiceConfig() );
79         }
80     }
81     
82         public static String JavaDoc
83     getDefaultInstanceName()
84     {
85         return getDefaultInstanceName( "JMXConnectorConfig" );
86     }
87     
88         public static JMXConnectorConfig
89     ensureDefaultInstance( final AdminServiceConfig adminServiceConfig )
90     {
91         JMXConnectorConfig result =
92             adminServiceConfig.getJMXConnectorConfigMap().get( getDefaultInstanceName() );
93         
94         if ( result == null )
95         {
96             final SecurityServiceConfig securityServiceConfig =
97                 getConfigConfig( adminServiceConfig ).getSecurityServiceConfig();
98                 
99             final AuthRealmConfig defaultAuthRealm =
100                 AuthRealmConfigTest.ensureDefaultInstance( securityServiceConfig );
101             
102             result = createInstance( getDefaultInstanceName(),
103                 ADDRESS, DEFAULT_PORT, defaultAuthRealm, OPTIONAL );
104         }
105         
106         return result;
107     }
108     
109         public static JMXConnectorConfig
110     createInstance(
111         final String JavaDoc name,
112         final String JavaDoc address,
113         final String JavaDoc port,
114         final AuthRealmConfig authRealm,
115         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
116     {
117         final AdminServiceConfig adminServiceConfig =
118             getConfigConfig( authRealm ).getAdminServiceConfig();
119         
120         return adminServiceConfig.createJMXConnectorConfig( name,
121                     address, port, authRealm.getName(), optional );
122     }
123     
124     
125     
126         protected Container
127     getProgenyContainer()
128     {
129         return getAdminServiceConfig();
130     }
131
132         protected String JavaDoc
133     getProgenyJ2EEType()
134     {
135         return XTypes.JMX_CONNECTOR_CONFIG;
136     }
137     
138         final SecurityServiceConfig
139     getSecurityServiceConfig()
140     {
141         return getConfigConfig().getSecurityServiceConfig();
142     }
143     
144         final AuthRealmConfig
145     createAuthRealmConfig( final String JavaDoc name )
146     {
147         removeAuthRealmConfig( name );
148         
149         return getSecurityServiceConfig().createAuthRealmConfig(
150             name, TEST_REALM_CLASS, null );
151     }
152     
153         private String JavaDoc
154     createAuthRealmName( final String JavaDoc progenyName )
155     {
156         return progenyName + ".TestRealm";
157     }
158     
159         final void
160     removeAuthRealmConfig( final String JavaDoc name )
161     {
162         try
163         {
164             getSecurityServiceConfig().removeAuthRealmConfig( name );
165         }
166         catch( Exception JavaDoc e )
167         {
168         }
169     }
170     
171         protected void
172     removeProgeny( final String JavaDoc name )
173     {
174         try
175         {
176             getAdminServiceConfig().removeJMXConnectorConfig( name );
177         }
178         finally
179         {
180             try
181             {
182                 removeAuthRealmConfig( createAuthRealmName( name ) );
183             }
184             catch( Exception JavaDoc e )
185             {
186             }
187         }
188     }
189
190         protected final AMXConfig
191     createProgeny(
192         final String JavaDoc name,
193         final Map JavaDoc<String JavaDoc,String JavaDoc> options )
194     {
195         final Map JavaDoc<String JavaDoc,String JavaDoc> allOptions = MapUtil.newMap( options, OPTIONAL );
196         
197         final int port = (name.hashCode() % 16000) + 33111;
198         
199         final String JavaDoc authRealmName = createAuthRealmName( name );
200         final AuthRealmConfig authRealmConfig = createAuthRealmConfig( authRealmName );
201         
202         try
203         {
204             return getAdminServiceConfig().createJMXConnectorConfig(name,
205                 ADDRESS, "" + port, authRealmName, allOptions);
206         }
207         catch( Exception JavaDoc e )
208         {
209             removeAuthRealmConfig( authRealmName );
210             throw new RuntimeException JavaDoc( e );
211         }
212     }
213     
214         final AdminServiceConfig
215     getAdminServiceConfig()
216     {
217         return( getConfigConfig(). getAdminServiceConfig());
218     }
219     
220         public void
221     testCreateSSL()
222         throws Exception JavaDoc
223     {
224         if ( ! checkNotOffline( "testCreateSSL" ) )
225         {
226             return;
227         }
228         
229         final String JavaDoc NAME = "JMXConnectorConfigTest-testCreateSSL";
230         try
231         {
232             removeEx(NAME);
233             final JMXConnectorConfig newConfig =
234                 (JMXConnectorConfig)createProgeny( NAME, null);
235                 
236             final Map JavaDoc<String JavaDoc,JMXConnectorConfig> jmxConnectors =
237                 getAdminServiceConfig().getJMXConnectorConfigMap();
238             
239             final JMXConnectorConfig jmxConnector = (JMXConnectorConfig)
240                 jmxConnectors.get(NAME);
241             assert jmxConnector != null;
242             assert jmxConnector == newConfig;
243             
244             final String JavaDoc CERT_NICKNAME = NAME + "Cert";
245             
246             final SSLConfig ssl = jmxConnector.createSSLConfig( CERT_NICKNAME, null);
247             assert ssl != null;
248             assert ssl.getCertNickname().equals( CERT_NICKNAME );
249             
250             jmxConnector.removeSSLConfig();
251         }
252         finally
253         {
254             remove(NAME);
255         }
256     }
257 }
258
259
260
Popular Tags