KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 package com.sun.enterprise.management.config;
30
31 import java.util.Set JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.management.AttributeList JavaDoc;
35 import javax.management.Notification JavaDoc;
36 import javax.management.NotificationListener JavaDoc;
37 import javax.management.MBeanServerConnection JavaDoc;
38 import javax.management.NotCompliantMBeanException JavaDoc;
39
40 import com.sun.appserv.management.base.XTypes;
41 import com.sun.appserv.management.base.AMX;
42 import com.sun.appserv.management.base.QueryMgr;
43
44 import com.sun.appserv.management.client.AppserverConnectionSource;
45
46 import com.sun.appserv.management.config.ClusterConfig;
47 import com.sun.appserv.management.config.ConfigConfig;
48 import com.sun.appserv.management.config.StandaloneServerConfig;
49 import com.sun.appserv.management.config.ResourceRefConfig;
50 import com.sun.appserv.management.config.MailResourceConfig;
51 import com.sun.appserv.management.config.DomainConfig;
52
53
54
55 import com.sun.enterprise.management.AMXTestBase;
56 import com.sun.enterprise.management.Capabilities;
57
58
59 /**
60  */

61 public final class ReferencesTest extends AMXTestBase
62 {
63     public ReferencesTest()
64     {
65     }
66     
67     
68     private static final String JavaDoc MAIL_RESOURCE_NAME = "test/mail1";
69     
70         MailResourceConfig
71     createMailResourceConfig()
72     {
73         final MailResourceConfig mr =
74             getDomainConfig().createMailResourceConfig(
75                 MAIL_RESOURCE_NAME,
76                 "localhost",
77                 "mailuser@domain.com",
78                 "mailfrom@domain.com",
79                 null );
80         return mr;
81     }
82     
83       MailResourceConfig
84     ensureMailResourceConfig()
85     {
86         final Map JavaDoc<String JavaDoc,MailResourceConfig> mails =
87             getDomainConfig().getMailResourceConfigMap();
88         
89         MailResourceConfig mr = mails.get( MAIL_RESOURCE_NAME );
90         if ( mr == null )
91         {
92             mr = createMailResourceConfig();
93         }
94         return mr;
95     }
96     
97         void
98     removeMailResourceConfig()
99     {
100         final Map JavaDoc<String JavaDoc,MailResourceConfig> mails =
101             getDomainConfig().getMailResourceConfigMap();
102         
103         MailResourceConfig mr = mails.get( MAIL_RESOURCE_NAME );
104         if ( mr != null )
105         {
106             getDomainConfig().removeMailResourceConfig( mr.getName() );
107         }
108     }
109     
110         public void
111     testCreateAndRemoveResourceRefStandaloneServer()
112         throws Exception JavaDoc
113     {
114         if ( ! checkNotOffline( "testCreateRemove" ) )
115         {
116             return;
117         }
118         
119         final Map JavaDoc<String JavaDoc,AppserverConnectionSource> nodeAgents =
120             getNodeAgents();
121         
122         if ( nodeAgents.keySet().size() == 0 )
123         {
124             warning(
125                 "testCreateAndRemoveResourceRefStandaloneServer: no Node Agents--SKIPPING TEST" );
126             return;
127         }
128         final String JavaDoc nodeAgentName = nodeAgents.keySet().iterator().next();
129         
130         final ConfigSetup setup = new ConfigSetup( getDomainRoot() );
131         
132         ensureMailResourceConfig();
133         
134         final String JavaDoc serverName = "testCreateAndRemoveResourceRefStandaloneServer";
135         final String JavaDoc configName = serverName + "-config";
136         
137         final ConfigConfig config = setup.createConfig( configName );
138         try
139         {
140             final int basePort = 34770;
141             
142             final StandaloneServerConfig server =
143                 setup.createServer( serverName, basePort, nodeAgentName, configName );
144             try
145             {
146                 final ResourceRefConfig ref =
147                     server.createResourceRefConfig( MAIL_RESOURCE_NAME );
148                 assert( ref != null );
149                 
150                 server.removeResourceRefConfig( ref.getName() );
151             }
152             catch( Exception JavaDoc e )
153             {
154                 setup.removeServer( serverName );
155                 throw e;
156             }
157             finally
158             {
159                 removeMailResourceConfig();
160             }
161         }
162         catch( Exception JavaDoc e )
163         {
164             setup.removeConfig( configName );
165             throw e;
166         }
167     }
168     
169         public void
170     testCreateRefToMissingTarget()
171     {
172         if ( ! checkNotOffline( "testCreateRemove" ) )
173         {
174             return;
175         }
176         
177         final String JavaDoc MISSING_NAME = "NonExistent";
178         
179         final DomainConfig domainConfig = getDomainRoot().getDomainConfig();
180         final StandaloneServerConfig serverConfig =
181             domainConfig.getStandaloneServerConfigMap().get( "server" );
182         
183         try
184         {
185             serverConfig.createResourceRefConfig( MISSING_NAME );
186             assert false;
187             
188             serverConfig.createDeployedItemRefConfig( MISSING_NAME );
189             assert false;
190         }
191         catch( Exception JavaDoc e )
192         {
193             // good
194
}
195         
196     }
197     
198     /*
199     public void testCreateAndRemoveResourceRefCluster()
200     {
201         Map clusterMap<String,ClusterConfig> =
202             getDomainConfig().getClusterConfigMap();
203         
204         ClusterConfig cluster = clusterMap.get("testCluster");
205         
206         cluster.createResourceRefConfig("jdbc/PointBase");
207         
208         cluster.removeResourceRefConfig("jdbc/PointBase");
209     }
210     */

211  
212     /*
213
214
215     
216     public void testCreateAndRemoveDeployedItemRef() {
217         trace("\n..testCreateAndRemoveDeployedItemRef");
218         
219         StandaloneServerConfigMgr proxy =
220         getDomainConfig().getStandaloneServerConfigMgr();
221         
222         ClusterConfigMgr c =
223             getDomainConfig().getClusterConfigMgr();
224
225         Map serverMap =
226             getDomainConfig().getStandaloneServerConfigMap();
227         
228         Map clusterMap =
229             getDomainConfig().getClusterConfigMap();
230          
231         trace("I got the names of the servers!!!!!" + serverMap);
232         StandaloneServerConfig server =
233         (StandaloneServerConfig)serverMap.get("testServer");
234         
235         trace("I got the names of the clusters!!!!!" + clusterMap);
236         ClusterConfig cluster =
237             (ClusterConfig)clusterMap.get("testCluster");
238          
239         DeployedItemRefConfigMgr deploy =
240         server.getDeployedItemRefConfigMgr();
241         
242         
243         DeployedItemRefConfigMgr deploy2 =
244             cluster.getDeployedItemRefConfigMgr();
245          
246         trace("I got the deploy item ref mgr proxy from server! " + deploy);
247         
248         trace("I got the deploy item ref mgr proxy from cluster! " + deploy2);
249          
250         trace("New deployedItemRef: " +
251             deploy.create("jndiTree", new java.util.HashMap()));
252          
253         trace("New deployedItemRef: " +
254             deploy2.create("jndiTree", new java.util.HashMap()));
255    
256         try {
257             trace("Sleeping.....");
258             Thread.sleep(2000);
259         } catch (Exception e) {
260             e.printStackTrace();
261         }
262
263         // remove("testDeployedItemRefServer");
264         // c.remove("testDeployedItemRefCluster");
265         
266         deploy.remove("jndiTree");
267         deploy2.remove("jndiTree");
268     }
269     
270     
271     public void testCreateAndRemoveServerRef()
272              {
273         trace("\n..testCreateAndRemoveServerRef");
274      
275         Map map =
276             getDomainConfig().getClusterConfigMap();
277         Set names = map.keySet();
278         trace("I got the names of the clusters!!!!!" + map);
279         ClusterConfig proxy =
280             (ClusterConfig)map.get("testCluster");
281      
282         ServerRefConfigMgr serverRefMgr =
283             getServerRefConfigMgr();
284      
285         trace("I got the server ref proxy! " + serverRefMgr);
286      
287         trace("New server reference: " +
288             serverRefMgr.create("testServerRef"));
289      
290         try {
291             trace("Sleeping.....");
292             Thread.sleep(2000);
293         } catch (Exception e) {
294             e.printStackTrace();
295         }
296      
297         trace("Removing the server reference!!");
298         serverRefMgr.remove("testServerRef");
299      
300     }
301    
302     
303     public void testCreateAndRemoveStandaloneServer()
304              {
305         trace("\n..testCreateAndRemoveServer");
306      
307         ConfigConfigMgr configMgr =
308             getDomainConfig().getConfigConfigMgr();
309      
310         trace("I got the config proxy! " + configMgr);
311         trace("New config: " +
312             configMgr.create("testConfig", new java.util.HashMap()));
313         StandaloneServerConfigMgr proxy =
314             getDomainConfig().getStandaloneServerConfigMgr();
315      
316         trace("I got the standalone server proxy! " + proxy);
317      
318         assert(proxy != null) : "The StandaloneServerConfigMgr is NULL!!";
319         
320         trace("New standAloneServer: " +
321             create("testStandaloneServerWithNewSig", "test-agent",
322                 "testConfig", null));
323      
324         try {
325             trace("Sleeping.....");
326             Thread.sleep(2000);
327         } catch (Exception e) {
328             e.printStackTrace();
329         }
330      
331         trace("Removing the standalone server!!");
332      
333         remove("testStandaloneServerWithNewSig");
334      
335        // configMgr.remove("testConfig");
336     }
337     
338     
339     public void testCreateAndRemoveClusteredServer()
340             throws IOException {
341         trace("\n..testCreateAndRemoveClusteredServer");
342      
343         ClusteredServerConfigMgr proxy =
344             getDomainConfig().getClusteredServerConfigMgr();
345      
346         trace("I got the clustered server proxy! " + proxy);
347      
348      
349         trace("New cluster: " +
350             create("testClusteredServerWithNewSig", null, null, ));
351      
352         try {
353             trace("Sleeping.....");
354             Thread.sleep(2000);
355         } catch (Exception e) {
356             e.printStackTrace();
357         }
358      
359         trace("Removing the slustered server!!");
360         remove("testClusteredServer");
361      
362     }
363      */

364     
365     
366 }
367
368
369
Popular Tags