1 17 18 package org.apache.avalon.fortress.util.test; 19 20 import junit.framework.TestCase; 21 import org.apache.avalon.fortress.ContainerManagerConstants; 22 import org.apache.avalon.fortress.util.ContextManager; 23 import org.apache.avalon.fortress.util.FortressConfig; 24 import org.apache.avalon.framework.container.ContainerUtil; 25 import org.apache.avalon.framework.context.Context; 26 import org.apache.avalon.framework.logger.ConsoleLogger; 27 import org.apache.avalon.framework.service.ServiceManager; 28 import org.apache.excalibur.instrument.InstrumentManager; 29 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; 30 31 37 public class ContextManagerTestCase extends TestCase implements ContainerManagerConstants 38 { 39 private ContextManager m_manager; 40 private InstrumentManager m_instrManager; 41 42 public ContextManagerTestCase( String name ) 43 { 44 super( name ); 45 } 46 47 public void setUp() throws Exception 48 { 49 FortressConfig config = new FortressConfig( FortressConfig.createDefaultConfig() ); 50 config.setContainerConfiguration( "resource://org/apache/avalon/fortress/test/data/test1.xconf" ); 51 config.setLoggerManagerConfiguration( "resource://org/apache/avalon/fortress/test/data/test1.xlog" ); 52 53 m_instrManager = new DefaultInstrumentManager(); 54 ContainerUtil.enableLogging(m_instrManager, new ConsoleLogger()); 55 ContainerUtil.initialize(m_instrManager); 56 config.setInstrumentManager(m_instrManager); 57 58 m_manager = new ContextManager( config.getContext(), new ConsoleLogger() ); 59 m_manager.initialize(); 60 } 61 62 public void testContextManager() throws Exception 63 { 64 final Context managerContext = m_manager.getContainerManagerContext(); 65 assertNotNull( managerContext ); 66 67 final ServiceManager serviceManager = (ServiceManager) managerContext.get( SERVICE_MANAGER ); 68 assertNotNull( serviceManager ); 69 70 final InstrumentManager instrumentManager = 71 (InstrumentManager) serviceManager.lookup( InstrumentManager.ROLE ); 72 assertNotNull( instrumentManager ); 73 assertSame( m_instrManager, instrumentManager ); 74 } 75 76 public void tearDown() 77 { 78 m_manager.dispose(); 79 } 80 } 81 | Popular Tags |