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.run;
004:
005: import fitnesse.wiki.*;
006: import fitnesse.http.*;
007: import fitnesse.FitNesseContext;
008: import fitnesse.testutil.AbstractRegex;
009:
010: public class FitClientResponderTest extends AbstractRegex {
011: private WikiPage root;
012:
013: private FitClientResponder responder;
014:
015: private MockRequest request;
016:
017: private FitNesseContext context;
018:
019: private Response response;
020:
021: private MockResponseSender sender;
022:
023: private static PageCrawler crawler;
024:
025: private static WikiPage suite;
026:
027: public void setUp() throws Exception {
028: root = InMemoryPage.makeRoot("RooT");
029: responder = new FitClientResponder();
030: request = new MockRequest();
031: context = new FitNesseContext(root);
032:
033: buildSuite(root);
034: }
035:
036: public static void buildSuite(WikiPage root) throws Exception {
037: crawler = root.getPageCrawler();
038: suite = crawler.addPage(root, PathParser.parse("SuitePage"),
039: "!path classes\n");
040: crawler.addPage(suite, PathParser.parse("TestPassing"),
041: "!|fitnesse.testutil.PassFixture|\n");
042: crawler.addPage(suite, PathParser.parse("TestFailing"),
043: "!|fitnesse.testutil.FailFixture|\n");
044: crawler.addPage(suite, PathParser.parse("TestError"),
045: "!|fitnesse.testutil.ErrorFixture|\n");
046: crawler.addPage(suite, PathParser.parse("TestIgnore"),
047: "!|fitnesse.testutil.IgnoreFixture|\n");
048: crawler.addPage(suite, PathParser.parse("SomePage"),
049: "This is just some page.");
050: }
051:
052: public void tearDown() throws Exception {
053: }
054:
055: public void testPageNotFound() throws Exception {
056: String result = getResultFor("MissingPage");
057: assertSubString("MissingPage was not found", result);
058: }
059:
060: public void testOneTest() throws Exception {
061: String result = getResultFor("SuitePage.TestPassing");
062: assertEquals("0000000000", result.substring(0, 10));
063: assertSubString("PassFixture", result);
064: }
065:
066: public void testSuite() throws Exception {
067: String result = getResultFor("SuitePage");
068: assertEquals("0000000000", result.substring(0, 10));
069: assertSubString("PassFixture", result);
070: assertSubString("FailFixture", result);
071: assertSubString("ErrorFixture", result);
072: assertSubString("IgnoreFixture", result);
073: assertNotSubString("some page", result);
074: }
075:
076: public void testRelativePageNamesIncluded() throws Exception {
077: String result = getResultFor("SuitePage");
078: assertNotSubString("SuitePage", result);
079: assertSubString("TestPassing", result);
080: assertSubString("TestFailing", result);
081: assertSubString("TestError", result);
082: assertSubString("TestIgnore", result);
083: }
084:
085: public void testPageThatIsNoATest() throws Exception {
086: String result = getResultFor("SuitePage.SomePage");
087: assertSubString(
088: "SomePage is neither a Test page nor a Suite page.",
089: result);
090: }
091:
092: private String getResultFor(String name) throws Exception {
093: return getResultFor(name, false);
094: }
095:
096: private String getResultFor(String name, boolean addPaths)
097: throws Exception {
098: request.setResource(name);
099: if (addPaths)
100: request.addInput("includePaths", "blah");
101: response = responder.makeResponse(context, request);
102: sender = new MockResponseSender(response);
103: String result = sender.sentData();
104: return result;
105: }
106:
107: public void testWithClasspathOnSuite() throws Exception {
108: String result = getResultFor("SuitePage", true);
109: assertTrue(result.startsWith("00000000000000000007classes"));
110: }
111:
112: public void testWithClasspathOnTestInSuite() throws Exception {
113: crawler
114: .addPage(
115: suite,
116: PathParser.parse("TestPage"),
117: "!path jar.jar\n!path /some/dir/with/.class/files\n!|fitnesse.testutil.IgnoreFixture|\n");
118: String result = getResultFor("SuitePage.TestPage", true);
119:
120: assertSubString("classes", result);
121: assertSubString("jar.jar", result);
122: assertSubString("/some/dir/with/.class/files", result);
123: }
124: }
|