KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > util > test > ComponentTestCase


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.util.test;
9
10 import junit.framework.TestCase;
11 import org.apache.avalon.framework.component.ComponentException;
12 import org.apache.avalon.framework.component.DefaultComponentManager;
13 import org.apache.avalon.framework.configuration.ConfigurationException;
14 import org.apache.avalon.framework.configuration.DefaultConfiguration;
15 import org.apache.avalon.framework.context.ContextException;
16 import org.apache.avalon.framework.context.DefaultContext;
17 import org.apache.avalon.framework.logger.LogKitLogger;
18 import org.apache.avalon.framework.parameters.ParameterException;
19 import org.apache.avalon.framework.parameters.Parameters;
20 import org.apache.log.Hierarchy;
21
22 /**
23  * This class provides basic facilities for enforcing Avalon's contracts
24  * within your own code.
25  *
26  * @author <a HREF="bloritsch@apache.org">Berin Loritsch</a>
27  * @version CVS $Revision: 1.3 $ $Date: 2002/01/17 15:02:01 $
28  */

29 public final class ComponentTestCase
30     extends TestCase
31 {
32     public ComponentTestCase( String JavaDoc test )
33     {
34         super( test );
35     }
36
37     public void testCorrectLifecycle()
38         throws Exception JavaDoc
39     {
40         FullLifecycleComponent component = new FullLifecycleComponent();
41
42         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
43         component.contextualize(new DefaultContext());
44         component.compose(new DefaultComponentManager());
45         component.configure(new DefaultConfiguration("", ""));
46         component.parameterize(new Parameters());
47         component.initialize();
48         component.start();
49         component.suspend();
50         component.resume();
51         component.stop();
52         component.dispose();
53     }
54
55     public void testMissingLogger()
56         throws Exception JavaDoc
57     {
58         FullLifecycleComponent component = new FullLifecycleComponent();
59
60         try
61         {
62             component.contextualize(new DefaultContext());
63         }
64         catch ( Exception JavaDoc e )
65         {
66             return;
67         }
68         fail("Did not detect missing logger");
69     }
70
71     public void testOutOfOrderInitialize()
72         throws Exception JavaDoc
73     {
74         FullLifecycleComponent component = new FullLifecycleComponent();
75
76         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
77         component.contextualize(new DefaultContext());
78         component.compose(new DefaultComponentManager());
79         try
80         {
81             component.initialize();
82             component.parameterize(new Parameters());
83         }
84         catch ( Exception JavaDoc e )
85         {
86             return;
87         }
88         fail("Did not detect out of order initialization");
89     }
90
91     public void testOutOfOrderDispose()
92         throws Exception JavaDoc
93     {
94         FullLifecycleComponent component = new FullLifecycleComponent();
95
96         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
97         component.contextualize(new DefaultContext());
98         component.compose(new DefaultComponentManager());
99         component.configure(new DefaultConfiguration("", ""));
100         component.parameterize(new Parameters());
101         component.initialize();
102         component.start();
103         component.suspend();
104         component.resume();
105
106         try
107         {
108             component.dispose();
109             component.stop();
110         }
111         catch ( Exception JavaDoc e )
112         {
113             return;
114         }
115         fail("Did not detect out of order disposal");
116     }
117
118     public void testDoubleAssignOfLogger()
119     {
120         FullLifecycleComponent component = new FullLifecycleComponent();
121
122         try
123         {
124             component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
125             component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
126         }
127         catch (Exception JavaDoc e)
128         {
129             // test successfull
130
return;
131         }
132
133         fail("Did not detect double assignment of Logger");
134     }
135
136     public void testDoubleAssignOfContext()
137     {
138         FullLifecycleComponent component = new FullLifecycleComponent();
139
140         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
141         try
142         {
143             component.contextualize(new DefaultContext());
144             component.contextualize(new DefaultContext());
145         }
146         catch (Exception JavaDoc e)
147         {
148             // test successfull
149
return;
150         }
151
152         fail("Did not detect double assignment of Context");
153     }
154
155     public void testDoubleAssignOfParameters()
156         throws Exception JavaDoc
157     {
158         FullLifecycleComponent component = new FullLifecycleComponent();
159
160         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
161         component.contextualize(new DefaultContext());
162         component.compose(new DefaultComponentManager());
163         component.configure(new DefaultConfiguration("", ""));
164
165         try
166         {
167             component.parameterize(new Parameters());
168             component.parameterize(new Parameters());
169         }
170         catch (Exception JavaDoc e)
171         {
172             // test successfull
173
return;
174         }
175
176         fail("Did not detect double assignment of Parameters");
177     }
178
179     public void testDoubleAssignOfConfiguration() throws Exception JavaDoc
180     {
181         FullLifecycleComponent component = new FullLifecycleComponent();
182
183         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
184         component.contextualize(new DefaultContext());
185         component.compose(new DefaultComponentManager());
186         try
187         {
188             component.configure(new DefaultConfiguration("", ""));
189             component.configure(new DefaultConfiguration("", ""));
190         }
191         catch (Exception JavaDoc e)
192         {
193             // test successfull
194
return;
195         }
196
197         fail("Did not detect double assignment of Configuration");
198     }
199
200     public void testDoubleAssignOfComponentManger()
201         throws Exception JavaDoc
202     {
203         FullLifecycleComponent component = new FullLifecycleComponent();
204
205         component.enableLogging(new LogKitLogger(Hierarchy.getDefaultHierarchy().getLoggerFor("")));
206         component.contextualize(new DefaultContext());
207         try
208         {
209             component.compose(new DefaultComponentManager());
210             component.compose(new DefaultComponentManager());
211         }
212         catch (Exception JavaDoc e)
213         {
214             // test successfull
215
return;
216         }
217
218         fail("Did not detect double assignment of ComponentManager");
219     }
220 }
221
Popular Tags