KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > util > test > ContextManagerTestCase


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 /**
32  * ContextManagerTestCase does XYZ
33  *
34  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
35  * @version CVS $ Revision: 1.1 $
36  */

37 public class ContextManagerTestCase extends TestCase implements ContainerManagerConstants
38 {
39     private ContextManager m_manager;
40     private InstrumentManager m_instrManager;
41
42     public ContextManagerTestCase( String JavaDoc name )
43     {
44         super( name );
45     }
46
47     public void setUp() throws Exception JavaDoc
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 JavaDoc
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