001: /*
002: * ========================================================================
003: *
004: * Copyright 2003-2004 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.container;
021:
022: import java.io.File;
023:
024: import junit.framework.Assert;
025:
026: import org.apache.cactus.integration.ant.deployment.DeployableFile;
027: import org.apache.cactus.integration.ant.util.AntTaskFactory;
028: import org.apache.commons.logging.Log;
029: import org.apache.tools.ant.types.Path;
030: import org.apache.tools.ant.types.Environment.Variable;
031:
032: /**
033: * Mock implementation of the {@link Container} interface.
034: *
035: * @version $Id: MockContainer.java 239130 2005-01-29 15:49:18Z vmassol $
036: */
037: public final class MockContainer implements Container {
038: // Instance Variables ------------------------------------------------------
039:
040: /**
041: * The dummy server.
042: */
043: private MockHttpServer server;
044:
045: /**
046: * Whether it is expected that the startUp() method is called.
047: * <code>null</code> for "Don't care".
048: */
049: private Boolean expectedStartUpCalled;
050:
051: /**
052: * Whether the startUp() method was called.
053: */
054: private boolean startUpCalled;
055:
056: /**
057: * Whether it is expected that the shutDown() method is called.
058: * <code>null</code> for "Don't care".
059: */
060: private Boolean expectedShutDownCalled;
061:
062: /**
063: * Whether the shutDown() method was called.
064: */
065: private boolean shutDownCalled;
066:
067: // Constructors ------------------------------------------------------------
068:
069: /**
070: * Constructor.
071: *
072: * @param theServer The dummy HTTP server
073: */
074: public MockContainer(MockHttpServer theServer) {
075: this .server = theServer;
076: }
077:
078: /**
079: * Constructor.
080: */
081: public MockContainer() {
082: }
083:
084: // Container Implementation ------------------------------------------------
085:
086: /**
087: * @see Container#getName()
088: */
089: public String getName() {
090: return null;
091: }
092:
093: /**
094: * @see Container#getTestContext()
095: */
096: public String getTestContext() {
097: return null;
098: }
099:
100: /**
101: * @see Container#getStartUpWait()
102: */
103: public long getStartUpWait() {
104: return 0;
105: }
106:
107: /**
108: * @see Container#getPort()
109: */
110: public int getPort() {
111: return 0;
112: }
113:
114: /**
115: * @see Container#getToDir()
116: */
117: public File getToDir() {
118: return null;
119: }
120:
121: /**
122: * @see Container#init()
123: */
124: public void init() {
125: }
126:
127: /**
128: * @see Container#isEnabled()
129: */
130: public boolean isEnabled() {
131: return false;
132: }
133:
134: /**
135: * @see Container#isExcluded(java.lang.String)
136: */
137: public boolean isExcluded(String theTestName) {
138: return false;
139: }
140:
141: /**
142: * @see Container#setAntTaskFactory(AntTaskFactory)
143: */
144: public void setAntTaskFactory(AntTaskFactory theFactory) {
145: }
146:
147: /**
148: * @see Container#setLog(Log)
149: */
150: public void setLog(Log theLog) {
151: }
152:
153: /**
154: * @see Container#setDeployableFile
155: */
156: public void setDeployableFile(DeployableFile theWarFile) {
157: }
158:
159: /**
160: * @see Container#startUp()
161: */
162: public void startUp() {
163: this .startUpCalled = true;
164: if (this .server != null) {
165: Thread thread = new Thread(this .server);
166: thread.start();
167: }
168: }
169:
170: /**
171: * @see Container#shutDown()
172: */
173: public void shutDown() {
174: this .shutDownCalled = true;
175: if (this .server != null) {
176: this .server.stop();
177: }
178: }
179:
180: /**
181: * @see Container#getServer()
182: */
183: public String getServer() {
184: return null;
185: }
186:
187: /**
188: * @see Container#getProtocol()
189: */
190: public String getProtocol() {
191: return null;
192: }
193:
194: /**
195: * @see Container#getBaseURL()
196: */
197: public String getBaseURL() {
198: return null;
199: }
200:
201: // Public Methods ----------------------------------------------------------
202:
203: /**
204: * Sets whether to expect a call to the startUp() method.
205: *
206: * @param isExpected Whether a call is expected or not
207: */
208: public void expectStartUpCalled(boolean isExpected) {
209: this .expectedStartUpCalled = isExpected ? Boolean.TRUE
210: : Boolean.FALSE;
211: }
212:
213: /**
214: * Sets whether to expect a call to the shutDown() method.
215: *
216: * @param isExpected Whether a call is expected or not
217: */
218: public void expectShutDownCalled(boolean isExpected) {
219: this .expectedShutDownCalled = isExpected ? Boolean.TRUE
220: : Boolean.FALSE;
221: }
222:
223: /**
224: * Verify the mock object's state.
225: */
226: public void verify() {
227: if (this .expectedStartUpCalled != null) {
228: Assert
229: .assertTrue(
230: "The startUp() method should "
231: + (this .expectedStartUpCalled
232: .booleanValue() ? ""
233: : "not ")
234: + "have been called",
235: this .expectedStartUpCalled.booleanValue() == startUpCalled);
236: }
237: if (this .expectedShutDownCalled != null) {
238: Assert
239: .assertTrue(
240: "The shutDown() method should "
241: + (this .expectedShutDownCalled
242: .booleanValue() ? ""
243: : "not ")
244: + "have been called",
245: this .expectedShutDownCalled.booleanValue() == shutDownCalled);
246: }
247: }
248:
249: /**
250: * @see Container#setSystemProperties(Variable[])
251: */
252: public void setSystemProperties(Variable[] theProperties) {
253: // do nothing
254: }
255:
256: /**
257: * @see Container#getSystemProperties()
258: */
259: public Variable[] getSystemProperties() {
260: throw new RuntimeException("not implemented");
261: }
262:
263: /**
264: * @see Container#setContainerClasspath(Path)
265: */
266: public void setContainerClasspath(Path theClasspath) {
267: // do nothing
268: }
269:
270: /**
271: * @see Container#getContainerClasspath()
272: */
273: public Path getContainerClasspath() {
274: throw new RuntimeException("not implemented");
275: }
276: }
|