KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28
29 import com.sun.appserv.management.DomainRoot;
30 import com.sun.appserv.management.base.AMX;
31 import com.sun.appserv.management.base.Util;
32
33 import com.sun.appserv.management.base.SystemInfo;
34 import com.sun.appserv.management.config.DomainConfig;
35 import com.sun.appserv.management.config.ConfigConfig;
36
37 import com.sun.appserv.management.util.misc.MapUtil;
38 import com.sun.appserv.management.util.misc.StringUtil;
39
40
41 import com.sun.enterprise.management.AMXTestBase;
42 import com.sun.enterprise.management.Capabilities;
43 import com.sun.enterprise.management.MultipleServerSupportRequired;
44
45
46 /**
47  */

48 public final class ConfigConfigTest extends AMXTestBase
49     implements MultipleServerSupportRequired
50 {
51         public
52     ConfigConfigTest()
53     {
54         if ( checkNotOffline( "ensureDefaultInstance" ) )
55         {
56             ensureDefaultInstance( getDomainRoot() );
57         }
58
59     }
60     
61         public static ConfigConfig
62     ensureDefaultInstance( final DomainRoot domainRoot )
63     {
64         ConfigConfig config = null;
65         
66         final DomainConfig domainConfig = domainRoot.getDomainConfig();
67         final Map JavaDoc<String JavaDoc,ConfigConfig> existing = domainConfig.getConfigConfigMap();
68         
69         if ( supportsMultipleServers( domainRoot ) )
70         {
71             config = existing.get( getDefaultInstanceName( domainRoot ) );
72             if ( config == null )
73             {
74                 final ConfigSetup setup = new ConfigSetup( domainRoot );
75                 config = setup.createConfig( getDefaultInstanceName( domainRoot ) );
76             }
77         }
78         else
79         {
80             config = existing.get( PE_CONFIG_NAME );
81             assert( config != null ) : "No config named " + StringUtil.quote( PE_CONFIG_NAME );
82         }
83         return config;
84     }
85
86         public static String JavaDoc
87     getDefaultInstanceName( final DomainRoot domainRoot )
88     {
89         String JavaDoc name = null;
90         
91         if ( domainRoot.getSystemInfo().supportsFeature( SystemInfo.MULTIPLE_SERVERS_FEATURE ) )
92         {
93             name = getDefaultInstanceName( "ConfigConfigTest" );
94         }
95         else
96         {
97             name = PE_CONFIG_NAME;
98         }
99         return name;
100     }
101
102     
103        private ConfigConfig
104     create( final String JavaDoc name )
105         throws Throwable JavaDoc
106     {
107         final ConfigSetup setup = new ConfigSetup( getDomainRoot() );
108         
109         setup.removeConfig( name );
110         
111         final ConfigConfig config = setup.createConfig( name );
112         assert( name.equals( config.getName() ) );
113         
114         // see that it responds to a request
115
final Map JavaDoc<String JavaDoc,Object JavaDoc> attrs = Util.getExtra( config ).getAllAttributes();
116         //printVerbose( "Attributes for config " + config.getName() + ":" );
117
//printVerbose( MapUtil.toString( attrs, NEWLINE ) );
118

119         return config;
120     }
121     
122         public void
123     testCreateRemove()
124         throws Throwable JavaDoc
125     {
126         if ( ! checkNotOffline( "testCreateRemove" ) )
127         {
128             return;
129         }
130         
131         final String JavaDoc NAME = "ConfigConfigTest.testCreateRemove";
132         
133         final Map JavaDoc<String JavaDoc,ConfigConfig> before = getDomainConfig().getConfigConfigMap();
134         
135         final int NUM = 2;
136         final ConfigConfig[] configs = new ConfigConfig[ NUM ];
137         
138         for( int i = 0; i < NUM; ++i )
139         {
140             configs[ i ] = create( NAME + i );
141         }
142         
143         final ConfigSetup setup = new ConfigSetup( getDomainRoot() );
144         for( final ConfigConfig config : configs )
145         {
146             setup.removeConfig( config.getName() );
147             
148             // verify that the config is gone
149
try
150             {
151                 Util.getExtra( config ).getAllAttributes();
152                 fail( "Config " + config.getName() + " should no longer exist" );
153             }
154             catch( Exception JavaDoc e )
155             {
156                 // good, we expected to be here
157
}
158         }
159         
160         final Map JavaDoc<String JavaDoc,ConfigConfig> after = getDomainConfig().getConfigConfigMap();
161         assert( before.keySet().equals( after.keySet() ) );
162     }
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
Popular Tags