Source Code Cross Referenced for WebTestResult.java in  » Testing » jakarta-cactus » org » apache » cactus » internal » 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 » jakarta cactus » org.apache.cactus.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2004 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.internal;
021:
022:        import java.io.PrintWriter;
023:        import java.io.Serializable;
024:        import java.io.StringWriter;
025:
026:        /**
027:         * Represent the result of the execution of the Test class by the
028:         * server redirector. If any exception was raised during the test, it
029:         * is saved by this class.
030:         *
031:         * @version $Id: WebTestResult.java 238991 2004-05-22 11:34:50Z vmassol $
032:         */
033:        public class WebTestResult implements  Serializable {
034:            /**
035:             * Name of Root XML tag (see {@link #toXml()}).
036:             */
037:            public static final String XML_ROOT_ELEMENT = "webresult";
038:
039:            /**
040:             * Name of Exception XML tag (see {@link #toXml()}).
041:             */
042:            public static final String XML_EXCEPTION_ELEMENT = "exception";
043:
044:            /**
045:             * Name of Exception XML attribute that contains the exception classname
046:             * (see {@link #toXml()}).
047:             */
048:            public static final String XML_EXCEPTION_CLASSNAME_ATTRIBUTE = "classname";
049:
050:            /**
051:             * Name of Exception Message XML tag (see {@link #toXml()}).
052:             */
053:            public static final String XML_EXCEPTION_MESSAGE_ELEMENT = "message";
054:
055:            /**
056:             * Name of Exception Stacktrace XML tag (see {@link #toXml()}).
057:             */
058:            public static final String XML_EXCEPTION_STACKTRACE_ELEMENT = "stacktrace";
059:
060:            /**
061:             * Name of the exception class if an error occurred
062:             */
063:            private String exceptionClassName;
064:
065:            /**
066:             * Save the stack trace as text because otherwise it will not be
067:             * transmitted back to the client (the stack trac field in the
068:             * <code>Throwable</code> class is transient).
069:             */
070:            private String exceptionStackTrace;
071:
072:            /**
073:             * The exception message if an error occurred
074:             */
075:            private String exceptionMessage;
076:
077:            /**
078:             * Constructor to call when the test was ok and no error was raised.
079:             */
080:            public WebTestResult() {
081:            }
082:
083:            /**
084:             * Constructor to call when an exception was raised during the test.
085:             *
086:             * @param theException the raised exception.
087:             */
088:            public WebTestResult(Throwable theException) {
089:                this .exceptionClassName = theException.getClass().getName();
090:                this .exceptionMessage = theException.getMessage();
091:
092:                // Save the stack trace as text
093:                StringWriter sw = new StringWriter();
094:                PrintWriter pw = new PrintWriter(sw);
095:
096:                theException.printStackTrace(pw);
097:                this .exceptionStackTrace = sw.toString();
098:            }
099:
100:            /**
101:             * Constructor used to reconstruct a WebTestResult object from its String
102:             * representation.
103:             *
104:             * @param theClassName the class name of the exception thrown on the server
105:             *        side
106:             * @param theMessage the message of the exception thrown on the server side
107:             * @param theStackTrace the stack trace of the exception thrown on the
108:             *        server side
109:             */
110:            public WebTestResult(String theClassName, String theMessage,
111:                    String theStackTrace) {
112:                this .exceptionClassName = theClassName;
113:                this .exceptionMessage = theMessage;
114:                this .exceptionStackTrace = theStackTrace;
115:            }
116:
117:            /**
118:             * @return the exception class name if an exception was raised or
119:             *         <code>null</code> otherwise.
120:             */
121:            public String getExceptionClassName() {
122:                return this .exceptionClassName;
123:            }
124:
125:            /**
126:             * @return the exception message if an exception was raised or
127:             *         <code>null</code> otherwise.
128:             */
129:            public String getExceptionMessage() {
130:                return this .exceptionMessage;
131:            }
132:
133:            /**
134:             * @return true if an exception was raised during the test, false otherwise.
135:             */
136:            public boolean hasException() {
137:                return (this .exceptionClassName != null);
138:            }
139:
140:            /**
141:             * @return the stack trace as a string
142:             */
143:            public String getExceptionStackTrace() {
144:                return this .exceptionStackTrace;
145:            }
146:
147:            /**
148:             * @see Object#toString()
149:             */
150:            public String toString() {
151:                StringBuffer buffer = new StringBuffer();
152:
153:                if (hasException()) {
154:                    buffer.append("Test failed, Exception message = ["
155:                            + getExceptionMessage() + "]");
156:                } else {
157:                    buffer.append("Test ok");
158:                }
159:
160:                return buffer.toString();
161:            }
162:
163:            /**
164:             * @return an XML representation of the test result to be sent in the
165:             *         HTTP response to the Cactus client.
166:             */
167:            public String toXml() {
168:                StringBuffer xmlText = new StringBuffer();
169:
170:                xmlText.append("<" + XML_ROOT_ELEMENT + ">");
171:
172:                if (hasException()) {
173:                    xmlText.append("<" + XML_EXCEPTION_ELEMENT + " "
174:                            + XML_EXCEPTION_CLASSNAME_ATTRIBUTE + "=\"");
175:                    xmlText.append(this .exceptionClassName);
176:                    xmlText.append("\">");
177:                    xmlText.append("<" + XML_EXCEPTION_MESSAGE_ELEMENT
178:                            + "><![CDATA[");
179:                    xmlText.append(this .exceptionMessage);
180:                    xmlText.append("]]></" + XML_EXCEPTION_MESSAGE_ELEMENT
181:                            + ">");
182:                    xmlText.append("<" + XML_EXCEPTION_STACKTRACE_ELEMENT
183:                            + "><![CDATA[");
184:                    xmlText.append(this .exceptionStackTrace);
185:                    xmlText.append("]]></" + XML_EXCEPTION_STACKTRACE_ELEMENT
186:                            + ">");
187:                    xmlText.append("</" + XML_EXCEPTION_ELEMENT + ">");
188:                }
189:
190:                xmlText.append("</" + XML_ROOT_ELEMENT + ">");
191:
192:                return xmlText.toString();
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.