remm 01/04/22 23:51:54
Modified: httpclient/src/test/org/apache/commons/httpclient
TestMethods.java
Log:
- Add very basic tests for GET and HEAD. Some more specific test will require
deploying a custom web application, and this more advanced test suite
will be part of Tomcat 4.
Revision Changes Path
1.2 +128 -5
jakarta-commons-sandbox/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java
Index: TestMethods.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestMethods.java 2001/04/22 05:45:28 1.1
+++ TestMethods.java 2001/04/23 06:51:53 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v
1.1 2001/04/22 05:45:28 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/22 05:45:28 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v
1.2 2001/04/23 06:51:53 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/04/23 06:51:53 $
*
* ====================================================================
*
@@ -70,20 +70,36 @@
* configuration of Tomcat 4 is used as the server.
*
* @author Remy Maucherat
- * @version $Id: TestMethods.java,v 1.1 2001/04/22 05:45:28 remm Exp $
+ * @version $Id: TestMethods.java,v 1.2 2001/04/23 06:51:53 remm Exp $
*/
public class TestMethods extends TestCase {
+
+ // -------------------------------------------------------------- Constants
+
+
+ private static final String host = "127.0.0.1";
+ private static final int port = 8080;
+
+
+ // ------------------------------------------------------------ Constructor
+
+
public TestMethods(String testName) {
super(testName);
}
+
+ // ------------------------------------------------------- TestCase Methods
+
+
public static Test suite() {
return new TestSuite(TestMethods.class);
}
+
+
+ // ----------------------------------------------------------- OPTIONS Test
- private String host = "127.0.0.1";
- private int port = 8080;
public void testMethodsOptions() {
@@ -104,5 +120,112 @@
methodsAllowed.hasMoreElements());
}
+
+
+ // --------------------------------------------------------------- GET Test
+
+
+ public void testMethodsGet() {
+
+ HttpClient client = new HttpClient();
+ client.startSession(host, port);
+
+ OptionsMethod opmethod = new OptionsMethod("/");
+
+ try {
+ client.executeMethod(opmethod);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ GetMethod method = new GetMethod("/");
+ method.setUseDisk(false);
+
+ try {
+ client.executeMethod(method);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ try {
+ String data = method.getDataAsString();
+ // This enumeration musn't be empty
+ assert("No data returned.",
+ (data.length() > 0));
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ method.recycle();
+ method.setPath("/index.html");
+ method.setUseDisk(true);
+
+ try {
+ client.executeMethod(method);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ try {
+ String data = method.getDataAsString();
+ // This enumeration musn't be empty
+ assert("No data returned.",
+ (data.length() > 0));
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ }
+
+
+ // -------------------------------------------------------------- HEAD Test
+
+
+ public void testMethodsHead() {
+
+ HttpClient client = new HttpClient();
+ client.startSession(host, port);
+
+ OptionsMethod opmethod = new OptionsMethod("/");
+
+ try {
+ client.executeMethod(opmethod);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ HeadMethod method = new HeadMethod("/");
+
+ try {
+ client.executeMethod(method);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ assert("Method failed : " + method.getStatusCode(),
+ (method.getStatusCode() == 200));
+
+ method.recycle();
+ method.setPath("/index.html");
+
+ try {
+ client.executeMethod(method);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail("Unable to execute method : " + t.toString());
+ }
+
+ assert("Method failed : " + method.getStatusCode(),
+ (method.getStatusCode() == 200));
+
+ }
+
}