1 17 18 package org.apache.avalon.fortress.impl.extensions.test; 19 20 import junit.framework.TestCase; 21 import junit.framework.Assert; 22 import org.apache.avalon.fortress.impl.extensions.InstrumentableCreator; 23 import org.apache.avalon.framework.context.DefaultContext; 24 import org.apache.avalon.lifecycle.Creator; 25 import org.apache.excalibur.instrument.Instrument; 26 import org.apache.excalibur.instrument.InstrumentManageable; 27 import org.apache.excalibur.instrument.InstrumentManager; 28 import org.apache.excalibur.instrument.Instrumentable; 29 30 36 public class InstrumentableCreatorTestCase extends TestCase 37 { 38 private Instrumentable m_instrumentable; 39 private DefaultContext m_context; 40 private InstrumentManager m_instrumentManager; 41 private boolean m_isActive = false; 42 43 public InstrumentableCreatorTestCase( String name ) 44 { 45 super( name ); 46 } 47 48 public void setUp() 49 { 50 m_instrumentable = new TestInstrumentable(); 51 m_instrumentManager = new TestInstrumentManager(); 52 m_context = new DefaultContext(); 53 m_context.put( "component.name", "component1" ); 54 m_context.makeReadOnly(); 55 } 56 57 public void testNoInstrumentManager() throws Exception 58 { 59 Creator creator = new InstrumentableCreator( null ); 60 61 creator.create( m_instrumentable, m_context ); 62 creator.destroy( m_instrumentable, m_context ); 63 } 64 65 public void testInstrumentManager() throws Exception 66 { 67 Creator creator = new InstrumentableCreator( m_instrumentManager ); 68 m_isActive = true; 69 70 creator.create( m_instrumentable, m_context ); 71 creator.destroy( m_instrumentable, m_context ); 72 } 73 74 class TestInstrumentable implements Instrumentable, InstrumentManageable 75 { 76 private static final String DEFAULT_NAME = "test"; 77 private String m_name = DEFAULT_NAME; 78 private String m_assigned; 79 80 public void setInstrumentableName( String name ) 81 { 82 assertTrue( m_isActive ); 83 assertNotNull( name ); 84 m_name = name; 85 m_assigned = m_name; 86 } 87 88 public String getInstrumentableName() 89 { 90 assertTrue( m_isActive ); 91 assertNotNull( m_name ); 92 93 if ( null == m_assigned ) 94 { 95 assertEquals( DEFAULT_NAME, m_name ); 96 } 97 else 98 { 99 assertEquals( m_assigned, m_name ); 100 } 101 102 return m_name; 103 } 104 105 public Instrument[] getInstruments() 106 { 107 assertTrue( m_isActive ); 108 return new Instrument[0]; 109 } 110 111 public Instrumentable[] getChildInstrumentables() 112 { 113 assertTrue( m_isActive ); 114 return new Instrumentable[0]; 115 } 116 117 public void setInstrumentManager( InstrumentManager instrumentManager ) 118 { 119 assertTrue( m_isActive ); 120 } 121 } 122 } 123 | Popular Tags |