001: package com.mockrunner.servlet;
002:
003: import javax.servlet.Filter;
004: import javax.servlet.ServletRequest;
005: import javax.servlet.ServletResponse;
006: import javax.servlet.http.HttpServlet;
007:
008: import com.mockrunner.base.BasicHTMLOutputTestCase;
009: import com.mockrunner.base.HTMLOutputModule;
010: import com.mockrunner.mock.web.WebMockObjectFactory;
011:
012: /**
013: * Delegator for {@link com.mockrunner.servlet.ServletTestModule}. You can
014: * subclass this adapter or use {@link com.mockrunner.servlet.ServletTestModule}
015: * directly (so your test case can use another base class).
016: * This basic adapter can be used if you don't need any other modules. It
017: * does not extend {@link com.mockrunner.base.BaseTestCase}. If you want
018: * to use several modules in conjunction, consider subclassing
019: * {@link com.mockrunner.servlet.ServletTestCaseAdapter}.
020: * <b>This class is generated from the {@link com.mockrunner.servlet.ServletTestModule}
021: * and should not be edited directly</b>.
022: */
023: public abstract class BasicServletTestCaseAdapter extends
024: BasicHTMLOutputTestCase {
025: private ServletTestModule servletTestModule;
026: private WebMockObjectFactory webMockObjectFactory;
027:
028: public BasicServletTestCaseAdapter() {
029:
030: }
031:
032: public BasicServletTestCaseAdapter(String name) {
033: super (name);
034: }
035:
036: protected void tearDown() throws Exception {
037: super .tearDown();
038: servletTestModule = null;
039: webMockObjectFactory = null;
040: }
041:
042: /**
043: * Creates the {@link com.mockrunner.servlet.ServletTestModule}. If you
044: * overwrite this method, you must call <code>super.setUp()</code>.
045: */
046: protected void setUp() throws Exception {
047: super .setUp();
048: servletTestModule = createServletTestModule(getWebMockObjectFactory());
049: }
050:
051: /**
052: * Creates a {@link com.mockrunner.mock.web.WebMockObjectFactory}.
053: * @return the created {@link com.mockrunner.mock.web.WebMockObjectFactory}
054: */
055: protected WebMockObjectFactory createWebMockObjectFactory() {
056: return new WebMockObjectFactory();
057: }
058:
059: /**
060: * Same as <code>createWebMockObjectFactory(otherFactory, true)</code>.
061: */
062: protected WebMockObjectFactory createWebMockObjectFactory(
063: WebMockObjectFactory otherFactory) {
064: return new WebMockObjectFactory(otherFactory);
065: }
066:
067: /**
068: * Creates a {@link com.mockrunner.mock.web.WebMockObjectFactory} based on another
069: * {@link com.mockrunner.mock.web.WebMockObjectFactory}.
070: * The created {@link com.mockrunner.mock.web.WebMockObjectFactory} will have its own
071: * request and response objects. If you set <i>createNewSession</i>
072: * to <code>true</code> it will also have its own session object.
073: * The two factories will share one <code>ServletContext</code>.
074: * Especially important for multithreading tests.
075: * If you set <i>createNewSession</i> to false, the two factories
076: * will share one session. This setting simulates multiple requests
077: * from the same client.
078: * @param otherFactory the other factory
079: * @param createNewSession create a new session for the new factory
080: * @return the created {@link com.mockrunner.mock.web.WebMockObjectFactory}
081: */
082: protected WebMockObjectFactory createWebMockObjectFactory(
083: WebMockObjectFactory otherFactory, boolean createNewSession) {
084: return new WebMockObjectFactory(otherFactory, createNewSession);
085: }
086:
087: /**
088: * Gets the {@link com.mockrunner.mock.web.WebMockObjectFactory}.
089: * @return the {@link com.mockrunner.mock.web.WebMockObjectFactory}
090: */
091: protected WebMockObjectFactory getWebMockObjectFactory() {
092: synchronized (WebMockObjectFactory.class) {
093: if (webMockObjectFactory == null) {
094: webMockObjectFactory = createWebMockObjectFactory();
095: }
096: }
097: return webMockObjectFactory;
098: }
099:
100: /**
101: * Sets the {@link com.mockrunner.mock.web.WebMockObjectFactory}.
102: * @param webMockObjectFactory the {@link com.mockrunner.mock.web.WebMockObjectFactory}
103: */
104: protected void setWebMockObjectFactory(
105: WebMockObjectFactory webMockObjectFactory) {
106: this .webMockObjectFactory = webMockObjectFactory;
107: }
108:
109: /**
110: * Creates a {@link com.mockrunner.servlet.ServletTestModule} based on the current
111: * {@link com.mockrunner.mock.web.WebMockObjectFactory}.
112: * Same as <code>createServletTestModule(getWebMockObjectFactory())</code>.
113: * @return the created {@link com.mockrunner.servlet.ServletTestModule}
114: */
115: protected ServletTestModule createServletTestModule() {
116: return new ServletTestModule(getWebMockObjectFactory());
117: }
118:
119: /**
120: * Creates a {@link com.mockrunner.servlet.ServletTestModule} with the specified
121: * {@link com.mockrunner.mock.web.WebMockObjectFactory}.
122: * @return the created {@link com.mockrunner.servlet.ServletTestModule}
123: */
124: protected ServletTestModule createServletTestModule(
125: WebMockObjectFactory mockFactory) {
126: return new ServletTestModule(mockFactory);
127: }
128:
129: /**
130: * Returns the {@link com.mockrunner.servlet.ServletTestModule} as
131: * {@link com.mockrunner.base.HTMLOutputModule}.
132: * @return the {@link com.mockrunner.base.HTMLOutputModule}
133: */
134: protected HTMLOutputModule getHTMLOutputModule() {
135: return servletTestModule;
136: }
137:
138: /**
139: * Gets the {@link com.mockrunner.servlet.ServletTestModule}.
140: * @return the {@link com.mockrunner.servlet.ServletTestModule}
141: */
142: protected ServletTestModule getServletTestModule() {
143: return servletTestModule;
144: }
145:
146: /**
147: * Sets the {@link com.mockrunner.servlet.ServletTestModule}.
148: * @param servletTestModule the {@link com.mockrunner.servlet.ServletTestModule}
149: */
150: protected void setServletTestModule(
151: ServletTestModule servletTestModule) {
152: this .servletTestModule = servletTestModule;
153: }
154:
155: /**
156: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#setServlet(HttpServlet)}
157: */
158: protected void setServlet(HttpServlet servlet) {
159: servletTestModule.setServlet(servlet);
160: }
161:
162: /**
163: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#setServlet(HttpServlet, boolean)}
164: */
165: protected void setServlet(HttpServlet servlet, boolean doInit) {
166: servletTestModule.setServlet(servlet, doInit);
167: }
168:
169: /**
170: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doGet}
171: */
172: protected void doGet() {
173: servletTestModule.doGet();
174: }
175:
176: /**
177: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doPost}
178: */
179: protected void doPost() {
180: servletTestModule.doPost();
181: }
182:
183: /**
184: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doHead}
185: */
186: protected void doHead() {
187: servletTestModule.doHead();
188: }
189:
190: /**
191: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doPut}
192: */
193: protected void doPut() {
194: servletTestModule.doPut();
195: }
196:
197: /**
198: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doDelete}
199: */
200: protected void doDelete() {
201: servletTestModule.doDelete();
202: }
203:
204: /**
205: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doOptions}
206: */
207: protected void doOptions() {
208: servletTestModule.doOptions();
209: }
210:
211: /**
212: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doTrace}
213: */
214: protected void doTrace() {
215: servletTestModule.doTrace();
216: }
217:
218: /**
219: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#getServlet}
220: */
221: protected HttpServlet getServlet() {
222: return servletTestModule.getServlet();
223: }
224:
225: /**
226: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#createServlet(Class)}
227: */
228: protected HttpServlet createServlet(Class servletClass) {
229: return servletTestModule.createServlet(servletClass);
230: }
231:
232: /**
233: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#createFilter(Class)}
234: */
235: protected Filter createFilter(Class filterClass) {
236: return servletTestModule.createFilter(filterClass);
237: }
238:
239: /**
240: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#addFilter(Filter)}
241: */
242: protected void addFilter(Filter filter) {
243: servletTestModule.addFilter(filter);
244: }
245:
246: /**
247: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#addFilter(Filter, boolean)}
248: */
249: protected void addFilter(Filter filter, boolean doInit) {
250: servletTestModule.addFilter(filter, doInit);
251: }
252:
253: /**
254: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#releaseFilters}
255: */
256: protected void releaseFilters() {
257: servletTestModule.releaseFilters();
258: }
259:
260: /**
261: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#setDoChain(boolean)}
262: */
263: protected void setDoChain(boolean doChain) {
264: servletTestModule.setDoChain(doChain);
265: }
266:
267: /**
268: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#doFilter}
269: */
270: protected void doFilter() {
271: servletTestModule.doFilter();
272: }
273:
274: /**
275: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#getFilteredRequest}
276: */
277: protected ServletRequest getFilteredRequest() {
278: return servletTestModule.getFilteredRequest();
279: }
280:
281: /**
282: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#getFilteredResponse}
283: */
284: protected ServletResponse getFilteredResponse() {
285: return servletTestModule.getFilteredResponse();
286: }
287:
288: /**
289: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#clearOutput}
290: */
291: protected void clearOutput() {
292: servletTestModule.clearOutput();
293: }
294:
295: /**
296: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#init}
297: */
298: protected void init() {
299: servletTestModule.init();
300: }
301:
302: /**
303: * Delegates to {@link com.mockrunner.servlet.ServletTestModule#service}
304: */
305: protected void service() {
306: servletTestModule.service();
307: }
308: }
|