KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > ext > offline > OfflineDottedNamePrefixesTest


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.ext.offline;
24
25 import java.util.Set JavaDoc;
26 import java.util.HashSet JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29
30 import com.sun.appserv.management.base.Util;
31 import com.sun.appserv.management.util.misc.GSetUtil;
32 import com.sun.appserv.management.util.misc.CollectionUtil;
33 import com.sun.appserv.management.config.ConfigElement;
34
35 import com.sun.enterprise.management.AMXTestBase;
36 import com.sun.enterprise.management.offline.OfflineDottedNamePrefixes;
37
38
39 /**
40  */

41 public final class OfflineDottedNamePrefixesTest extends AMXTestBase
42 {
43         public
44     OfflineDottedNamePrefixesTest()
45     {
46     }
47
48         private ObjectName JavaDoc
49     ON( final String JavaDoc objectNameString )
50     {
51         return Util.newObjectName( objectNameString );
52     }
53     
54         public void
55     testGetInstance()
56     {
57         assert OfflineDottedNamePrefixes.getInstance() != null;
58     }
59     
60     private static final String JavaDoc DOMAIN="amx:j2eeType=X-DomainConfig,name=na";
61     private static final String JavaDoc SERVER_CONFIG="amx:j2eeType=X-StandaloneServerConfig,name=server-config";
62     
63         private String JavaDoc
64     getPrefix( final String JavaDoc objectNameString )
65     {
66         return getPrefix( ON( objectNameString ) );
67     }
68     
69        private String JavaDoc
70     getPrefix( final ObjectName JavaDoc objectName )
71     {
72         final OfflineDottedNamePrefixes prefixes =
73             OfflineDottedNamePrefixes.getInstance();
74         
75         return prefixes.getPrefix( objectName );
76     }
77     
78         public void
79     testIllegal()
80     {
81         try
82         {
83             assert( getPrefix( "amx:foo=bar" ) == null );
84             assert false;
85         }
86         catch( Exception JavaDoc e )
87         {
88         }
89     }
90     
91         public void
92     testGetPrefix()
93     {
94         assert( getPrefix( DOMAIN ).equals( "domain" ) );
95         assert( getPrefix( SERVER_CONFIG ).equals( "server-config" ) );
96     }
97     
98         public void
99     testAllAMXConfig()
100     {
101         if ( getConnection() == null )
102         {
103             warning( "testAllAMXConfig: No MBeanServerConnection, skipping test" );
104             return;
105         }
106         
107         final Set JavaDoc<ConfigElement> all = getTestUtil().getAllAMX( ConfigElement.class );
108         
109         final Set JavaDoc<String JavaDoc> missing = new HashSet JavaDoc<String JavaDoc>();
110         for( final ConfigElement config : all )
111         {
112             final ObjectName JavaDoc objectName = Util.getObjectName( config );
113             final String JavaDoc prefix = getPrefix( objectName );
114             if ( prefix == null )
115             {
116                 missing.add( config.getJ2EEType() );
117             }
118             else
119             {
120                 //trace( prefix );
121
}
122         }
123         
124         if ( missing.size() != 0 )
125         {
126             //warning( "The following j2eeTypes do not yet have prefix support: " + NEWLINE +
127
//CollectionUtil.toString( missing, NEWLINE ) );
128
}
129     }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Popular Tags