1 19 20 package org.apache.excalibur.instrument.test; 21 22 import junit.framework.TestCase; 23 24 import org.apache.avalon.framework.logger.ConsoleLogger; 25 import org.apache.excalibur.instrument.CounterInstrument; 26 import org.apache.excalibur.instrument.Instrument; 27 import org.apache.excalibur.instrument.Instrumentable; 28 import org.apache.excalibur.instrument.ValueInstrument; 29 30 36 public class LogEnabledInstrumentableTestCase 37 extends TestCase 38 { 39 42 public LogEnabledInstrumentableTestCase( String name ) 43 { 44 super( name ); 45 } 46 47 50 51 54 private void generalTest( Instrument[] instruments, Instrumentable[] children ) 55 throws Exception 56 { 57 AbstractLogEnabledInstrumentableImpl impl = 58 new AbstractLogEnabledInstrumentableImpl( "base" ); 59 impl.enableLogging( new ConsoleLogger() ); 60 61 impl.setInstrumentableName( "test" ); 63 64 for ( int i = 0; i < instruments.length; i++ ) 66 { 67 impl.addInstrument( instruments[i] ); 68 } 69 70 for ( int i = 0; i < children.length; i++ ) 72 { 73 impl.addChildInstrumentable( children[i] ); 74 } 75 76 assertEquals( "Instrumentable name incorrect.", impl.getInstrumentableName(), "test" ); 78 79 80 Instrument[] implInstruments = impl.getInstruments(); 82 assertEquals( "The number of instruments is not correct.", 83 implInstruments.length, instruments.length ); 84 for ( int i = 0; i < instruments.length; i++ ) 85 { 86 assertEquals( "Instrument[i] is not correct.", implInstruments[i], instruments[i] ); 87 } 88 89 try 91 { 92 impl.addInstrument( new CounterInstrument( "bad" ) ); 93 fail( "Should not have been able to add more instruments" ); 94 } 95 catch ( IllegalStateException e ) 96 { 97 } 99 100 101 Instrumentable[] implChildren = impl.getChildInstrumentables(); 103 assertEquals( "The number of child instrumentables is not correct.", 104 implChildren.length, children.length ); 105 for ( int i = 0; i < children.length; i++ ) 106 { 107 assertEquals( "Child[i] is not correct.", implChildren[i], children[i] ); 108 } 109 110 try 112 { 113 impl.addChildInstrumentable( new AbstractInstrumentableImpl( "bad" ) ); 114 fail( "Should not have been able to add more child instrumentables" ); 115 } 116 catch ( IllegalStateException e ) 117 { 118 } 120 } 121 122 125 public void testEmpty() throws Exception 126 { 127 Instrument[] instruments = new Instrument[] {}; 128 Instrumentable[] children = new Instrumentable[] {}; 129 130 generalTest( instruments, children ); 131 } 132 133 public void test1Instrument() throws Exception 134 { 135 Instrument[] instruments = new Instrument[] 136 { 137 new CounterInstrument( "c1" ) 138 }; 139 Instrumentable[] children = new Instrumentable[] {}; 140 141 generalTest( instruments, children ); 142 } 143 144 public void testNInstrument() throws Exception 145 { 146 Instrument[] instruments = new Instrument[] 147 { 148 new CounterInstrument( "c1" ), 149 new ValueInstrument( "v1" ), 150 new CounterInstrument( "c2" ), 151 new ValueInstrument( "v2" ), 152 new CounterInstrument( "c3" ), 153 new ValueInstrument( "v3" ), 154 new CounterInstrument( "c4" ), 155 new ValueInstrument( "v4" ) 156 }; 157 Instrumentable[] children = new Instrumentable[] {}; 158 159 generalTest( instruments, children ); 160 } 161 162 public void test1ChildInstrumentable() throws Exception 163 { 164 Instrument[] instruments = new Instrument[] {}; 165 Instrumentable[] children = new Instrumentable[] 166 { 167 new AbstractInstrumentableImpl( "i1" ) 168 }; 169 170 generalTest( instruments, children ); 171 } 172 173 public void testNChildInstrumentable() throws Exception 174 { 175 Instrument[] instruments = new Instrument[] {}; 176 Instrumentable[] children = new Instrumentable[] 177 { 178 new AbstractInstrumentableImpl( "i1" ), 179 new AbstractInstrumentableImpl( "i2" ), 180 new AbstractInstrumentableImpl( "i3" ), 181 new AbstractInstrumentableImpl( "i4" ), 182 new AbstractInstrumentableImpl( "i5" ), 183 new AbstractInstrumentableImpl( "i6" ) 184 }; 185 186 generalTest( instruments, children ); 187 } 188 } 189 190 | Popular Tags |