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.editing;
004:
005: import fitnesse.*;
006: import fitnesse.testutil.*;
007: import fitnesse.http.*;
008: import fitnesse.wiki.*;
009:
010: public class EditResponderTest extends AbstractRegex {
011: private WikiPage root;
012:
013: private MockRequest request;
014:
015: private Responder responder;
016:
017: private SimpleResponse response;
018:
019: private PageCrawler crawler;
020:
021: public void setUp() throws Exception {
022: root = InMemoryPage.makeRoot("root");
023: crawler = root.getPageCrawler();
024: request = new MockRequest();
025: responder = new EditResponder();
026: }
027:
028: public void testResponse() throws Exception {
029: crawler.addPage(root, PathParser.parse("ChildPage"),
030: "child content with <html>");
031: request.setResource("ChildPage");
032:
033: response = (SimpleResponse) responder.makeResponse(
034: new FitNesseContext(root), request);
035: assertEquals(200, response.getStatus());
036:
037: String body = response.getContent();
038: assertSubString("<html>", body);
039: assertSubString("<form", body);
040: assertSubString("method=\"post\"", body);
041: assertSubString("child content with <html>", body);
042: assertSubString("name=\"responder\"", body);
043: assertSubString("name=\"" + EditResponder.SAVE_ID + "\"", body);
044: assertSubString("name=\"" + EditResponder.TICKET_ID + "\"",
045: body);
046: assertSubString("type=\"submit\"", body);
047: }
048:
049: public void testPasteFromExcelExists() throws Exception {
050: response = (SimpleResponse) responder.makeResponse(
051: new FitNesseContext(root), request);
052: String body = response.getContent();
053: assertMatches("SpreadsheetTranslator.js", body);
054: assertMatches("spreadsheetSupport.js", body);
055: }
056:
057: public void testTableWizard() throws Exception {
058: final String TOP_LEVEL = "LevelOne";
059: final String MID_LEVEL = "LevelTwo";
060: final String BOTTOM_LEVEL = "LevelThree";
061:
062: final String FIXTURE_ONE = "FixtureOne";
063: final String FIXTURE_TWO = "FixtureTwo";
064: final String FIXTURE_THREE = "FixtureThree";
065:
066: buildPageHierarchyWithFixtures(TOP_LEVEL, MID_LEVEL,
067: BOTTOM_LEVEL, FIXTURE_ONE, FIXTURE_TWO, FIXTURE_THREE);
068: final String pathName = TOP_LEVEL + PathParser.PATH_SEPARATOR
069: + MID_LEVEL + PathParser.PATH_SEPARATOR + BOTTOM_LEVEL;
070: String body = invokeEditResponder(pathName);
071:
072: assertTrue(body.indexOf("<select name=\"fixtureTable\"") != -1);
073: assertSubString("<option value=\"default\">- Fixture -", body);
074: assertSubString("<option value=\"" + FIXTURE_ONE + "\">"
075: + FIXTURE_ONE, body);
076: assertSubString("<option value=\"" + FIXTURE_TWO + "\">"
077: + FIXTURE_TWO, body);
078: assertSubString("<option value=\"" + FIXTURE_THREE + "\">"
079: + FIXTURE_THREE, body);
080: assertTrue(body.indexOf("Not.A.Fixture") == -1);
081: }
082:
083: private String invokeEditResponder(final String pathName)
084: throws Exception {
085: request.setResource(pathName);
086:
087: WikiPagePath path = PathParser.parse(pathName);
088: setTestAttributeForPage(crawler.getPage(root, path));
089: response = (SimpleResponse) responder.makeResponse(
090: new FitNesseContext(root), request);
091: String body = response.getContent();
092: return body;
093: }
094:
095: private void buildPageHierarchyWithFixtures(final String TOP_LEVEL,
096: final String MID_LEVEL, final String BOTTOM_LEVEL,
097: final String FIXTURE_ONE, final String FIXTURE_TWO,
098: final String FIXTURE_THREE) throws Exception {
099: WikiPagePath topLevelPath = PathParser.parse(TOP_LEVEL);
100: WikiPagePath midLevelPath = PathParser.parse(MID_LEVEL);
101: WikiPagePath bottomLevelPath = PathParser.parse(BOTTOM_LEVEL);
102:
103: WikiPage topPage = crawler.addPage(root, topLevelPath,
104: "!fixture " + FIXTURE_ONE
105: + "\r\nNot.A.Fixture\r\n!fixture "
106: + FIXTURE_TWO);
107: WikiPage level2 = crawler.addPage(topPage, midLevelPath,
108: "!fixture " + FIXTURE_THREE);
109: crawler.addPage(level2, bottomLevelPath, "Level three");
110: }
111:
112: public void testMissingPageDoesNotGetCreated() throws Exception {
113: request.setResource("MissingPage");
114: responder.makeResponse(new FitNesseContext(root), request);
115: assertFalse(root.hasChildPage("MissingPage"));
116: }
117:
118: private void setTestAttributeForPage(WikiPage page)
119: throws Exception {
120: PageData data = page.getData();
121: data.setAttribute(WikiPage.ACTION_TEST, "true");
122: page.commit(data);
123: }
124: }
|