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.wiki.*;
006: import fitnesse.http.*;
007: import fitnesse.*;
008: import fitnesse.testutil.AbstractRegex;
009:
010: public class TableWizardResponderTest 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 TableWizardResponder();
026: }
027:
028: public void testResponseForNonFixture() throws Exception {
029: prepareTest();
030: request.setResource("ChildPage");
031: request.addInput("fixture", "fitnesse.FitNesse");
032: request.addInput("text", "child content");
033:
034: response = (SimpleResponse) responder.makeResponse(
035: new FitNesseContext(root), request);
036: String body = response.getContent();
037: assertMatches("child content", body);
038: // FIXME
039: // assertMatches("# fitnesse.FitNesse is not a valid fixture! #", body);
040: }
041:
042: public void testResponseForNonColumnFixture() throws Exception {
043: crawler.addPage(root, PathParser.parse("ChildPage"),
044: "child content with <html>");
045: request.setResource("ChildPage");
046: request.addInput("fixture", "fitnesse.FitNesse");
047: request.addInput("text",
048: "child content with <html>\nmore text.\n");
049:
050: response = (SimpleResponse) responder.makeResponse(
051: new FitNesseContext(root), request);
052: assertEquals(200, response.getStatus());
053:
054: String body = response.getContent();
055: assertTrue(body.indexOf("<html>") != -1);
056: assertTrue(body.indexOf("<form") != -1);
057: assertTrue(body.indexOf("method=\"post\"") != -1);
058: assertTrue(body.indexOf("child content with <html>") != -1);
059: assertTrue(body.indexOf("name=\"saveId\"") != -1);
060: assertMatches(
061: "child content with <html>.*more text..*!-fitnesse.FitNesse-!|",
062: body);
063: }
064:
065: // public void testResponseForColumnFixture() throws Exception
066: // {
067: // prepareTest();
068: // request.setResource("ChildPage");
069: // request.addInput("fixture", "fitnesse.testutil.DummyClassForWizardTest");
070: // request.addInput("text", "child content");
071: //
072: // response = (SimpleResponse)responder.makeResponse(new
073: // FitNesseContext(root), request);
074: // String body = response.getContent();
075: // assertTrue(body.indexOf("child
076: // content\n!|fitnesse.testutil.DummyClassForWizardTest|\n|v1 |f1()|\n") !=
077: // -1);
078: // assertTrue(body.indexOf("|int|int |") != -1);
079: // }
080:
081: // public void testResponseForRowFixture() throws Exception
082: // {
083: // prepareTest();
084: // request.setResource("ChildPage");
085: // request.addInput("fixture", "fitnesse.fixtures.PayCheckRecordFixture");
086: // request.addInput("text", "child content");
087: //
088: // response = (SimpleResponse)responder.makeResponse(new
089: // FitNesseContext(root), request);
090: // String body = response.getContent();
091: // assertTrue(body.indexOf("child
092: // content\n!|fitnesse.fixtures.PayCheckRecordFixture|\n|employeeId|date
093: // |name |pay() |\n") != -1);
094: // assertTrue(body.indexOf( "|int |String|String|double|\n") != -1);
095: // }
096:
097: public void testCreateCommandLine() throws Exception {
098: prepareTest();
099: String commandLine = new TableWizardResponder()
100: .createCommandLine(root.getChildPage("ChildPage"),
101: "fitnesse.fixtures.ResponseExaminer");
102: assertTrue(commandLine.startsWith("java -cp "));
103: assertTrue(commandLine
104: .endsWith("fitnesse.FixtureTemplateCreator fitnesse.fixtures.ResponseExaminer"));
105: }
106:
107: private void prepareTest() throws Exception {
108: crawler.addPage(root, PathParser.parse("ChildPage"),
109: "child content");
110: PageData data = root.getData();
111: data.setContent("!path classes");
112: root.commit(data);
113: }
114: }
|