KickJava   Java API By Example, From Geeks To Geeks.

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


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.framework.configuration.DefaultConfiguration;
22 import org.apache.avalon.framework.context.DefaultContext;
23 import org.apache.avalon.framework.logger.NullLogger;
24 import org.apache.avalon.framework.parameters.Parameters;
25 import org.apache.avalon.framework.service.DefaultServiceManager;
26
27 /**
28  * This class provides basic facilities for enforcing Avalon's contracts
29  * within your own code.
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.5 $ $Date: 2004/02/28 15:16:27 $
33  */

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