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