KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > base > AMXDebugTest


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

29 package com.sun.enterprise.management.base;
30
31 import java.io.File JavaDoc;
32
33 import com.sun.appserv.management.base.AMXDebug;
34 import com.sun.appserv.management.util.misc.Output;
35
36
37
38 import com.sun.enterprise.management.AMXTestBase;
39 import com.sun.enterprise.management.Capabilities;
40
41 import com.sun.enterprise.management.Capabilities;
42
43 /**
44  */

45 public final class AMXDebugTest extends junit.framework.TestCase
46 {
47         public
48     AMXDebugTest()
49     {
50         getAMXDebug().setDefaultDebug( true );
51         getAMXDebug().setAll( true );
52     }
53     
54         private String JavaDoc
55     getID( final String JavaDoc uniquifier )
56     {
57         return this.getClass().getName() + "." + uniquifier;
58     }
59     
60         private Output
61     getOutput( final String JavaDoc id )
62     {
63         return getAMXDebug().getOutput( id );
64     }
65     
66         private AMXDebug
67     getAMXDebug()
68     {
69         return AMXDebug.getInstance();
70     }
71        
72         public synchronized void
73     testCreateFile()
74     {
75         // multiple iterations require that we choose a new file each time
76
final String JavaDoc id = getID( "testCreateFile" + System.currentTimeMillis() );
77         final Output output = getOutput( id );
78         
79         final File JavaDoc outputFile = getAMXDebug().getOutputFile( id );
80         outputFile.delete();
81         assert( ! outputFile.exists() );
82         
83         output.printDebug( "test" );
84         assert( outputFile.exists() );
85     }
86        
87         public synchronized void
88     testToggleDebug()
89     {
90         final String JavaDoc id = getID( "testToggleDebug" );
91         final Output output = getOutput( id );
92         
93         getAMXDebug().setDebug( id, false );
94         assert( ! getAMXDebug().getDebug( id ) );
95         getAMXDebug().setDebug( id, true );
96         assert( getAMXDebug().getDebug( id ) );
97     }
98     
99         public synchronized void
100     testReset()
101     {
102         final String JavaDoc id = getID( "testReset" );
103         final Output output = getOutput( id );
104         
105         getAMXDebug().reset( id );
106         final File JavaDoc outputFile = getAMXDebug().getOutputFile( id );
107         outputFile.delete();
108         assert( ! outputFile.exists() );
109         output.printDebug( "test" );
110         assert( outputFile.exists() );
111         
112         // make sure we can call it repeatedly
113
getAMXDebug().reset( id );
114         getAMXDebug().reset( id );
115         getAMXDebug().reset( id );
116     }
117     
118     
119         public synchronized void
120     testPrint()
121     {
122         final String JavaDoc id = getID( "testPrint" );
123         final Output output = getOutput( id );
124         
125         output.printDebug( "printDebug" );
126         output.printError( "printError" );
127         output.println( "println" );
128         output.print( "print" );output.print( "..." );output.print( "END" );
129     }
130     
131     
132         public synchronized void
133     testClose()
134     {
135         final String JavaDoc id = getID( "testClose" );
136         final Output output = getOutput( id );
137         final File JavaDoc outputFile = getAMXDebug().getOutputFile( id );
138         
139         output.println( "hello" );
140         assert( outputFile.exists() );
141         
142         output.close();
143         outputFile.delete();
144         assert( !outputFile.exists() );
145         
146         output.println( "hello" );
147         assert( outputFile.exists() );
148     }
149     
150         public synchronized void
151     testToggleDefaultDebug()
152     {
153         final String JavaDoc id = getID( "testToggleDefaultDebug" );
154         final Output output = getOutput( id );
155         
156         getAMXDebug().setDefaultDebug( false );
157         assert( ! getAMXDebug().getDefaultDebug() );
158         
159         getAMXDebug().setDefaultDebug( true );
160         assert( getAMXDebug().getDefaultDebug() );
161     }
162     
163     
164         public synchronized void
165     testSetAll()
166     {
167         final String JavaDoc id = getID( "testSetAll" );
168         final Output output = getOutput( id );
169         
170         getAMXDebug().setAll( false );
171         getAMXDebug().setAll( false );
172         getAMXDebug().setAll( true );
173         getAMXDebug().setAll( true );
174         getAMXDebug().setAll( false );
175         getAMXDebug().setAll( true );
176         getAMXDebug().setAll( true );
177     }
178     
179     
180         public synchronized void
181     testMark()
182     {
183         final String JavaDoc id = getID( "testMark" );
184         final Output output = getOutput( id );
185         
186         getAMXDebug().mark( id );
187         getAMXDebug().mark( id, null );
188         getAMXDebug().mark( id, "marker 1" );
189         getAMXDebug().mark( id, "marker 2" );
190         getAMXDebug().mark( output, null );
191         getAMXDebug().mark( output, "marker 3" );
192     }
193 }
194
195
Popular Tags