KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > MockContainer


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

20 package org.apache.cactus.integration.ant.container;
21
22 import java.io.File JavaDoc;
23
24 import junit.framework.Assert;
25
26 import org.apache.cactus.integration.ant.deployment.DeployableFile;
27 import org.apache.cactus.integration.ant.util.AntTaskFactory;
28 import org.apache.commons.logging.Log;
29 import org.apache.tools.ant.types.Path;
30 import org.apache.tools.ant.types.Environment.Variable;
31
32 /**
33  * Mock implementation of the {@link Container} interface.
34  *
35  * @version $Id: MockContainer.java,v 1.14 2004/05/31 20:05:23 vmassol Exp $
36  */

37 public final class MockContainer implements Container
38 {
39     // Instance Variables ------------------------------------------------------
40

41     /**
42      * The dummy server.
43      */

44     private MockHttpServer server;
45
46     /**
47      * Whether it is expected that the startUp() method is called.
48      * <code>null</code> for "Don't care".
49      */

50     private Boolean JavaDoc expectedStartUpCalled;
51
52     /**
53      * Whether the startUp() method was called.
54      */

55     private boolean startUpCalled;
56
57     /**
58      * Whether it is expected that the shutDown() method is called.
59      * <code>null</code> for "Don't care".
60      */

61     private Boolean JavaDoc expectedShutDownCalled;
62
63     /**
64      * Whether the shutDown() method was called.
65      */

66     private boolean shutDownCalled;
67
68     // Constructors ------------------------------------------------------------
69

70     /**
71      * Constructor.
72      *
73      * @param theServer The dummy HTTP server
74      */

75     public MockContainer(MockHttpServer theServer)
76     {
77         this.server = theServer;
78     }
79
80     /**
81      * Constructor.
82      */

83     public MockContainer()
84     {
85     }
86
87     // Container Implementation ------------------------------------------------
88

89     /**
90      * @see Container#getName()
91      */

92     public String JavaDoc getName()
93     {
94         return null;
95     }
96
97     /**
98      * @see Container#getTestContext()
99      */

100     public String JavaDoc getTestContext()
101     {
102         return null;
103     }
104     
105     /**
106      * @see Container#getStartUpWait()
107      */

108     public long getStartUpWait()
109     {
110         return 0;
111     }
112     
113     /**
114      * @see Container#getPort()
115      */

116     public int getPort()
117     {
118         return 0;
119     }
120
121     /**
122      * @see Container#getToDir()
123      */

124     public File JavaDoc getToDir()
125     {
126         return null;
127     }
128
129     /**
130      * @see Container#init()
131      */

132     public void init()
133     {
134     }
135
136     /**
137      * @see Container#isEnabled()
138      */

139     public boolean isEnabled()
140     {
141         return false;
142     }
143
144     /**
145      * @see Container#isExcluded(java.lang.String)
146      */

147     public boolean isExcluded(String JavaDoc theTestName)
148     {
149         return false;
150     }
151
152     /**
153      * @see Container#setAntTaskFactory(AntTaskFactory)
154      */

155     public void setAntTaskFactory(AntTaskFactory theFactory)
156     {
157     }
158
159     /**
160      * @see Container#setLog(Log)
161      */

162     public void setLog(Log theLog)
163     {
164     }
165
166     /**
167      * @see Container#setDeployableFile
168      */

169     public void setDeployableFile(DeployableFile theWarFile)
170     {
171     }
172
173     /**
174      * @see Container#startUp()
175      */

176     public void startUp()
177     {
178         this.startUpCalled = true;
179         if (this.server != null)
180         {
181             Thread JavaDoc thread = new Thread JavaDoc(this.server);
182             thread.start();
183         }
184     }
185
186     /**
187      * @see Container#shutDown()
188      */

189     public void shutDown()
190     {
191         this.shutDownCalled = true;
192         if (this.server != null)
193         {
194             this.server.stop();
195         }
196     }
197
198     // Public Methods ----------------------------------------------------------
199

200     /**
201      * Sets whether to expect a call to the startUp() method.
202      *
203      * @param isExpected Whether a call is expected or not
204      */

205     public void expectStartUpCalled(boolean isExpected)
206     {
207         this.expectedStartUpCalled = isExpected ? Boolean.TRUE : Boolean.FALSE;
208     }
209
210     /**
211      * Sets whether to expect a call to the shutDown() method.
212      *
213      * @param isExpected Whether a call is expected or not
214      */

215     public void expectShutDownCalled(boolean isExpected)
216     {
217         this.expectedShutDownCalled = isExpected ? Boolean.TRUE : Boolean.FALSE;
218     }
219
220     /**
221      * Verify the mock object's state.
222      */

223     public void verify()
224     {
225         if (this.expectedStartUpCalled != null)
226         {
227             Assert.assertTrue("The startUp() method should "
228                 + (this.expectedStartUpCalled.booleanValue() ? "" : "not ")
229                 + "have been called",
230                 this.expectedStartUpCalled.booleanValue() == startUpCalled);
231         }
232         if (this.expectedShutDownCalled != null)
233         {
234             Assert.assertTrue("The shutDown() method should "
235                 + (this.expectedShutDownCalled.booleanValue() ? "" : "not ")
236                 + "have been called",
237                 this.expectedShutDownCalled.booleanValue() == shutDownCalled);
238         }
239     }
240
241     /**
242      * @see Container#setSystemProperties(Variable[])
243      */

244     public void setSystemProperties(Variable[] theProperties)
245     {
246         // do nothing
247
}
248
249     /**
250      * @see Container#getSystemProperties()
251      */

252     public Variable[] getSystemProperties()
253     {
254         throw new RuntimeException JavaDoc("not implemented");
255     }
256
257     /**
258      * @see Container#setContainerClasspath(Path)
259      */

260     public void setContainerClasspath(Path theClasspath)
261     {
262         // do nothing
263
}
264
265     /**
266      * @see Container#getContainerClasspath()
267      */

268     public Path getContainerClasspath()
269     {
270         throw new RuntimeException JavaDoc("not implemented");
271     }
272 }
273
Popular Tags