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