01: package com.canoo.webtest.engine;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import org.apache.tools.ant.BuildException;
07:
08: import com.canoo.webtest.steps.Step;
09:
10: /**
11: * Base class for WebTest exceptions.
12: * @author Marc Guillemot
13: */
14: public class WebTestException extends BuildException {
15: private Step fFailedStep;
16: private final List details = new ArrayList();
17: private final String fShortMessage;
18:
19: protected WebTestException(final String message,
20: final Throwable cause) {
21: super (message, cause);
22: fShortMessage = message;
23: }
24:
25: /**
26: * @param failedStep may only be null for testing purposes *
27: */
28: protected WebTestException(final String message,
29: final Step failedStep, final Throwable cause) {
30: this (message, cause);
31: fFailedStep = failedStep;
32: }
33:
34: /**
35: * @param failedStep may only be null for testing purposes *
36: */
37: protected WebTestException(final String message,
38: final Step failedStep) {
39: this (message, failedStep, null);
40: }
41:
42: /**
43: * @param failedStep may only be null for testing purposes *
44: */
45: protected WebTestException(final String shortMessage,
46: final String messageEnd, final Step failedStep) {
47: super (shortMessage + messageEnd);
48: fShortMessage = shortMessage;
49: fFailedStep = failedStep;
50: }
51:
52: /**
53: * Gets details of the exception
54: * @return a list of {@link NameValuePair}
55: */
56: public List getDetails() {
57: return details;
58: }
59:
60: public void addDetail(final String name, final String value) {
61: details.add(new NameValuePair(name, value));
62: }
63:
64: /**
65: * Gets the short form of the message. This is what will be displayed as
66: * error cause in the report. The detailed information from {@link #getDetails()}
67: * receives a special formatting. This may be the same than {@link #getMessage()} when for instance
68: * no detail information is available.
69: * @return the short message
70: */
71: public String getShortMessage() {
72: return fShortMessage;
73: }
74:
75: public String toString() {
76: if (fFailedStep == null) {
77: return super .toString();
78: } else {
79: return super .toString() + ", Step: "
80: + fFailedStep.toString();
81: }
82: }
83: }
|