KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > helper > RefHelperTest


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.helper;
24
25 import java.util.Set JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29
30 import com.sun.appserv.management.base.XTypes;
31
32 import com.sun.appserv.management.base.Util;
33
34 import com.sun.appserv.management.helper.RefHelper;
35
36 import com.sun.appserv.management.config.RefConfig;
37 import com.sun.appserv.management.config.ResourceRefConfig;
38 import com.sun.appserv.management.config.DeployedItemRefConfig;
39 import com.sun.appserv.management.config.ServerRefConfig;
40 import com.sun.appserv.management.config.ClusterRefConfig;
41 import com.sun.appserv.management.config.RefConfigReferent;
42
43
44 import com.sun.enterprise.management.AMXTestBase;
45 import com.sun.enterprise.management.Capabilities;
46
47
48 /**
49     This test should normally be run before the generic tests
50     so that it can set up default items for many of the config elements
51     so that the generic tests will actually test them. Otherwise,
52     when the generic tests are run, they won't see any instances
53     of many of the AMXConfig MBeans.
54     <p>
55     If there are errors doing this, disable this test in amxtest.classes,
56     fix the error in the specific place it's occurring, then re-enabled
57     this test.
58  */

59 public final class RefHelperTest extends AMXTestBase
60 {
61         public
62     RefHelperTest( )
63     {
64     }
65     
66         public void
67     testFindResourceRefs()
68     {
69         final Set JavaDoc<ResourceRefConfig> refs1 =
70             RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.RESOURCE_REF_CONFIG);
71             
72         final Set JavaDoc<ResourceRefConfig> refs2 =
73             RefHelper.findAllResourceRefConfigs( getQueryMgr() );
74         
75         assertEquals( refs1, refs2 );
76     }
77     
78         public void
79     testFindDeployedItemRefs()
80     {
81         final Set JavaDoc<RefConfig> refs1 =
82             RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.DEPLOYED_ITEM_REF_CONFIG);
83             
84         final Set JavaDoc<DeployedItemRefConfig> refs2 =
85             RefHelper.findAllDeployedItemRefConfigs( getQueryMgr() );
86         
87         assertEquals( refs1, refs2 );
88     }
89     
90     
91         public void
92     testFindServerRefs()
93     {
94         final Set JavaDoc<RefConfig> refs1 =
95             RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.SERVER_REF_CONFIG);
96             
97         final Set JavaDoc<ServerRefConfig> refs2 =
98             RefHelper.findAllServerRefConfigs( getQueryMgr() );
99         
100         assertEquals( refs1, refs2 );
101     }
102     
103         public void
104     testFindClusterRefs()
105     {
106         final Set JavaDoc<RefConfig> refs1 =
107             RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), XTypes.CLUSTER_REF_CONFIG);
108             
109         final Set JavaDoc<ClusterRefConfig> refs2 =
110             RefHelper.findAllClusterRefConfigs( getQueryMgr() );
111         
112         assertEquals( refs1, refs2 );
113     }
114     
115         public void
116     testFindAllRefConfigs()
117     {
118         final Set JavaDoc<RefConfig> all =
119             RefHelper.findAllRefConfigs( getQueryMgr() );
120         
121         final Set JavaDoc<String JavaDoc> referentJ2EETypes = RefHelper.getReferentJ2EETypes();
122         assert( referentJ2EETypes.size() >= 4 );
123         
124         final Set JavaDoc<RefConfig> allSeparately = new HashSet JavaDoc<RefConfig>();
125         
126         for( final String JavaDoc j2eeType : referentJ2EETypes )
127         {
128             final Set JavaDoc<RefConfig> refs =
129                 RefHelper.findAllRefConfigsByJ2EEType( getQueryMgr(), j2eeType ) ;
130             
131             for( final RefConfig ref : refs)
132             {
133                 allSeparately.add( ref );
134             }
135         }
136         
137         assertEquals( all, allSeparately );
138     }
139     
140     
141         public void
142     testFindAllRefConfigsByName()
143     {
144         final Set JavaDoc<RefConfig> refs =
145             RefHelper.findAllRefConfigs( getQueryMgr() );
146         
147         final Set JavaDoc<String JavaDoc> names = Util.getNames( refs );
148         final Map JavaDoc<String JavaDoc,Set JavaDoc<RefConfig>> byName =
149             new HashMap JavaDoc<String JavaDoc, Set JavaDoc<RefConfig>>();
150         
151         // initialize map, keyed by name
152
for( final String JavaDoc name : names )
153         {
154             byName.put( name, new HashSet JavaDoc<RefConfig>() );
155         }
156         
157         // populate each Set with RefConfig of the same name
158
for( final RefConfig ref : refs )
159         {
160             final Set JavaDoc<RefConfig> s = byName.get( ref.getName() );
161             
162             s.add( ref );
163         }
164         
165         // verify that the names all refer to the same type
166
for( final String JavaDoc name : byName.keySet() )
167         {
168             final Set JavaDoc<RefConfig> s = byName.get( name );
169             
170             final String JavaDoc lastJ2EEType = s.iterator().next().getJ2EEType();
171             for( final RefConfig ref : s )
172             {
173                  assertEquals( ref.getJ2EEType(), lastJ2EEType );
174             }
175         }
176         
177         // now verify that we can get the same set another way
178
for( final String JavaDoc name : byName.keySet() )
179         {
180             final Set JavaDoc<RefConfig> s = byName.get( name );
181             
182             final String JavaDoc j2eeType = s.iterator().next().getJ2EEType();
183             final Set JavaDoc<RefConfig> s2 =
184                 RefHelper.findAllRefConfigsWithName( getQueryMgr(), j2eeType, name );
185             
186             assertEquals( s, s2 );
187         }
188     }
189
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
Popular Tags