KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Collections JavaDoc;
29
30 import java.io.IOException JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33
34 import com.sun.appserv.management.base.AMX;
35 import com.sun.appserv.management.base.Container;
36 import com.sun.appserv.management.base.XTypes;
37
38 import com.sun.appserv.management.config.AMXConfig;
39 import com.sun.appserv.management.config.HTTPListenerConfig;
40 import com.sun.appserv.management.config.HTTPServiceConfig;
41 import com.sun.appserv.management.config.SSLConfig;
42 import com.sun.appserv.management.config.PropertiesAccess;
43 import com.sun.appserv.management.config.HTTPListenerConfigKeys;
44 import com.sun.appserv.management.config.HTTPListenerConfigFamilyValues;
45 import static com.sun.appserv.management.config.SSLConfigKeys.*;
46
47
48 import com.sun.enterprise.management.AMXTestBase;
49 import com.sun.enterprise.management.Capabilities;
50
51 import com.sun.appserv.management.util.jmx.JMXUtil;
52 import com.sun.appserv.management.util.misc.MapUtil;
53 import com.sun.appserv.management.util.misc.TypeCast;
54
55 /**
56  */

57 public final class HTTPListenerConfigTest extends ConfigMgrTestBase
58 {
59     static final String JavaDoc ADDRESS = "0.0.0.0";
60     static final String JavaDoc DEF_VIRTUAL_SERVER = "server";
61     static final String JavaDoc SERVER_NAME = "localhost";
62     
63     // !!! deliberately use old, incorrect form; it should still succeed
64
static final Map JavaDoc<String JavaDoc,Object JavaDoc> OPTIONAL = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
65     static
66     {
67         OPTIONAL.put( PropertiesAccess.PROPERTY_PREFIX + "xyz", "abc");
68         OPTIONAL.put( HTTPListenerConfigKeys.ENABLED_KEY, Boolean.FALSE);
69         OPTIONAL.put( HTTPListenerConfigKeys.ACCEPTOR_THREADS_KEY, new Integer JavaDoc(4 ) );
70         //OPTIONAL.put( HTTPListenerConfigKeys.BLOCKING_ENABLED_KEY, "false" );
71
//OPTIONAL.put( HTTPListenerConfigKeys.REDIRECT_PORT_KEY, "9081" );
72
OPTIONAL.put( HTTPListenerConfigKeys.XPOWERED_BY_KEY, Boolean.TRUE );
73         //OPTIONAL.put( HTTPListenerConfigKeys.FAMILY_KEY, HTTPListenerConfigFamilyValues.INET );
74
}
75
76         public
77     HTTPListenerConfigTest ()
78     {
79     }
80     
81     
82         HTTPServiceConfig
83     getHTTPServiceConfig( )
84     {
85         return( getConfigConfig( ).getHTTPServiceConfig() );
86     }
87     
88         public void
89     testGetHTTPListeners()
90     {
91         final HTTPServiceConfig httpService =
92             getConfigConfig( ).getHTTPServiceConfig();
93         
94         final Map JavaDoc<String JavaDoc,HTTPListenerConfig> proxies = httpService.getHTTPListenerConfigMap();
95         
96         for( final String JavaDoc listenerName : proxies.keySet() )
97         {
98             final HTTPListenerConfig listener = (HTTPListenerConfig)
99                 proxies.get( listenerName );
100                 
101             listener.getEnabled();
102         }
103     }
104     
105         protected String JavaDoc
106     getProgenyTestName()
107     {
108         return( "HTTPListenerConfigMgrTest-test-listener" );
109     }
110     
111         protected Container
112     getProgenyContainer()
113     {
114         return getHTTPService();
115     }
116
117         protected String JavaDoc
118     getProgenyJ2EEType()
119     {
120         return XTypes.HTTP_LISTENER_CONFIG;
121     }
122
123
124         protected void
125     removeProgeny( final String JavaDoc name )
126     {
127         getHTTPService().removeHTTPListenerConfig( name );
128     }
129     
130         protected final AMXConfig
131     createProgeny( final String JavaDoc name, final Map JavaDoc<String JavaDoc,String JavaDoc> options )
132     {
133         // this is incorrect code-on purpose-to test backward compatibility with Maps
134
// that aren't of type <String,String>
135
final Map JavaDoc<String JavaDoc,String JavaDoc> optional = TypeCast.asMap( OPTIONAL );
136         assert( ! MapUtil.isAllStrings( optional ) );
137         
138         final Map JavaDoc<String JavaDoc,String JavaDoc> allOptions = MapUtil.newMap( options, optional );
139         assert( ! MapUtil.isAllStrings( allOptions ) );
140         
141         final int port = 31000 + (name.hashCode() % 31000);
142         
143         final HTTPListenerConfig config =
144             getHTTPService().createHTTPListenerConfig(name,
145                 ADDRESS, port, DEF_VIRTUAL_SERVER, SERVER_NAME, allOptions );
146         
147         return( config );
148     }
149
150         protected final HTTPServiceConfig
151     getHTTPService()
152     {
153         return getConfigConfig().getHTTPServiceConfig();
154     }
155     
156     
157         
158         public void
159     testCreateSSL()
160         throws Exception JavaDoc
161     {
162         final Map JavaDoc<String JavaDoc,String JavaDoc> options =
163             Collections.unmodifiableMap( MapUtil.newMap(
164             new String JavaDoc[]
165             {
166                 CLIENT_AUTH_ENABLED_KEY, "false",
167                 SSL_2_ENABLED_KEY, "true",
168                 SSL_3_ENABLED_KEY, "true",
169                 SSL_2_CIPHERS_KEY, "+rc4,-rc4export,-rc2,-rc2export,+idea,+des,+desede3",
170                 SSL3_TLS_CIPHERS_KEY,
171                     "+rsa_rc4_128_md5,+rsa3des_sha,+rsa_des_sha,-rsa_rc4_40_md5" +
172                     "-rsa_rc2_40_md5,-rsa_null_md5,-rsa_des_56_sha,-rsa_rc4_56_sha",
173                 TLS_ENABLED_KEY, "true",
174                 TLS_ROLLBACK_ENABLED_KEY, "true",
175             }
176             ));
177             
178         if ( ! checkNotOffline( "testCreateSSL" ) )
179         {
180             return;
181         }
182         
183         final String JavaDoc NAME = "HTTPListenerConfigMgr-listener-for-testCreateSSL";
184         
185         try
186         {
187             removeEx( NAME );
188             final HTTPListenerConfig newListener =
189                 (HTTPListenerConfig)createProgeny( NAME, null );
190             assert newListener != null;
191             
192             // verify that the new listener is present
193
final Map JavaDoc<String JavaDoc,HTTPListenerConfig> listeners =
194                 getHTTPService().getHTTPListenerConfigMap();
195             final HTTPListenerConfig listener = listeners.get( NAME );
196             assert listener != null;
197             assert listener == newListener;
198             
199             final String JavaDoc CERT_NICKNAME = NAME + "Cert";
200             
201             final SSLConfig ssl = listener.createSSLConfig( CERT_NICKNAME, options);
202             assert ssl != null;
203             assert ssl.getCertNickname().equals( CERT_NICKNAME );
204             
205             listener.removeSSLConfig();
206         }
207         finally
208         {
209             remove( NAME );
210         }
211     }
212 }
213
214
215
Popular Tags