KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > impl > extensions > test > InstrumentableCreatorTestCase


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

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 JavaDoc 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 JavaDoc
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 JavaDoc
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 JavaDoc DEFAULT_NAME = "test";
77         private String JavaDoc m_name = DEFAULT_NAME;
78         private String JavaDoc m_assigned;
79
80         public void setInstrumentableName( String JavaDoc name )
81         {
82             assertTrue( m_isActive );
83             assertNotNull( name );
84             m_name = name;
85             m_assigned = m_name;
86         }
87
88         public String JavaDoc 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