01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders;
04:
05: import fitnesse.FitNesseContext;
06: import fitnesse.http.*;
07: import fitnesse.testutil.AbstractRegex;
08: import fitnesse.wiki.*;
09:
10: public class NameResponderTest extends AbstractRegex {
11: private WikiPage root;
12:
13: private NameWikiPageResponder responder;
14:
15: private MockRequest request;
16:
17: private PageCrawler crawler;
18:
19: private String pageOneName;
20:
21: private String pageTwoName;
22:
23: private String frontPageName;
24:
25: private WikiPagePath pageOnePath;
26:
27: private WikiPagePath pageTwoPath;
28:
29: private WikiPagePath frontPagePath;
30:
31: protected void setUp() throws Exception {
32: root = InMemoryPage.makeRoot("RooT");
33: crawler = root.getPageCrawler();
34: responder = new NameWikiPageResponder();
35: request = new MockRequest();
36:
37: pageOneName = "PageOne";
38: pageTwoName = "PageTwo";
39: frontPageName = "FrontPage";
40:
41: pageOnePath = PathParser.parse(pageOneName);
42: pageTwoPath = PathParser.parse(pageTwoName);
43: frontPagePath = PathParser.parse(frontPageName);
44: }
45:
46: public void testTextPlain() throws Exception {
47:
48: Response r = responder.makeResponse(new FitNesseContext(root),
49: request);
50: assertEquals("text/plain", r.getContentType());
51: }
52:
53: public void testPageNamesFromRoot() throws Exception {
54: crawler.addPage(root, pageOnePath);
55: crawler.addPage(root, pageTwoPath);
56: request.setResource("");
57: SimpleResponse response = (SimpleResponse) responder
58: .makeResponse(new FitNesseContext(root), request);
59: assertHasRegexp(pageOneName, response.getContent());
60: assertHasRegexp(pageTwoName, response.getContent());
61: }
62:
63: public void testPageNamesFromASubPage() throws Exception {
64: WikiPage frontPage = crawler.addPage(root, frontPagePath);
65: crawler.addPage(frontPage, pageOnePath);
66: crawler.addPage(frontPage, pageTwoPath);
67: request.setResource("");
68: SimpleResponse response = (SimpleResponse) responder
69: .makeResponse(new FitNesseContext(root), request);
70: assertHasRegexp(frontPageName, response.getContent());
71: assertDoesntHaveRegexp(pageOneName, response.getContent());
72: assertDoesntHaveRegexp(pageTwoName, response.getContent());
73:
74: request.setResource(frontPageName);
75: response = (SimpleResponse) responder.makeResponse(
76: new FitNesseContext(root), request);
77: assertHasRegexp(pageOneName, response.getContent());
78: assertHasRegexp(pageTwoName, response.getContent());
79: assertDoesntHaveRegexp(frontPageName, response.getContent());
80: }
81: }
|