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.testutil.*;
008: import fitnesse.FitNesseContext;
009: import java.util.*;
010:
011: public class SuiteResponderTest extends AbstractRegex {
012: private MockRequest request;
013:
014: private SuiteResponder responder;
015:
016: private WikiPage root;
017:
018: private WikiPage suite;
019:
020: private int port = 9123;
021:
022: private FitNesseContext context;
023:
024: private FitSocketReceiver receiver;
025:
026: private WikiPage testPage;
027:
028: private PageCrawler crawler;
029:
030: private WikiPage testPage2;
031:
032: private WikiPage testChildPage;
033:
034: private String suitePageName;
035:
036: public void setUp() throws Exception {
037: suitePageName = "SuitePage";
038: root = InMemoryPage.makeRoot("RooT");
039: crawler = root.getPageCrawler();
040: PageData data = root.getData();
041: data.setContent(classpathWidgets());
042: root.commit(data);
043: suite = crawler.addPage(root, PathParser.parse(suitePageName),
044: "This is the test suite\n");
045: testPage = addTestToSuite("TestOne",
046: "|!-fitnesse.testutil.PassFixture-!|\n");
047:
048: request = new MockRequest();
049: request.setResource(suitePageName);
050: responder = new SuiteResponder();
051: responder.page = suite;
052: context = new FitNesseContext(root);
053: context.port = port;
054:
055: receiver = new FitSocketReceiver(port, context.socketDealer);
056: }
057:
058: private WikiPage addTestToSuite(String name, String content)
059: throws Exception {
060: return addTestPage(suite, name, content);
061: }
062:
063: private WikiPage addTestPage(WikiPage page, String name,
064: String content) throws Exception {
065: WikiPage testPage = crawler.addPage(page, PathParser
066: .parse(name), content);
067: PageData data = testPage.getData();
068: data.setAttribute(WikiPage.ACTION_TEST);
069: testPage.commit(data);
070: return testPage;
071: }
072:
073: public void tearDown() throws Exception {
074: receiver.close();
075: receiver = null;
076: }
077:
078: private String runSuite() throws Exception {
079: receiver.receiveSocket();
080: Response response = responder.makeResponse(context, request);
081: MockResponseSender sender = new MockResponseSender(response);
082: String results = sender.sentData();
083: return results;
084: }
085:
086: public void testGatherXRefTestPages() throws Exception {
087: WikiPage testPage = crawler.addPage(root, PathParser
088: .parse("SomePage"), "!xref PageA\n!xref PageB");
089: WikiPage pageA = crawler.addPage(root, PathParser
090: .parse("PageA"));
091: WikiPage pageB = crawler.addPage(root, PathParser
092: .parse("PageB"));
093: List xrefTestPages = SuiteResponder
094: .gatherCrossReferencedTestPages(testPage, root);
095: assertEquals(2, xrefTestPages.size());
096: assertTrue(xrefTestPages.contains(pageA));
097: assertTrue(xrefTestPages.contains(pageB));
098: }
099:
100: public void testBuildClassPath() throws Exception {
101: responder.page = suite;
102: List testPages = SuiteResponder.getAllTestPagesUnder(suite);
103: String classpath = SuiteResponder.buildClassPath(testPages,
104: responder.page);
105: assertSubString("classes", classpath);
106: assertSubString("dummy.jar", classpath);
107: }
108:
109: // FIXME
110: public void XtestWithOneTest() throws Exception {
111: String results = runSuite();
112: assertSubString("href=\"#TestOne\"", results);
113: assertSubString("1 right", results);
114: assertSubString("id=\"TestOne\"", results);
115: assertSubString(" href=\"SuitePage.TestOne\"", results);
116: assertSubString("PassFixture", results);
117: }
118:
119: // FIXME
120: public void XtestPageWithXref() throws Exception {
121: PageData data = suite.getData();
122: data
123: .setContent("!see XrefOne\r\n!see XrefTwo\n!see XrefThree\n");
124: suite.commit(data);
125: addTestPage(root, "XrefOne",
126: "|!-fitnesse.testutil.PassFixture-!|\n");
127: addTestPage(root, "XrefTwo",
128: "|!-fitnesse.testutil.PassFixture-!|\n");
129:
130: String results = runSuite();
131: assertSubString("href=\"#XrefOne\"", results);
132: assertSubString("href=\"#XrefTwo\"", results);
133: }
134:
135: // FIXME
136: public void XtestWithTwoTests() throws Exception {
137: addTestToSuite("TestTwo",
138: "|!-fitnesse.testutil.FailFixture-!|\n\n|!-fitnesse.testutil.FailFixture-!|\n");
139: String results = runSuite();
140: assertSubString("href=\"#TestOne\"", results);
141: assertSubString("href=\"#TestTwo\"", results);
142: assertSubString("1 right", results);
143: assertSubString("2 wrong", results);
144: assertSubString("id=\"TestOne\"", results);
145: assertSubString("id=\"TestTwo\"", results);
146: assertSubString("PassFixture", results);
147: assertSubString("FailFixture", results);
148: }
149:
150: // FIXME
151: public void XtestSuiteWithEmptyPage() throws Exception {
152: suite = crawler.addPage(root, PathParser
153: .parse("SuiteWithEmptyPage"),
154: "This is the empty page test suite\n");
155: addTestPage(suite, "TestThatIsEmpty", "");
156: request.setResource("SuiteWithEmptyPage");
157: runSuite();
158:
159: WikiPagePath errorLogPath = PathParser
160: .parse("ErrorLogs.SuiteWithEmptyPage");
161: WikiPage errorLog = crawler.getPage(root, errorLogPath);
162: PageData data = errorLog.getData();
163: String errorLogContent = data.getContent();
164: assertNotSubString("Exception", errorLogContent);
165: }
166:
167: // FIXME
168: public void XtestSuiteWithOneTestWithoutTable() throws Exception {
169: addTestToSuite("TestWithoutTable", "This test has not table");
170: addTestToSuite("TestTwo",
171: "|!-fitnesse.testutil.PassFixture-!|\n");
172: addTestToSuite("TestThree",
173: "|!-fitnesse.testutil.PassFixture-!|\n");
174:
175: String results = runSuite();
176: assertSubString("TestOne", results);
177: assertSubString("TestTwo", results);
178: assertSubString("TestThree", results);
179: assertSubString("TestWithoutTable", results);
180: }
181:
182: public void testExitCodeHeader() throws Exception {
183: String results = runSuite();
184: assertSubString("Exit-Code: 0", results);
185: }
186:
187: public void testGetAllTestPages() throws Exception {
188: setUpForGetAllTestPages();
189: List testPages = SuiteResponder.getAllTestPagesUnder(suite);
190: assertEquals(3, testPages.size());
191: assertEquals(true, testPages.contains(testPage));
192: assertEquals(true, testPages.contains(testPage2));
193: assertEquals(true, testPages.contains(testChildPage));
194: }
195:
196: private void setUpForGetAllTestPages() throws Exception {
197: testPage2 = addTestToSuite("TestPageTwo", "test page two");
198: testChildPage = testPage2.addChildPage("TestChildPage");
199: PageData data = testChildPage.getData();
200: data.setAttribute(WikiPage.ACTION_TEST);
201: testChildPage.commit(data);
202: }
203:
204: public void testGetAllTestPagesSortsByQulifiedNames()
205: throws Exception {
206: setUpForGetAllTestPages();
207: List testPages = SuiteResponder.getAllTestPagesUnder(suite);
208: assertEquals(3, testPages.size());
209: assertEquals(testPage, testPages.get(0));
210: assertEquals(testPage2, testPages.get(1));
211: assertEquals(testChildPage, testPages.get(2));
212: }
213:
214: public void testSetUpAndTearDown() throws Exception {
215: WikiPage setUp = crawler.addPage(root, PathParser
216: .parse("SuiteSetUp"), "suite set up");
217: WikiPage tearDown = crawler.addPage(root, PathParser
218: .parse("SuiteTearDown"), "suite tear down");
219:
220: List testPages = responder.makePageList();
221: assertEquals(3, testPages.size());
222: assertSame(setUp, testPages.get(0));
223: assertSame(tearDown, testPages.get(2));
224: }
225:
226: public void testExecutionStatusAppears() throws Exception {
227: String results = runSuite();
228: assertHasRegexp(divWithIdAndContent("execution-status", ".*?"),
229: results);
230: }
231:
232: public void testTestSummaryInformationIncludesPageSummary()
233: throws Exception {
234: String results = runSuite();
235: assertHasRegexp(
236: divWithIdAndContent("test-summary",
237: ".*?Test Pages:.*? .*?Assertions:.*?"),
238: results);
239: }
240:
241: public void testFormatTestSummaryInformation() throws Exception {
242: String results = runSuite();
243: assertHasRegexp(
244: divWithIdAndContent("test-summary",
245: ".*?<strong>Test Pages:</strong>.*?<strong>Assertions:</strong>.*?"),
246: results);
247: }
248:
249: private String classpathWidgets() {
250: return "!path classes\n" + "!path lib/dummy.jar\n";
251: }
252: }
|