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.testutil.*;
006: import fitnesse.wiki.*;
007:
008: public class ErrorLogGeneratorTest extends RegexTest {
009: private static String ErrorLogName = ExecutionLog.ErrorLogName;
010:
011: private WikiPage testPage;
012: private MockCommandRunner runner;
013: private ExecutionLog log;
014: private WikiPage root;
015: private WikiPage errorLogsParentPage;
016:
017: public void setUp() throws Exception {
018: root = InMemoryPage.makeRoot("RooT");
019: errorLogsParentPage = root.addChildPage(ErrorLogName);
020: testPage = root.addChildPage("TestPage");
021: runner = new MockCommandRunner("some command", 123);
022: log = new ExecutionLog(testPage, runner);
023: }
024:
025: public void tearDown() throws Exception {
026: }
027:
028: public void testPageIsCreated() throws Exception {
029: log.publish();
030: assertTrue(errorLogsParentPage.hasChildPage(testPage.getName()));
031: }
032:
033: public void testErrorLogContentIsReplaced() throws Exception {
034: WikiPage errorLogPage = root.getPageCrawler().addPage(root,
035: PathParser.parse("ErrorLogs.TestPage"));
036: PageData data = errorLogPage.getData();
037: data.setContent("old content");
038: errorLogPage.commit(data);
039:
040: log.publish();
041: String content = errorLogPage.getData().getContent();
042: assertNotSubString("old content", content);
043: }
044:
045: public void testBasicContent() throws Exception {
046: String content = getGeneratedContent();
047:
048: assertSubString("'''Command: '''", content);
049: assertSubString("!-some command-!", content);
050: assertSubString("'''Exit code: '''", content);
051: assertSubString("123", content);
052: assertSubString("'''Date: '''", content);
053: assertSubString("'''Time elapsed: '''", content);
054: }
055:
056: private String getGeneratedContent() throws Exception {
057: log.publish();
058: WikiPage errorLogPage = errorLogsParentPage
059: .getChildPage(testPage.getName());
060: String content = errorLogPage.getData().getContent();
061: return content;
062: }
063:
064: public void testNoExtraLogTextWasGenerated() throws Exception {
065: String content = getGeneratedContent();
066:
067: assertNotSubString("Exception", content);
068: assertNotSubString("Standard Error", content);
069: assertNotSubString("Standard Output", content);
070: }
071:
072: public void testStdout() throws Exception {
073: runner.setOutput("standard output that got printed");
074: String content = getGeneratedContent();
075:
076: assertSubString("'''Standard Output:'''", content);
077: assertSubString("standard output that got printed", content);
078: }
079:
080: public void testStderr() throws Exception {
081: runner.setError("standard error that got printed");
082: String content = getGeneratedContent();
083:
084: assertSubString("'''Standard Error:'''", content);
085: assertSubString("standard error that got printed", content);
086: }
087:
088: public void testException() throws Exception {
089: log.addException(new Exception("I made this"));
090: String content = getGeneratedContent();
091:
092: assertSubString("'''Internal Exception:'''", content);
093: assertSubString("I made this", content);
094: }
095:
096: public void testExecutionReport_Ok() throws Exception {
097: WikiPageDummy wikiPageDummy = new WikiPageDummy(
098: "This.Is.Not.A.Real.Location");
099: MockCommandRunner mockCommandRunner = new MockCommandRunner();
100: ExecutionLog executionLog = new ExecutionLog(wikiPageDummy,
101: mockCommandRunner);
102: ExecutionStatus result;
103:
104: if (executionLog.exceptionCount() > 0)
105: result = ExecutionStatus.ERROR;
106: else if (executionLog.hasCapturedOutput())
107: result = ExecutionStatus.OUTPUT;
108: else
109: result = ExecutionStatus.OK;
110:
111: assertSame(ExecutionStatus.OK, result);
112: }
113:
114: public void testExecutionReport_Output() throws Exception {
115: WikiPageDummy wikiPageDummy = new WikiPageDummy(
116: "This.Is.Not.A.Real.Location");
117: MockCommandRunner mockCommandRunner = new MockCommandRunner();
118: mockCommandRunner.setOutput("I wrote something here");
119: ExecutionLog executionLog = new ExecutionLog(wikiPageDummy,
120: mockCommandRunner);
121: ExecutionStatus result;
122:
123: if (executionLog.exceptionCount() > 0)
124: result = ExecutionStatus.ERROR;
125: else if (executionLog.hasCapturedOutput())
126: result = ExecutionStatus.OUTPUT;
127: else
128: result = ExecutionStatus.OK;
129:
130: assertSame(ExecutionStatus.OUTPUT, result);
131: }
132:
133: public void testExecutionReport_Error() throws Exception {
134: WikiPageDummy wikiPageDummy = new WikiPageDummy(
135: "This.Is.Not.A.Real.Location");
136: MockCommandRunner mockCommandRunner = new MockCommandRunner();
137: ExecutionLog executionLog = new ExecutionLog(wikiPageDummy,
138: mockCommandRunner);
139: executionLog.addException(new RuntimeException("I messed up"));
140: ExecutionStatus result;
141:
142: if (executionLog.exceptionCount() > 0)
143: result = ExecutionStatus.ERROR;
144: else if (executionLog.hasCapturedOutput())
145: result = ExecutionStatus.OUTPUT;
146: else
147: result = ExecutionStatus.OK;
148:
149: assertSame(ExecutionStatus.ERROR, result);
150: }
151: }
|