1 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 39 public class DefaultInstrumentManagerImplTestCase 40 extends TestCase 41 { 42 private DefaultInstrumentManagerImpl m_instrumentManager; 43 44 47 public DefaultInstrumentManagerImplTestCase( String name ) 48 { 49 super( name ); 50 } 51 52 55 public void setUp() 56 throws Exception 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 72 { 73 System.out.println( "tearDown()" ); 74 m_instrumentManager.dispose(); 75 m_instrumentManager = null; 76 77 super.tearDown(); 78 } 79 80 83 private void assertInstrumentableExists( String 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 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 } 101 } 102 103 private void assertInstrumentExists( String 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 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 } 121 } 122 123 131 146 147 150 public void testCreateDestroy() throws Exception 151 { 152 } 153 154 public void testLookupDefaultInstruments() throws Exception 155 { 156 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 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 171 { 172 173 } 174 } 175 176 | Popular Tags |