KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.management.config;
25
26 import java.util.Set JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31
32 import com.sun.appserv.management.config.JavaConfig;
33 import com.sun.appserv.management.util.misc.StringUtil;
34 import com.sun.appserv.management.util.misc.GSetUtil;
35
36 import com.sun.enterprise.management.AMXTestBase;
37 import com.sun.enterprise.management.Capabilities;
38
39 /**
40  */

41 public final class JavaConfigTest extends AMXTestBase
42 {
43         public
44     JavaConfigTest ()
45     {
46     }
47
48         public void
49     testGetJVMOptions()
50     {
51         final JavaConfig jc = getConfigConfig().getJavaConfig();
52         
53         final String JavaDoc[] jvmOptions = jc.getJVMOptions();
54         
55         if ( jvmOptions.length < 2 )
56         {
57             warning( "Fewer than 2 JVM options, is this right: " +
58                 StringUtil.toString( jvmOptions ));
59             
60         }
61         
62         /*
63         Arrays.sort( jvmOptions );
64         trace("length = " + jvmOptions.length);
65         for (int ii=0; ii<jvmOptions.length; ii++)
66         {
67             trace("jvmOptions[" + ii + "] = " + jvmOptions[ii]);
68         }
69         */

70     }
71     
72         public void
73     testSetJVMOptions()
74     {
75         final String JavaDoc newOption1 = "-DJavaConfigTest.OK=true";
76         final String JavaDoc newOption2 = "-XJavaConfigTest.OK=true";
77         
78         final JavaConfig jc = getConfigConfig().getJavaConfig();
79         
80         final Set JavaDoc<String JavaDoc> beforeSet = GSetUtil.newUnmodifiableStringSet( jc.getJVMOptions() );
81         
82         // add our new options
83
final Set JavaDoc<String JavaDoc> requestSet = new HashSet JavaDoc<String JavaDoc>( beforeSet );
84         requestSet.add( newOption1 );
85         requestSet.add( newOption2 );
86         jc.setJVMOptions( GSetUtil.toStringArray( requestSet ) );
87
88         Set JavaDoc<String JavaDoc> afterSet = GSetUtil.newUnmodifiableStringSet( jc.getJVMOptions() );
89         
90         // make sure our new options are present
91
assert( afterSet.contains( newOption1 ) );
92         assert( afterSet.contains( newOption2 ) );
93         
94         // make sure all prior options are still present
95
for( final String JavaDoc beforeOption : beforeSet )
96         {
97             assert( afterSet.contains( beforeOption ) );
98         }
99         
100         // now remove our two options
101
requestSet.remove( newOption1 );
102         requestSet.remove( newOption2 );
103         jc.setJVMOptions( GSetUtil.toStringArray( requestSet ) );
104         
105         // verify our two options are gone
106
afterSet = GSetUtil.newUnmodifiableStringSet( jc.getJVMOptions() );
107         assert( ! afterSet.contains( newOption1 ) );
108         assert( ! afterSet.contains( newOption2 ) );
109         
110         // make sure all prior options are still present
111
assert( afterSet.equals( beforeSet ) );
112     }
113     
114         public void
115     testGetters()
116         throws Exception JavaDoc
117     {
118         final JavaConfig jc = getConfigConfig().getJavaConfig();
119         
120         String JavaDoc s;
121         
122         s = jc.getBytecodePreprocessors();
123         if ( s != null )
124         {
125             jc.setBytecodePreprocessors( s );
126         }
127
128         s = jc.getClasspathPrefix();
129         if ( s != null )
130         {
131             jc.setClasspathPrefix( s );
132         }
133
134         s = jc.getClasspathSuffix();
135         if ( s != null )
136         {
137             jc.setClasspathSuffix( s );
138         }
139
140         s = jc.getSystemClasspath();
141         if ( s != null )
142         {
143             jc.setSystemClasspath( s );
144         }
145
146         final boolean debugEnabled = jc.getDebugEnabled();
147         jc.setDebugEnabled( debugEnabled );
148
149         s = jc.getDebugOptions();
150         if ( s != null )
151         {
152             jc.setDebugOptions( s );
153         }
154
155         final boolean envClasspathIgnored = jc.getEnvClasspathIgnored();
156         jc.setEnvClasspathIgnored( envClasspathIgnored );
157
158         s = jc.getJavaHome();
159         if ( s != null )
160         {
161             jc.setJavaHome( s );
162         }
163
164         s = jc.getJavacOptions();
165         if ( s != null )
166         {
167             jc.setJavacOptions( s );
168         }
169
170         final String JavaDoc[] options = jc.getJVMOptions();
171         if ( options != null )
172         {
173             jc.setJVMOptions( options );
174         }
175
176         s = jc.getNativeLibraryPathPrefix();
177         if ( s != null )
178         {
179             jc.setNativeLibraryPathPrefix( s );
180         }
181
182         s = jc.getNativeLibraryPathSuffix();
183         if ( s != null )
184         {
185             jc.setNativeLibraryPathSuffix( s );
186         }
187
188         s = jc.getRMICOptions();
189         if ( s != null )
190         {
191             jc.setRMICOptions( s );
192         }
193
194         s = jc.getServerClasspath();
195         if ( s != null )
196         {
197             jc.setServerClasspath( s );
198         }
199     }
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Popular Tags