KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-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 package org.apache.avalon.excalibur.testcase.test;
18
19 import junit.framework.TestCase;
20
21 import org.apache.avalon.excalibur.testcase.FullLifecycleComponent;
22 import org.apache.avalon.framework.configuration.DefaultConfiguration;
23 import org.apache.avalon.framework.context.DefaultContext;
24 import org.apache.avalon.framework.logger.NullLogger;
25 import org.apache.avalon.framework.parameters.Parameters;
26 import org.apache.avalon.framework.service.DefaultServiceManager;
27
28 /**
29  * This class provides basic facilities for enforcing Avalon's contracts
30  * within your own code.
31  *
32  * @deprecated ECM is no longer supported
33  *
34  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
35  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:36 $
36  */

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

228 }
229
Popular Tags