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 fitnesse.*;
006: import fitnesse.authentication.*;
007: import fitnesse.testutil.*;
008: import fitnesse.http.*;
009: import fitnesse.wiki.*;
010:
011: public class WikiPageResponderTest extends AbstractRegex {
012: private WikiPage root;
013:
014: private SimpleResponse response;
015:
016: private PageCrawler crawler;
017:
018: public void setUp() throws Exception {
019: root = InMemoryPage.makeRoot("root");
020: crawler = root.getPageCrawler();
021: }
022:
023: public void testResponse() throws Exception {
024: crawler.addPage(root, PathParser.parse("ChildPage"),
025: "child content");
026: MockRequest request = new MockRequest();
027: request.setResource("ChildPage");
028:
029: Responder responder = new WikiPageResponder();
030: response = (SimpleResponse) responder.makeResponse(
031: new FitNesseContext(root), request);
032:
033: assertEquals(200, response.getStatus());
034:
035: String body = response.getContent();
036:
037: assertSubString("<html>", body);
038: assertSubString("<body", body);
039: assertSubString("child content", body);
040: assertSubString("href=\"ChildPage?edit\"", body);
041: assertSubString("ChildPage</span>", body);
042: assertSubString("Cache-Control: max-age=0", response
043: .makeHttpHeaders());
044: }
045:
046: public void testAttributeButtons() throws Exception {
047: crawler.addPage(root, PathParser.parse("NormalPage"));
048: WikiPage noButtonsPage = crawler.addPage(root, PathParser
049: .parse("NoButtonPage"));
050: for (int i = 0; i < WikiPage.NON_SECURITY_ATTRIBUTES.length; i++) {
051: String attribute = WikiPage.NON_SECURITY_ATTRIBUTES[i];
052: PageData data = noButtonsPage.getData();
053: data.removeAttribute(attribute);
054: noButtonsPage.commit(data);
055: }
056:
057: SimpleResponse response = requestPage("NormalPage");
058: // FIXME: We broke the edit comment tag when adding the onclick attribute
059: // assertSubString("<!--Edit button-->", response.getContent());
060: // assertSubString("<!--Search button-->", response.getContent());
061: // assertSubString("<!--Versions button-->", response.getContent());
062: assertNotSubString("<!--Suite button-->", response.getContent());
063: assertNotSubString("<!--Test button-->", response.getContent());
064:
065: response = requestPage("NoButtonPage");
066: assertNotSubString("<!--Edit button-->", response.getContent());
067: assertNotSubString("<!--Search button-->", response
068: .getContent());
069: assertNotSubString("<!--Versions button-->", response
070: .getContent());
071: assertNotSubString("<!--Suite button-->", response.getContent());
072: assertNotSubString("<!--Test button-->", response.getContent());
073: }
074:
075: public void testEditButtonOnclick() throws Exception {
076: crawler.addPage(root, PathParser.parse("NormalPage"));
077: WikiPage noButtonsPage = crawler.addPage(root, PathParser
078: .parse("NoButtonPage"));
079: for (int i = 0; i < WikiPage.NON_SECURITY_ATTRIBUTES.length; i++) {
080: String attribute = WikiPage.NON_SECURITY_ATTRIBUTES[i];
081: PageData data = noButtonsPage.getData();
082: data.removeAttribute(attribute);
083: noButtonsPage.commit(data);
084: }
085:
086: SimpleResponse response = requestPage("NormalPage");
087: assertSubString("onclick", response.getContent());
088: }
089:
090: public void testHeadersAndFooters() throws Exception {
091: crawler.addPage(root, PathParser.parse("NormalPage"), "normal");
092: crawler
093: .addPage(root, PathParser.parse("TestPage"),
094: "test page");
095: crawler.addPage(root, PathParser.parse("PageHeader"), "header");
096: crawler.addPage(root, PathParser.parse("PageFooter"), "footer");
097: crawler.addPage(root, PathParser.parse("SetUp"), "setup");
098: crawler.addPage(root, PathParser.parse("TearDown"), "teardown");
099:
100: SimpleResponse response = requestPage("NormalPage");
101: String content = response.getContent();
102: assertHasRegexp("header", content);
103: assertHasRegexp("normal", content);
104: assertHasRegexp("footer", content);
105: assertDoesntHaveRegexp("setup", content);
106: assertDoesntHaveRegexp("teardown", content);
107:
108: response = requestPage("TestPage");
109: content = response.getContent();
110: assertHasRegexp("header", content);
111: assertHasRegexp("test page", content);
112: assertHasRegexp("footer", content);
113: assertHasRegexp("setup", content);
114: assertHasRegexp("teardown", content);
115: }
116:
117: private SimpleResponse requestPage(String name) throws Exception {
118: MockRequest request = new MockRequest();
119: request.setResource(name);
120: Responder responder = new WikiPageResponder();
121: SimpleResponse response = (SimpleResponse) responder
122: .makeResponse(new FitNesseContext(root), request);
123: return response;
124: }
125:
126: public void testShouldGetVirtualPage() throws Exception {
127: WikiPage pageOne = crawler.addPage(root, PathParser
128: .parse("TargetPage"), "some content");
129: crawler.addPage(pageOne, PathParser.parse("ChildPage"),
130: "child content");
131: WikiPage linkerPage = crawler.addPage(root, PathParser
132: .parse("LinkerPage"), "linker content");
133: FitNesseUtil.bindVirtualLinkToPage(linkerPage, pageOne);
134: SimpleResponse response = requestPage("LinkerPage.ChildPage");
135:
136: assertSubString("child content", response.getContent());
137: }
138:
139: public void testVirtualPageIndication() throws Exception {
140: WikiPage targetPage = crawler.addPage(root, PathParser
141: .parse("TargetPage"));
142: crawler.addPage(targetPage, PathParser.parse("ChildPage"));
143: WikiPage linkPage = (BaseWikiPage) crawler.addPage(root,
144: PathParser.parse("LinkPage"));
145: VirtualCouplingExtensionTest
146: .setVirtualWiki(linkPage, "http://localhost:"
147: + FitNesseUtil.port + "/TargetPage");
148:
149: FitNesseUtil.startFitnesse(root);
150: SimpleResponse response = null;
151: try {
152: response = requestPage("LinkPage.ChildPage");
153: } finally {
154: FitNesseUtil.stopFitnesse();
155: }
156:
157: assertSubString("<body class=\"virtual\">", response
158: .getContent());
159: }
160:
161: public void testImportedPageIndication() throws Exception {
162: WikiPage page = crawler.addPage(root, PathParser
163: .parse("SamplePage"));
164: PageData data = page.getData();
165: data.setAttribute("WikiImportSource", "blah");
166: page.commit(data);
167:
168: String content = requestPage("SamplePage").getContent();
169:
170: assertSubString("<body class=\"imported\">", content);
171: }
172:
173: public void testResponderIsSecureReadOperation() throws Exception {
174: Responder responder = new WikiPageResponder();
175: assertTrue(responder instanceof SecureResponder);
176: SecureOperation operation = ((SecureResponder) responder)
177: .getSecureOperation();
178: assertEquals(SecureReadOperation.class, operation.getClass());
179: }
180:
181: }
|