KickJava   Java API By Example, From Geeks To Geeks.

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


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/AppserverConnectionSourceTest.java,v 1.4 2005/12/25 03:41:26 tcfujii Exp $
26  * $Revision: 1.4 $
27  * $Date: 2005/12/25 03:41:26 $
28  */

29 package com.sun.enterprise.management.client;
30
31 import java.io.IOException JavaDoc;
32
33 import com.sun.appserv.management.client.AppserverConnectionSource;
34
35
36 import com.sun.enterprise.management.AMXTestBase;
37 import com.sun.enterprise.management.Capabilities;
38
39 /**
40     Tests AppserverConnectionSource.
41     
42     Note that no actual connect test can be done through normal junit tests since there
43     is no host/port available and no guarantee of a running server. All other aspects
44     can be tested.
45  */

46 public final class AppserverConnectionSourceTest extends AMXTestBase
47 {
48         public
49     AppserverConnectionSourceTest( )
50     {
51     }
52         public static Capabilities
53     getCapabilities()
54     {
55         return getOfflineCapableCapabilities( false );
56     }
57     
58         private static void
59     testConnect(
60         final String JavaDoc host,
61         final int port,
62         final String JavaDoc protocol,
63         final String JavaDoc user,
64         final String JavaDoc password )
65         throws IOException JavaDoc
66     {
67         final AppserverConnectionSource source =
68             new AppserverConnectionSource( protocol, host, port, user, password, null);
69         
70         source.getMBeanServerConnection( true );
71         
72     }
73     
74         public void
75     testConnect()
76         throws Exception JavaDoc
77     {
78         final String JavaDoc host = (String JavaDoc)getEnvValue( "HOST" );
79         final String JavaDoc port = (String JavaDoc)getEnvValue( "PORT" );
80         final String JavaDoc protocol = (String JavaDoc)getEnvValue( "PROTOCOL" );
81         final String JavaDoc user = (String JavaDoc)getEnvValue( "USER" );
82         final String JavaDoc password = (String JavaDoc)getEnvValue( "PASSWORD" );
83         
84         if ( host == null || port == null || protocol == null ||
85             user == null || password == null ||
86             ! AppserverConnectionSource.isSupportedProtocol( protocol ) )
87         {
88             trace( "AppserverConnectionSourceTest: skipped connect test; missing config:" +
89                 "host = " + host +
90                 ", port = " + port +
91                 ", protocol = " + protocol +
92                 ", user = " + user +
93                 ", password = " + password );
94         }
95         else
96         {
97             testConnect( host, new Integer JavaDoc( port ).intValue(), protocol, user, password );
98         }
99     }
100     
101         private AppserverConnectionSource
102     create( final String JavaDoc protocol )
103     {
104         return( new AppserverConnectionSource( protocol, "localhost", 9999, "admin", "admin123", null) );
105     }
106     
107         public void
108     testCreateS1ASHTTP()
109     {
110         create( AppserverConnectionSource.PROTOCOL_HTTP );
111     }
112     
113         public void
114     testCreateRMI()
115     {
116         create( AppserverConnectionSource.PROTOCOL_RMI );
117     }
118     
119         public void
120     testCreateIllegal()
121     {
122         try
123         {
124             create( "jmxmp" );
125         }
126         catch( IllegalArgumentException JavaDoc e )
127         {
128             // good
129
}
130     }
131     
132         public void
133     testToString()
134     {
135         create( AppserverConnectionSource.PROTOCOL_RMI ).toString();
136         create( AppserverConnectionSource.PROTOCOL_HTTP ).toString();
137     }
138 }
139
140
141
142
143
144
145
Popular Tags