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