1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.server.runner;
|
3
|
|
import java.io.PrintWriter;
|
4
|
|
import java.io.IOException;
|
5
|
|
import javax.servlet.http.HttpServlet;
|
6
|
|
import javax.servlet.http.HttpServletRequest;
|
7
|
|
import javax.servlet.http.HttpServletResponse;
|
8
|
|
import javax.servlet.ServletException;
|
9
|
|
import org.apache.cactus.util.Configuration;
|
10
|
|
import junit.framework.TestResult;
|
11
|
|
import junit.framework.Test;
|
12
|
|
|
13
|
|
/**
|
14
|
|
* Helper servlet to start a JUnit Test Runner in a webapp.
|
15
|
|
*
|
16
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
17
|
|
*
|
18
|
|
* @version $Id: ServletTestRunner.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $
|
19
|
|
*/
|
20
|
|
public class ServletTestRunner extends HttpServlet {
|
21
|
|
/**
|
22
|
|
* HTTP parameter containing name of test suite to execute
|
23
|
|
*/
|
24
|
|
private static final String HTTP_SUITE_PARAM = "suite";
|
25
|
|
/**
|
26
|
|
* HTTP parameter containing name of the XSL stylesheet to put in the
|
27
|
|
* returned XML test result. It will only work if the browser supports
|
28
|
|
* this feature (IE does, I don't know about others).
|
29
|
|
*/
|
30
|
|
private static final String HTTP_XSL_PARAM = "xsl";
|
31
|
|
/**
|
32
|
|
* Starts the test suite passed as a HTTP parameter
|
33
|
|
*
|
34
|
|
* @param theRequest the incoming HTTP client request
|
35
|
|
* @param theResponse the outgoing HTTP client request to send back.
|
36
|
|
*
|
37
|
|
* @exception ServletException if an error occurs when servicing the
|
38
|
|
* request
|
39
|
|
* @exception IOException if an error occurs when servicing the request
|
40
|
|
*/
|
41
|
0
|
public void doGet(HttpServletRequest theRequest,
|
42
|
|
HttpServletResponse theResponse) throws ServletException, IOException {
|
43
|
0
|
String suiteClassName = theRequest.getParameter("suite");
|
44
|
0
|
if (suiteClassName == null) {
|
45
|
0
|
throw new ServletException("Missing HTTP parameter [suite] in request");
|
46
|
|
}
|
47
|
0
|
String xslParam = theRequest.getParameter("xsl");
|
48
|
0
|
System.setProperty("cactus.contextURL",
|
49
|
|
"http://" + theRequest.getServerName() + ":" + theRequest.getServerPort() +
|
50
|
|
theRequest.getContextPath());
|
51
|
0
|
String xml = this.run(suiteClassName, xslParam);
|
52
|
0
|
theResponse.setContentType("text/xml");
|
53
|
0
|
PrintWriter pw = theResponse.getWriter();
|
54
|
0
|
pw.println(xml);
|
55
|
|
}
|
56
|
|
|
57
|
|
/**
|
58
|
|
* Run the suite tests and return the result.
|
59
|
|
*
|
60
|
|
* @param theSuiteClassName the suite containing the tests to run
|
61
|
|
* @param theXslFileName the name of the XSL stylesheet or null if we don't
|
62
|
|
* want to apply a stylesheet to the returned XML data
|
63
|
|
* @return the result object
|
64
|
|
* @exception ServletException if the suite failed to be loaded
|
65
|
|
*/
|
66
|
0
|
public String run(String theSuiteClassName, String theXslFileName) throws ServletException {
|
67
|
0
|
TestResult result = new TestResult();
|
68
|
0
|
XMLFormatter formatter = new XMLFormatter();
|
69
|
0
|
formatter.setXslFileName(theXslFileName);
|
70
|
0
|
formatter.setSuiteClassName(theSuiteClassName);
|
71
|
0
|
result.addListener(formatter);
|
72
|
0
|
long startTime = System.currentTimeMillis();
|
73
|
0
|
WebappTestRunner testRunner = new WebappTestRunner();
|
74
|
0
|
Test suite = testRunner.getTest(theSuiteClassName);
|
75
|
0
|
if (suite == null) {
|
76
|
0
|
throw new ServletException("Failed to load test suite [" + theSuiteClassName +
|
77
|
|
"], Reason is [" + testRunner.getErrorMessage() + "]");
|
78
|
|
}
|
79
|
0
|
suite.run(result);
|
80
|
0
|
long endTime = System.currentTimeMillis();
|
81
|
0
|
formatter.setTotalDuration(endTime - startTime);
|
82
|
0
|
return formatter.toXML(result);
|
83
|
|
}
|
84
|
|
|
85
|
|
/**
|
86
|
|
* Helper servlet to start a JUnit Test Runner in a webapp.
|
87
|
|
*
|
88
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
89
|
|
*
|
90
|
|
* @version $Id: ServletTestRunner.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $
|
91
|
|
*/
|
92
|
0
|
public ServletTestRunner() {
|
93
|
0
|
super();
|
94
|
|
}
|
95
|
|
}
|