1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.result;
20
21 import net.sf.jameleon.util.JameleonUtility;
22
23 /***
24 * An implementation of the @see TestResult that represents an HttpRequest. This class keeps track of the resource requested, the function
25 * that requested it and the status code returned by the resource.
26 */
27 public class HttpRequestResult{
28
29 /***
30 * The id of the tag that created this result
31 */
32 protected String functionId;
33 /***
34 * The url requested
35 */
36 protected String url;
37 /***
38 * The execution time
39 */
40 protected long executionTime;
41 /***
42 * THe status returned by the response
43 */
44 protected int statusCode;
45
46 /***
47 * Constructor
48 * @param url - the url requested.
49 * @param executionTime - the time taken to return a response.
50 * @param statusCode - the status code returned by the request.
51 * @param functionId - the id of the function point that requested the url.
52 * @param testCaseName - the name of the test case that contained the function point that requested the url.
53 */
54 public HttpRequestResult(String url, long executionTime, int statusCode, String functionId){
55 this.url = url;
56 this.executionTime = executionTime;
57 this.statusCode = statusCode;
58 this.functionId = functionId;
59 }
60
61 /***
62 * Sets the url requested
63 * @param url - the url requested.
64 */
65 public void setUrl(String url){
66 this.url = url;
67 }
68
69 /***
70 * Sets the status code returned by the url requested.
71 * @param statusCode the status code returned by the url requested.
72 */
73 public void setStatusCode(int statusCode){
74 this.statusCode = statusCode;
75 }
76
77 /***
78 * @return a String representation of the url results.
79 */
80 public String toString(){
81 StringBuffer sb = new StringBuffer();
82 sb.append("Function ID: ").append(functionId).append("\n");
83 sb.append("Requested URL: ").append(url).append("\n");
84 sb.append("Resposne Time: ").append(JameleonUtility.executionTimeToString(executionTime)).append("\n");
85 sb.append("Response Code: ").append(new Integer(statusCode)).append("\n");
86 return sb.toString();
87 }
88
89 /***
90 * @return an XML representation of the results.
91 */
92 public String toXML(){
93 StringBuffer str = new StringBuffer("\n\t");
94 str.append("<http-request>\n");
95 str.append("\t\t<functionId>").append(functionId).append("</functionId>\n");
96 str.append("\t\t<requested-url>").append(escapeXML(url)).append("</requested-url>\n");
97 str.append("\t\t<response-time>").append(JameleonUtility.executionTimeToString(executionTime)).append("</response-time>\n");
98 str.append("\t\t<response-code>").append(new Long(statusCode)).append("</response-code>\n");
99 str.append("\t</http-request>\n");
100 return str.toString();
101 }
102
103
104
105
106 protected String escapeXML(String text) {
107 String result = text;
108 if (result == null) {
109 result = "<null>";
110 }else{
111 result = result.replaceAll("<","<");
112 result = result.replaceAll(">",">");
113 result = result.replaceAll("&","&");
114 }
115 return result;
116 }
117
118 }