001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.responders;
004:
005: import java.io.File;
006:
007: import junit.framework.TestCase;
008: import fitnesse.Responder;
009: import fitnesse.http.MockRequest;
010: import fitnesse.responders.editing.CreateStiqPageResponder;
011: import fitnesse.responders.editing.EditResponder;
012: import fitnesse.responders.editing.PropertiesResponder;
013: import fitnesse.responders.editing.SavePropertiesResponder;
014: import fitnesse.responders.editing.SaveResponder;
015: import fitnesse.responders.editing.SymbolicLinkResponder;
016: import fitnesse.responders.editing.TableWizardResponder;
017: import fitnesse.responders.files.CreateDirectoryResponder;
018: import fitnesse.responders.files.DeleteConfirmationResponder;
019: import fitnesse.responders.files.DeleteFileResponder;
020: import fitnesse.responders.files.RenameFileConfirmationResponder;
021: import fitnesse.responders.files.RenameFileResponder;
022: import fitnesse.responders.files.RepoFileResponder;
023: import fitnesse.responders.files.UploadResponder;
024: import fitnesse.responders.refactoring.DeletePageResponder;
025: import fitnesse.responders.refactoring.MovePageResponder;
026: import fitnesse.responders.refactoring.NewStiqPageResponder;
027: import fitnesse.responders.refactoring.RefactorPageResponder;
028: import fitnesse.responders.refactoring.RenamePageResponder;
029: import fitnesse.responders.run.FitClientResponder;
030: import fitnesse.responders.run.SocketCatchingResponder;
031: import fitnesse.responders.run.TestResultFormattingResponder;
032: import fitnesse.responders.search.SearchFormResponder;
033: import fitnesse.responders.search.SearchResponder;
034: import fitnesse.responders.search.WhereUsedResponder;
035: import fitnesse.responders.versions.RollbackResponder;
036: import fitnesse.responders.versions.VersionResponder;
037: import fitnesse.responders.versions.VersionSelectionResponder;
038: import fitnesse.testutil.FitNesseUtil;
039: import fitnesse.util.FileUtil;
040: import fitnesse.wiki.InMemoryPage;
041: import fitnesse.wiki.MockWikiPage;
042: import fitnesse.wiki.PageCrawler;
043: import fitnesse.wiki.PathParser;
044: import fitnesse.wiki.WikiPage;
045:
046: public class ResponderFactoryTest extends TestCase {
047: private ResponderFactory factory;
048:
049: private MockRequest request;
050:
051: private MockWikiPage nonExistantPage;
052:
053: private WikiPage root;
054:
055: private PageCrawler crawler;
056:
057: public void setUp() throws Exception {
058: factory = new ResponderFactory("testDir");
059: request = new MockRequest();
060: root = InMemoryPage.makeRoot("root");
061: crawler = root.getPageCrawler();
062: nonExistantPage = new MockWikiPage();
063: }
064:
065: public void testGetResponderKey() throws Exception {
066: checkResponderKey("railroad", "railroad");
067: checkResponderKey("responder=railroad", "railroad");
068: checkResponderKey("", "");
069: }
070:
071: private void checkResponderKey(String queryString, String key) {
072: MockRequest request = new MockRequest();
073: request.setQueryString(queryString);
074: assertEquals(key, factory.getResponderKey(request));
075: }
076:
077: public void testWikiPageResponder() throws Exception {
078: request.setResource("SomePage");
079: assertResponderType(WikiPageResponder.class, root);
080: request.setResource("");
081: assertResponderType(WikiPageResponder.class, root);
082: request.setResource("root");
083: assertResponderType(WikiPageResponder.class, root);
084: }
085:
086: public void testRefactorPageResponder() throws Exception {
087: assertResponderTypeMatchesInput("refactor",
088: RefactorPageResponder.class);
089: }
090:
091: public void testDeletePageResponder() throws Exception {
092: assertResponderTypeMatchesInput("deletePage",
093: DeletePageResponder.class);
094: }
095:
096: public void testRenamePageResponder() throws Exception {
097: assertResponderTypeMatchesInput("renamePage",
098: RenamePageResponder.class);
099: }
100:
101: public void testEditResponder() throws Exception {
102: request.addInput("responder", "edit");
103: request.setResource("SomePage");
104: assertResponderType(EditResponder.class, root);
105: assertResponderType(EditResponder.class, nonExistantPage);
106: }
107:
108: public void testPageDataResponder() throws Exception {
109: request.addInput("responder", "pageData");
110: request.setResource("SomePage");
111: assertResponderType(PageDataWikiPageResponder.class, root);
112: }
113:
114: public void testSaveResponder() throws Exception {
115: assertResponderTypeMatchesInput("saveData", SaveResponder.class);
116: }
117:
118: // Removed because of Selenium's use of Get method parameters with the same name
119: // and FitNesse's overloaded use of Get parameters to drive Responder choice
120: /* public void testTestResponder() throws Exception {
121: assertResponderTypeMatchesInput("test", TestResponder.class);
122: }
123:
124: public void testSuiteResponder() throws Exception {
125: assertResponderTypeMatchesInput("suite", SuiteResponder.class);
126: }*/
127:
128: public void testFileResponder() throws Exception {
129: try {
130: new File("testDir").mkdir();
131: new File("testDir/files").mkdir();
132: FileUtil.createFile("testDir/files/someFile",
133: "this is a test");
134: request.setResource("files/someFile");
135: assertResponderType(ClasspathFileResponder.class,
136: nonExistantPage);
137: } finally {
138: FileUtil.deleteFileSystemDirectory("testDir");
139: }
140: }
141:
142: public void testSearchFormResponder() throws Exception {
143: assertResponderTypeMatchesInput("searchForm",
144: SearchFormResponder.class);
145: }
146:
147: public void testSearchResponder() throws Exception {
148: assertResponderTypeMatchesInput("search", SearchResponder.class);
149: }
150:
151: public void testSerializedPageResponder() throws Exception {
152: assertResponderTypeMatchesInput("proxy",
153: SerializedPageResponder.class);
154: }
155:
156: public void testVersionSelectionResponder() throws Exception {
157: assertResponderTypeMatchesInput("versions",
158: VersionSelectionResponder.class);
159: }
160:
161: public void testVersionResponder() throws Exception {
162: assertResponderTypeMatchesInput("viewVersion",
163: VersionResponder.class);
164: }
165:
166: public void testRollbackResponder() throws Exception {
167: assertResponderTypeMatchesInput("rollback",
168: RollbackResponder.class);
169: }
170:
171: public void testNameReponder() throws Exception {
172: assertResponderTypeMatchesInput("names",
173: NameWikiPageResponder.class);
174: }
175:
176: public void testUploadResponder() throws Exception {
177: assertResponderTypeMatchesInput("upload", UploadResponder.class);
178: }
179:
180: public void testCreateDirectoryResponder() throws Exception {
181: assertResponderTypeMatchesInput("createDir",
182: CreateDirectoryResponder.class);
183: }
184:
185: public void testDeleteFileResponder() throws Exception {
186: assertResponderTypeMatchesInput("deleteFile",
187: DeleteFileResponder.class);
188: }
189:
190: public void testRenameFileResponder() throws Exception {
191: assertResponderTypeMatchesInput("renameFile",
192: RenameFileResponder.class);
193: }
194:
195: public void testDeleteConfirmationFileResponder() throws Exception {
196: assertResponderTypeMatchesInput("deleteConfirmation",
197: DeleteConfirmationResponder.class);
198: }
199:
200: public void testRenameFileConfirmationResponder() throws Exception {
201: assertResponderTypeMatchesInput("renameConfirmation",
202: RenameFileConfirmationResponder.class);
203: }
204:
205: public void testCreatePropertiesResponder() throws Exception {
206: assertResponderTypeMatchesInput("properties",
207: PropertiesResponder.class);
208: }
209:
210: public void testCreateSavePropertiesResponder() throws Exception {
211: assertResponderTypeMatchesInput("saveProperties",
212: SavePropertiesResponder.class);
213: }
214:
215: public void testCreateWhereUsedResponder() throws Exception {
216: assertResponderTypeMatchesInput("whereUsed",
217: WhereUsedResponder.class);
218: }
219:
220: public void testCreateMovePageResponer() throws Exception {
221: assertResponderTypeMatchesInput("movePage",
222: MovePageResponder.class);
223: }
224:
225: public void testCreateTableWizardResponder() throws Exception {
226: assertResponderTypeMatchesInput("tableWizard",
227: TableWizardResponder.class);
228: }
229:
230: public void testSocketCatcher() throws Exception {
231: assertResponderTypeMatchesInput("socketCatcher",
232: SocketCatchingResponder.class);
233: }
234:
235: public void testFitClient() throws Exception {
236: assertResponderTypeMatchesInput("fitClient",
237: FitClientResponder.class);
238: }
239:
240: public void testRawContent() throws Exception {
241: assertResponderTypeMatchesInput("raw",
242: RawContentResponder.class);
243: }
244:
245: public void testRssResponder() throws Exception {
246: assertResponderTypeMatchesInput("rss", RssResponder.class);
247: }
248:
249: public void testPageImporterResponder() throws Exception {
250: assertResponderTypeMatchesInput("import",
251: WikiImportingResponder.class);
252: }
253:
254: public void testShutdownResponder() throws Exception {
255: assertResponderTypeMatchesInput("shutdown",
256: ShutdownResponder.class);
257: }
258:
259: public void testTestResultFormattingResponder() throws Exception {
260: assertResponderTypeMatchesInput("format",
261: TestResultFormattingResponder.class);
262: }
263:
264: public void testSymbolicLinkResponder() throws Exception {
265: assertResponderTypeMatchesInput("symlink",
266: SymbolicLinkResponder.class);
267: }
268:
269: public void testClasspathFileResponder() throws Exception {
270: assertResponderTypeMatchesInput("startPage",
271: ClasspathFileResponder.class);
272: }
273:
274: public void testNameTestPageResponder() throws Exception {
275: assertResponderTypeMatchesInput(
276: NewStiqPageResponder.RESPONDER_KEY,
277: NewStiqPageResponder.class);
278: }
279:
280: public void testCreateTestResponder() throws Exception {
281: assertResponderTypeMatchesInput(
282: CreateStiqPageResponder.RESPONDER_KEY,
283: CreateStiqPageResponder.class);
284: }
285:
286: public void testWillDisplayVirtualPages() throws Exception {
287: WikiPage root = InMemoryPage.makeRoot("RooT");
288: WikiPage page1 = crawler.addPage(root, PathParser
289: .parse("PageOne"));
290: crawler.addPage(page1, PathParser.parse("ChildOne"),
291: "child content");
292: WikiPage page2 = crawler.addPage(root, PathParser
293: .parse("PageTwo"));
294: FitNesseUtil.bindVirtualLinkToPage(page2, page1);
295: request.setResource("PageTwo.ChildOne");
296: assertResponderType(WikiPageResponder.class, root);
297: }
298:
299: public void testNotFoundResponder() throws Exception {
300: request.setResource("somepage");
301: assertResponderType(NotFoundResponder.class, root);
302: }
303:
304: public void testAddingResponders() throws Exception {
305: factory.addResponder("custom", WikiPageResponder.class);
306: assertResponderTypeMatchesInput("custom",
307: WikiPageResponder.class);
308: }
309:
310: public void testFilesResponderType() throws Exception {
311: assertResponderTypeMatchesInput("files",
312: ClasspathFileResponder.class);
313: }
314:
315: public void testStiqResponderType() throws Exception {
316: request.setResource("storytestiq/something");
317: assertResponderType(ClasspathFileResponder.class,
318: nonExistantPage);
319: request.setResource("stiq/somethingelse");
320: assertResponderType(ClasspathFileResponder.class,
321: nonExistantPage);
322: }
323:
324: public void testRepoFileResponder() throws Exception {
325: try {
326: new File("testDir").mkdir();
327: new File("testDir/anotherDir").mkdir();
328: FileUtil.createFile("testDir/anotherDir/someFile",
329: "this is a test");
330: request.setResource("~anotherDir/someFile");
331: assertResponderType(RepoFileResponder.class,
332: nonExistantPage);
333: } finally {
334: FileUtil.deleteFileSystemDirectory("testDir");
335: }
336: }
337:
338: private void assertResponderType(Class expectedClass, WikiPage page)
339: throws Exception {
340: Responder responder = factory.makeResponder(request, page);
341: assertEquals(expectedClass, responder.getClass());
342: }
343:
344: private void assertResponderTypeMatchesInput(String responderType,
345: Class responderClass) throws Exception {
346: request.addInput("responder", responderType);
347: assertResponderType(responderClass, root);
348: }
349: }
|