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