Source Code Cross Referenced for ExecutionLog.java in  » Testing » StoryTestIQ » fitnesse » responders » run » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » StoryTestIQ » fitnesse.responders.run 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.components.*;
007:        import fitnesse.responders.ErrorResponder;
008:        import fitnesse.html.*;
009:        import java.util.*;
010:        import java.text.SimpleDateFormat;
011:
012:        public class ExecutionLog {
013:            public static final String ErrorLogName = "ErrorLogs";
014:
015:            private PageCrawler crawler;
016:
017:            public static SimpleDateFormat makeDateFormat() {
018:                // SimpleDateFormat is not thread safe, so we need to create each
019:                // instance independently.
020:                return new SimpleDateFormat(
021:                        "h:mm:ss a (z) 'on' EEEE, MMMM d, yyyy");
022:            }
023:
024:            private String errorLogPageName;
025:
026:            private WikiPagePath errorLogPagePath;
027:
028:            private WikiPage root;
029:
030:            private CommandRunner runner;
031:
032:            private List reasons = new LinkedList();
033:
034:            private List exceptions = new LinkedList();
035:
036:            public ExecutionLog(WikiPage testPage, CommandRunner client)
037:                    throws Exception {
038:                this .runner = client;
039:
040:                crawler = testPage.getPageCrawler();
041:                crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
042:                root = crawler.getRoot(testPage);
043:                errorLogPagePath = crawler.getFullPath(testPage)
044:                        .addNameToFront(ErrorLogName);
045:                errorLogPageName = PathParser.render(errorLogPagePath);
046:            }
047:
048:            public void addException(Exception e) {
049:                exceptions.add(e);
050:            }
051:
052:            public void addReason(String reason) {
053:                if (!reasons.contains(reason))
054:                    reasons.add(reason);
055:            }
056:
057:            public void publish() throws Exception {
058:                String content = buildLogContent();
059:
060:                WikiPage errorLogPage = crawler.addPage(root, errorLogPagePath);
061:                PageData data = errorLogPage.getData();
062:                data.setContent(content);
063:                errorLogPage.commit(data);
064:            }
065:
066:            public String buildLogContent() {
067:                StringBuffer buffer = new StringBuffer();
068:                addEntry(buffer, "Date", makeDateFormat().format(new Date()));
069:                addEntry(buffer, "Command", runner.getCommand());
070:                addEntry(buffer, "Exit code", String.valueOf(runner
071:                        .getExitCode()));
072:                addEntry(buffer, "Time elapsed", (((double) runner
073:                        .getExecutionTime()) / 1000.0)
074:                        + " seconds");
075:                if (runner.wroteToOutputStream())
076:                    addOutputBlock(buffer);
077:                if (runner.wroteToErrorStream())
078:                    addErrorBlock(buffer);
079:                if (runner.hasExceptions() || exceptions.size() > 0)
080:                    addExceptionBlock(buffer);
081:                String content = buffer.toString();
082:                return content;
083:            }
084:
085:            private void addEntry(StringBuffer buffer, String key, String value) {
086:                buffer.append("|'''").append(key).append(": '''|").append("!-")
087:                        .append(value).append("-!").append("|\n");
088:            }
089:
090:            private void addOutputBlock(StringBuffer buffer) {
091:                buffer.append("----");
092:                buffer.append("'''Standard Output:'''").append("\n");
093:                buffer.append("{{{").append(runner.getOutput()).append("}}}");
094:            }
095:
096:            private void addErrorBlock(StringBuffer buffer) {
097:                buffer.append("----");
098:                buffer.append("'''Standard Error:'''").append("\n");
099:                buffer.append("{{{").append(runner.getError()).append("}}}");
100:            }
101:
102:            private void addExceptionBlock(StringBuffer buffer) {
103:                exceptions.addAll(runner.getExceptions());
104:                buffer.append("----");
105:                buffer.append("'''Internal Exception");
106:                if (exceptions.size() > 1)
107:                    buffer.append("s");
108:                buffer.append(":'''").append("\n");
109:                for (Iterator iterator = exceptions.iterator(); iterator
110:                        .hasNext();) {
111:                    Exception exception = (Exception) iterator.next();
112:                    buffer.append("{{{ ").append(
113:                            ErrorResponder.makeExceptionString(exception))
114:                            .append("}}}");
115:                }
116:            }
117:
118:            public int exceptionCount() {
119:                return exceptions.size();
120:            }
121:
122:            public String getErrorLogPageName() {
123:                return errorLogPageName;
124:            }
125:
126:            public boolean hasCapturedOutput() {
127:                return runner.wroteToErrorStream()
128:                        || runner.wroteToOutputStream();
129:            }
130:
131:            public String executionStatusHtml() throws Exception {
132:                String linkHref = getErrorLogPageName();
133:                return executionStatusHtml(linkHref, "");
134:            }
135:
136:            public String executionStatusHtml(String linkHref,
137:                    String imageUrlBase) throws Exception {
138:                ExecutionStatus executionStatus;
139:
140:                if (exceptionCount() > 0)
141:                    executionStatus = ExecutionStatus.ERROR;
142:                else if (hasCapturedOutput())
143:                    executionStatus = ExecutionStatus.OUTPUT;
144:                else
145:                    executionStatus = ExecutionStatus.OK;
146:
147:                HtmlTag status = new HtmlTag("div");
148:                status.addAttribute("id", "execution-status");
149:                HtmlTag image = new HtmlTag("img");
150:                image.addAttribute("src", imageUrlBase
151:                        + "/files/images/executionStatus/"
152:                        + executionStatus.getIconFilename());
153:                status.add(HtmlUtil.makeLink(linkHref, image.html()));
154:                status.add(HtmlUtil.BR);
155:                status.add(HtmlUtil.makeLink(linkHref, executionStatus
156:                        .getMessage()));
157:                return status.html();
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.