KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > impl > test > DefaultInstrumentManagerImplTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.manager.impl.test;
21
22 import junit.framework.TestCase;
23
24 import org.apache.avalon.framework.configuration.DefaultConfiguration;
25 import org.apache.avalon.framework.logger.ConsoleLogger;
26
27 import org.apache.excalibur.instrument.manager.impl.DefaultInstrumentManagerImpl;
28 import org.apache.excalibur.instrument.manager.InstrumentDescriptor;
29 import org.apache.excalibur.instrument.manager.InstrumentableDescriptor;
30 import org.apache.excalibur.instrument.manager.NoSuchInstrumentException;
31 import org.apache.excalibur.instrument.manager.NoSuchInstrumentableException;
32
33 /**
34  * Test of the DefaultInstrumentManagerImpl.
35  *
36  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
37  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:36 $
38  */

39 public class DefaultInstrumentManagerImplTestCase
40     extends TestCase
41 {
42     private DefaultInstrumentManagerImpl m_instrumentManager;
43     
44     /*---------------------------------------------------------------
45      * Constructors
46      *-------------------------------------------------------------*/

47     public DefaultInstrumentManagerImplTestCase( String JavaDoc name )
48     {
49         super( name );
50     }
51     
52     /*---------------------------------------------------------------
53      * TestCase Methods
54      *-------------------------------------------------------------*/

55     public void setUp()
56         throws Exception JavaDoc
57     {
58         System.out.println( "setUp()" );
59         
60         super.setUp();
61         
62         DefaultConfiguration instrumentConfig = new DefaultConfiguration( "instrument" );
63         
64         m_instrumentManager = new DefaultInstrumentManagerImpl();
65         m_instrumentManager.enableLogging( new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
66         m_instrumentManager.configure( instrumentConfig );
67         m_instrumentManager.initialize();
68     }
69     
70     public void tearDown()
71         throws Exception JavaDoc
72     {
73         System.out.println( "tearDown()" );
74         m_instrumentManager.dispose();
75         m_instrumentManager = null;
76         
77         super.tearDown();
78     }
79     
80     /*---------------------------------------------------------------
81      * Methods
82      *-------------------------------------------------------------*/

83     private void assertInstrumentableExists( String JavaDoc name )
84     {
85         InstrumentableDescriptor descriptor =
86             m_instrumentManager.locateInstrumentableDescriptor( name );
87         assertEquals( "Looked up instrumentable name incorrect.", descriptor.getName(), name );
88     }
89     
90     private void assertInstrumentableNotExists( String JavaDoc name )
91     {
92         try
93         {
94             m_instrumentManager.locateInstrumentableDescriptor( name );
95             fail( "Found an instrumentable named " + name + " when it should not have existed." );
96         }
97         catch( NoSuchInstrumentableException e )
98         {
99             // Ok
100
}
101     }
102     
103     private void assertInstrumentExists( String JavaDoc name )
104     {
105         InstrumentDescriptor descriptor =
106             m_instrumentManager.locateInstrumentDescriptor( name );
107         assertEquals( "Looked up instrument name incorrect.", descriptor.getName(), name );
108     }
109     
110     private void assertInstrumentNotExists( String JavaDoc name )
111     {
112         try
113         {
114             m_instrumentManager.locateInstrumentDescriptor( name );
115             fail( "Found an instrument named " + name + " when it should not have existed." );
116         }
117         catch( NoSuchInstrumentException e )
118         {
119             // Ok
120
}
121     }
122     
123     /* Never called
124     private void assertInstrumentSampleExists( String name )
125     {
126         InstrumentSampleDescriptor descriptor =
127             m_instrumentManager.locateInstrumentSampleDescriptor( name );
128         assertEquals( "Looked up instrument sample name incorrect.", descriptor.getName(), name );
129     }
130     */

131     /* Never called
132     private void assertInstrumentSampleNotExists( String name )
133     {
134         try
135         {
136             InstrumentSampleDescriptor descriptor =
137                 m_instrumentManager.locateInstrumentSampleDescriptor( name );
138             fail( "Found an instrument sample named " + name + " when it should not have existed." );
139         }
140         catch( NoSuchInstrumentSampleException e )
141         {
142             // Ok
143         }
144     }
145     */

146     
147     /*---------------------------------------------------------------
148      * Test Cases
149      *-------------------------------------------------------------*/

150     public void testCreateDestroy() throws Exception JavaDoc
151     {
152     }
153
154     public void testLookupDefaultInstruments() throws Exception JavaDoc
155     {
156         // Look for elements which should always exist.
157
assertInstrumentableExists( "instrument-manager" );
158         assertInstrumentExists( "instrument-manager.total-memory" );
159         assertInstrumentExists( "instrument-manager.free-memory" );
160         assertInstrumentExists( "instrument-manager.memory" );
161         assertInstrumentExists( "instrument-manager.active-thread-count" );
162         
163         // Look for elements which should not exist.
164
assertInstrumentableNotExists( "instrument-manager.total-memory" );
165         assertInstrumentableNotExists( "instrument-manager.foobar" );
166         assertInstrumentableNotExists( "foobar" );
167         assertInstrumentNotExists( "instrument-manager.foobar" );
168     }
169     
170     public void testLookupSamples() throws Exception JavaDoc
171     {
172         
173     }
174 }
175
176
Popular Tags