KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.HashMap JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29
30 import com.sun.appserv.management.base.Util;
31
32 import com.sun.appserv.management.config.JavaConfig;
33 import com.sun.appserv.management.config.ProfilerConfig;
34 import com.sun.appserv.management.config.ProfilerConfigKeys;
35
36 import com.sun.appserv.management.util.jmx.JMXUtil;
37
38
39 import com.sun.enterprise.management.AMXTestBase;
40 import com.sun.enterprise.management.Capabilities;
41
42 /**
43  */

44 public final class ProfilerConfigTest extends AMXTestBase
45 {
46     private static final String JavaDoc NATIVE_LIBRARY_PATH = "a/b/c";
47     private static final String JavaDoc CLASSPATH = "/foo/bar";
48     
49         private static Map JavaDoc<String JavaDoc,String JavaDoc>
50     getOptional()
51     {
52         final Map JavaDoc<String JavaDoc,String JavaDoc> optional = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
53         optional.put( ProfilerConfigKeys.NATIVE_LIBRARY_PATH_KEY, NATIVE_LIBRARY_PATH);
54         optional.put( ProfilerConfigKeys.CLASSPATH_KEY, CLASSPATH);
55         optional.put( ProfilerConfigKeys.ENABLED_KEY, "false");
56         return optional;
57     }
58
59         public
60     ProfilerConfigTest ()
61     {
62         if ( checkNotOffline( "testIllegalCreate" ) )
63         {
64             ensureDefaultInstance( getConfigConfig().getJavaConfig() );
65         }
66     }
67     
68         public static ProfilerConfig
69     ensureDefaultInstance( final JavaConfig javaConfig )
70     {
71         ProfilerConfig prof = javaConfig.getProfilerConfig( );
72         if ( prof == null )
73         {
74             final String JavaDoc NAME = "profiler";
75             
76             prof = javaConfig.createProfilerConfig( NAME, getOptional() );
77             assert prof != null;
78         }
79         
80         return prof;
81     }
82     
83         private void
84     testGetters( final ProfilerConfig prof )
85     {
86         assert( prof.getClasspath() != null );
87         prof.setClasspath( prof.getClasspath() );
88         
89         assert( prof.getNativeLibraryPath() != null );
90         prof.setNativeLibraryPath( prof.getNativeLibraryPath() );
91         
92         assert( prof.getJVMOptions() != null );
93         prof.setJVMOptions( prof.getJVMOptions() );
94         
95         prof.setEnabled( prof.getEnabled() );
96     }
97     
98         public synchronized void
99     testCreateRemoveProfiler()
100         throws Exception JavaDoc
101     {
102         if ( checkNotOffline( "testIllegalCreate" ) )
103         {
104             ensureDefaultInstance( getConfigConfig().getJavaConfig() );
105             
106             final JavaConfig javaConfig = getConfigConfig().getJavaConfig();
107             
108             javaConfig.removeProfilerConfig();
109             assert javaConfig.getProfilerConfig() == null :
110                 "Can't remove ProfilerConfig from " +
111                     JMXUtil.toString( Util.getObjectName(javaConfig) );
112             
113             ensureDefaultInstance( javaConfig );
114             assert javaConfig.getProfilerConfig() != null;
115             Util.getExtra( javaConfig.getProfilerConfig() ).getMBeanInfo();
116             
117             testGetters( javaConfig.getProfilerConfig() );
118             
119             javaConfig.removeProfilerConfig();
120             ensureDefaultInstance( javaConfig );
121             assert javaConfig.getProfilerConfig() != null;
122             Util.getExtra( javaConfig.getProfilerConfig() ).getMBeanInfo();
123             testGetters( javaConfig.getProfilerConfig() );
124         }
125     }
126 }
127
128
129
Popular Tags