1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus;
|
3
|
|
import java.io.PrintWriter;
|
4
|
|
import java.io.StringWriter;
|
5
|
|
import java.io.Serializable;
|
6
|
|
|
7
|
|
/**
|
8
|
|
* Represent the result of the execution of the Test class by the
|
9
|
|
* server redirector.If any exception was raised during the test, it
|
10
|
|
* is saved by this class.
|
11
|
|
*
|
12
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
13
|
|
*
|
14
|
|
* @version $Id: WebTestResult.java,v 1.4 2002/07/21 12:09:16 vmassol Exp $
|
15
|
|
*/
|
16
|
|
public class WebTestResult implements Serializable {
|
17
|
|
/**
|
18
|
|
* Name of the exception class if an error occurred
|
19
|
|
*/
|
20
|
|
private String exceptionClassName;
|
21
|
|
/**
|
22
|
|
* Save the stack trace as text because otherwise it will not be
|
23
|
|
* transmitted back to the client (the stack trac field in the
|
24
|
|
* <code>Throwable</code> class is transient).
|
25
|
|
*/
|
26
|
|
private String exceptionStackTrace;
|
27
|
|
/**
|
28
|
|
* The exception message if an error occurred
|
29
|
|
*/
|
30
|
|
private String exceptionMessage;
|
31
|
|
/**
|
32
|
|
* Name of Root XML tag (see {@link #toXml()}).
|
33
|
|
*/
|
34
|
|
public static final String XML_ROOT_ELEMENT = "webresult";
|
35
|
|
/**
|
36
|
|
* Name of Exception XML tag (see {@link #toXml()}).
|
37
|
|
*/
|
38
|
|
public static final String XML_EXCEPTION_ELEMENT = "exception";
|
39
|
|
/**
|
40
|
|
* Name of Exception XML attribute that contains the exception classname
|
41
|
|
* (see {@link #toXml()}).
|
42
|
|
*/
|
43
|
|
public static final String XML_EXCEPTION_CLASSNAME_ATTRIBUTE = "classname";
|
44
|
|
/**
|
45
|
|
* Name of Exception Message XML tag (see {@link #toXml()}).
|
46
|
|
*/
|
47
|
|
public static final String XML_EXCEPTION_MESSAGE_ELEMENT = "message";
|
48
|
|
/**
|
49
|
|
* Name of Exception Stacktrace XML tag (see {@link #toXml()}).
|
50
|
|
*/
|
51
|
|
public static final String XML_EXCEPTION_STACKTRACE_ELEMENT = "stacktrace";
|
52
|
|
/**
|
53
|
|
* Constructor to call when the test was ok and no error was raised.
|
54
|
|
*/
|
55
|
64
|
public WebTestResult() {
|
56
|
64
|
super();
|
57
|
|
}
|
58
|
|
/**
|
59
|
|
* Constructor to call when an exception was raised during the test.
|
60
|
|
*
|
61
|
|
* @param theException the raised exception.
|
62
|
|
*/
|
63
|
5
|
public WebTestResult(Throwable theException) {
|
64
|
5
|
super();
|
65
|
5
|
this.exceptionClassName = theException.getClass().getName();
|
66
|
5
|
this.exceptionMessage = theException.getMessage();
|
67
|
5
|
StringWriter sw = new StringWriter();
|
68
|
5
|
PrintWriter pw = new PrintWriter(sw);
|
69
|
5
|
theException.printStackTrace(pw);
|
70
|
5
|
this.exceptionStackTrace = sw.toString();
|
71
|
|
}
|
72
|
|
/**
|
73
|
|
* Constructor used to reconstruct a WebTestResult object from its String
|
74
|
|
* representation.
|
75
|
|
*
|
76
|
|
* @param theClassName the class name of the exception thrown on the server
|
77
|
|
* side
|
78
|
|
* @param theMessage the message of the exception thrown on the server side
|
79
|
|
* @param theStackTrace the stack trace of the exception thrown on the
|
80
|
|
* server side
|
81
|
|
*/
|
82
|
5
|
public WebTestResult(String theClassName, String theMessage, String theStackTrace) {
|
83
|
5
|
super();
|
84
|
5
|
this.exceptionClassName = theClassName;
|
85
|
5
|
this.exceptionMessage = theMessage;
|
86
|
5
|
this.exceptionStackTrace = theStackTrace;
|
87
|
|
}
|
88
|
|
/**
|
89
|
|
* @return the exception class name if an exception was raised or
|
90
|
|
* <code>null</code> otherwise.
|
91
|
|
*/
|
92
|
10
|
public String getExceptionClassName() {
|
93
|
10
|
return this.exceptionClassName;
|
94
|
|
}
|
95
|
|
|
96
|
|
/**
|
97
|
|
* @return the exception message if an exception was raised or
|
98
|
|
* <code>null</code> otherwise.
|
99
|
|
*/
|
100
|
6
|
public String getExceptionMessage() {
|
101
|
6
|
return this.exceptionMessage;
|
102
|
|
}
|
103
|
|
|
104
|
|
/**
|
105
|
|
* @return true if an exception was raised during the test, false otherwise.
|
106
|
|
*/
|
107
|
75
|
public boolean hasException() {
|
108
|
75
|
return (this.exceptionClassName != null);
|
109
|
|
}
|
110
|
|
|
111
|
|
/**
|
112
|
|
* @return the stack trace as a string
|
113
|
|
*/
|
114
|
6
|
public String getExceptionStackTrace() {
|
115
|
6
|
return this.exceptionStackTrace;
|
116
|
|
}
|
117
|
|
|
118
|
|
/**
|
119
|
|
* @see Object#toString()
|
120
|
|
*/
|
121
|
0
|
public String toString() {
|
122
|
0
|
StringBuffer buffer = new StringBuffer();
|
123
|
0
|
if (this.hasException()) {
|
124
|
0
|
buffer.append("Test failed, Exception message = [" + this.getExceptionMessage() + "]");
|
125
|
|
} else {
|
126
|
0
|
buffer.append("Test ok");
|
127
|
|
}
|
128
|
0
|
return buffer.toString();
|
129
|
|
}
|
130
|
|
|
131
|
|
/**
|
132
|
|
* @return an XML representation of the test result to be sent in the
|
133
|
|
* HTTP response to the Cactus client.
|
134
|
|
*/
|
135
|
9
|
public String toXml() {
|
136
|
9
|
StringBuffer xmlText = new StringBuffer();
|
137
|
9
|
xmlText.append("<webresult>");
|
138
|
9
|
if (this.hasException()) {
|
139
|
6
|
xmlText.append("<exception classname=\"");
|
140
|
6
|
xmlText.append(this.exceptionClassName);
|
141
|
6
|
xmlText.append("\">");
|
142
|
6
|
xmlText.append("<message><![CDATA[");
|
143
|
6
|
xmlText.append(this.exceptionMessage);
|
144
|
6
|
xmlText.append("]]></message>");
|
145
|
6
|
xmlText.append("<stacktrace><![CDATA[");
|
146
|
6
|
xmlText.append(this.exceptionStackTrace);
|
147
|
6
|
xmlText.append("]]></stacktrace>");
|
148
|
6
|
xmlText.append("</exception>");
|
149
|
|
}
|
150
|
9
|
xmlText.append("</webresult>");
|
151
|
9
|
return xmlText.toString();
|
152
|
|
}
|
153
|
|
|
154
|
|
}
|