KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 package com.sun.enterprise.management.config;
30
31 import java.util.Set JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Arrays JavaDoc;
35
36 import javax.management.ObjectName JavaDoc;
37
38
39 import com.sun.appserv.management.base.AMX;
40 import com.sun.appserv.management.base.Util;
41
42 import com.sun.appserv.management.DomainRoot;
43 import com.sun.appserv.management.client.AppserverConnectionSource;
44
45 import com.sun.appserv.management.config.DomainConfig;
46 import com.sun.appserv.management.config.NamedConfigElement;
47 import com.sun.appserv.management.config.StandaloneServerConfig;
48 import com.sun.appserv.management.config.ConfigConfig;
49 import com.sun.appserv.management.config.NodeAgentConfig;
50
51 import com.sun.appserv.management.util.misc.MapUtil;
52 import com.sun.appserv.management.util.misc.CollectionUtil;
53
54
55 import com.sun.enterprise.management.AMXTestBase;
56 import com.sun.enterprise.management.Capabilities;
57
58
59 /**
60  */

61 public final class StandaloneServerConfigTest extends AMXTestBase
62 {
63         public
64     StandaloneServerConfigTest()
65     {
66         if ( checkNotOffline( "ensureDefaultInstance" ) )
67         {
68             ensureDefaultInstance( getDomainRoot() );
69         }
70     }
71     
72         public static String JavaDoc
73     getDefaultInstanceName()
74     {
75         return "server";
76     }
77     
78     /**
79         We want the default instance to be available on both PE and EE
80         so we have no choice but to use the DAS instance.
81      */

82         public static StandaloneServerConfig
83     ensureDefaultInstance( final DomainRoot domainRoot )
84     {
85         final Map JavaDoc<String JavaDoc,StandaloneServerConfig> servers =
86             domainRoot.getDomainConfig().getStandaloneServerConfigMap();
87         
88         StandaloneServerConfig server = servers.get( getDefaultInstanceName() );
89         assert( server != null );
90         
91         return server;
92     }
93     
94         public static Capabilities
95     getCapabilities()
96     {
97         return getOfflineCapableCapabilities( false );
98     }
99     
100         public void
101     testCreateStandaloneServerConfig()
102         throws Throwable JavaDoc
103     {
104         final ConfigSetup setup = new ConfigSetup( getDomainRoot() );
105         final int basePort = 52700;
106         
107         final Map JavaDoc<String JavaDoc,NodeAgentConfig> nodeAgentConfigs = getDomainConfig().getNodeAgentConfigMap();
108         
109         if ( nodeAgentConfigs.keySet().size() == 0 )
110         {
111             warning( "testCreateStandaloneServerConfig: No node agents available, skipping test." );
112         }
113         else
114         {
115             for( final String JavaDoc nodeAgentName : nodeAgentConfigs.keySet() )
116             {
117                 final String JavaDoc serverName = nodeAgentName + ".StandaloneServerConfigTestServer";
118                 final String JavaDoc configName = serverName + "-config";
119                 
120                 setup.removeServer( serverName );
121                 setup.removeConfig( configName );
122                 
123                 final ConfigConfig config = setup.createConfig( configName );
124                 assert( configName.equals( config.getName() ) );
125                 final Map JavaDoc<String JavaDoc,Object JavaDoc> attrs = Util.getExtra( config ).getAllAttributes();
126                 
127                 try
128                 {
129                     final StandaloneServerConfig server =
130                         setup.createServer( serverName, basePort, nodeAgentName, config.getName() );
131                     
132                     setup.removeServer( server.getName() );
133                 }
134                 catch( Throwable JavaDoc t )
135                 {
136                     try
137                     {
138                         setup.removeConfig( config.getName() );
139                     }
140                     catch( Exception JavaDoc ee )
141                     {
142                     }
143                     throw t;
144                 }
145             }
146         }
147     }
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Popular Tags