Author: markt
Date: Thu Jul 30 18:10:35 2009
New Revision: 799392
URL: http://svn.apache.org/viewvc?rev=799392&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47569
Use the new base class so tests clean up after themselves
Modified:
tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java
tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
Modified: tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java?rev=799392&r1=799391&r2=799392&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestRequest.java Thu Jul 30
18:10:35 2009
@@ -38,14 +38,23 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.startup.TestTomcatBase;
import org.apache.catalina.startup.Tomcat;
-import junit.framework.TestCase;
-
/**
* Test case for {...@link Request}.
*/
-public class TestRequest extends TestCase {
+public class TestRequest extends TestTomcatBase {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
/**
* Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=37794
* POST parameters are not returned from a call to
@@ -54,6 +63,7 @@
*/
public void testBug37794() throws Exception {
Bug37794Client client = new Bug37794Client();
+ client.setPort(getPort());
// Edge cases around zero
client.doRequest(-1, false); // Unlimited
@@ -97,6 +107,8 @@
private static class Bug37794Servlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
/**
* Only interested in the parameters and values for POST requests.
*/
@@ -120,15 +132,28 @@
/**
* Bug 37794 test client.
*/
- private static class Bug37794Client extends SimpleHttpClient {
+ private class Bug37794Client extends SimpleHttpClient {
+
+ private boolean init;
+
+ private synchronized void init() throws Exception {
+ if (init) return;
+
+ Tomcat tomcat = getTomcatInstance();
+ StandardContext root = tomcat.addContext("", TEMP_DIR);
+ Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
+ root.addServletMapping("/test", "Bug37794");
+ tomcat.start();
+
+ init = true;
+ }
+
private Exception doRequest(int postLimit, boolean ucChunkedHead) {
- Tomcat tomcat = new Tomcat();
+ Tomcat tomcat = getTomcatInstance();
+
try {
- StandardContext root = tomcat.addContext("", TEMP_DIR);
- Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
- root.addServletMapping("/test", "Bug37794");
+ init();
tomcat.getConnector().setMaxPostSize(postLimit);
- tomcat.start();
// Open connection
connect();
@@ -167,12 +192,6 @@
disconnect();
} catch (Exception e) {
return e;
- } finally {
- try {
- tomcat.stop();
- } catch (Exception e) {
- // Ignore
- }
}
return null;
}
@@ -209,6 +228,7 @@
private Socket socket;
private Writer writer;
private BufferedReader reader;
+ private int port = 8080;
private String[] request;
private int requestPause = 1000;
@@ -217,6 +237,10 @@
private List<String> responseHeaders = new ArrayList<String>();
private String responseBody;
+ public void setPort(int thePort) {
+ port = thePort;
+ }
+
public void setRequest(String[] theRequest) {
request = theRequest;
}
@@ -238,7 +262,7 @@
}
public void connect() throws UnknownHostException, IOException {
- socket = new Socket("localhost", 8080);
+ socket = new Socket("localhost", port);
OutputStream os = socket.getOutputStream();
writer = new OutputStreamWriter(os);
InputStream is = socket.getInputStream();
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=799392&r1=799391&r2=799392&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Thu Jul 30
18:10:35 2009
@@ -29,19 +29,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import junit.framework.TestCase;
-
import org.apache.catalina.core.StandardContext;
import org.apache.tomcat.util.buf.ByteChunk;
-public class TestTomcat extends TestCase {
- Tomcat tomcat;
- // if you run in eclipse - or tomcat src dir
- String base = "./";
- File tempDir;
- static int port = 8001;
- long t0;
-
+public class TestTomcat extends TestTomcatBase {
+
/**
* Simple servlet to test in-line registration
*/
@@ -55,28 +47,6 @@
}
}
- public void setUp() throws Exception {
- t0 = System.currentTimeMillis();
- tempDir = new File(base + "output/tmp");
- tempDir.mkdir();
-
- tomcat = new Tomcat();
- tomcat.setBaseDir(tempDir.getAbsolutePath());
- tomcat.getHost().setAppBase(tempDir.getAbsolutePath() + "/webapps");
-
- // If each test is running on same port - they
- // may interfere with each other (on unix at least)
- port++;
- tomcat.setPort(port);
- }
-
- public void tearDown() throws Exception {
- tomcat.stop();
- System.err.println("Test time: " +
- (System.currentTimeMillis() - t0));
- ExpandWar.delete(tempDir);
- }
-
/**
* Start tomcat with a single context and one
* servlet - all programmatic, no server.xml or
@@ -85,10 +55,11 @@
* @throws Exception
*/
public void testProgrammatic() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ // Must have a real docBase - just use temp
StandardContext ctx =
- tomcat.addContext("/",
- tempDir.getAbsolutePath());
+ tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
// You can customize the context by calling
// its API
@@ -97,27 +68,34 @@
tomcat.start();
- ByteChunk res = getUrl("http://localhost:" + port + "/");
+ ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
assertEquals(res.toString(), "Hello world");
}
public void testSingleWebapp() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
// Currently in sandbox/tomcat-lite
File appDir =
- new File(base + "output/build/webapps/examples");
+ new File("output/build/webapps/examples");
// app dir is relative to server home
tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
tomcat.start();
- ByteChunk res = getUrl("http://localhost:" + port +
"/examples/servlets/servlet/HelloWorldExample");
+ ByteChunk res = getUrl("http://localhost:" + getPort() +
+ "/examples/servlets/servlet/HelloWorldExample");
assertTrue(res.toString().indexOf("<h1>Hello World!</h1>") > 0);
}
public void testLaunchTime() throws Exception {
- tomcat.addContext(null, "/", base);
+ Tomcat tomcat = getTomcatInstance();
+ long t0 = System.currentTimeMillis();
+ tomcat.addContext(null, "/", ".");
tomcat.start();
- }
+ System.err.println("Test time: " +
+ (System.currentTimeMillis() - t0));
+ }
/**
* Wrapper for getting the response.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]