rwaldhoff 01/07/27 15:52:25 Modified: httpclient/src/test/org/apache/commons/httpclient TestAll.java TestHttps.java TestMethods.java Added: httpclient/src/test/org/apache/commons/httpclient TestAllExternal.java TestAllLocal.java TestMethodsExternalHost.java TestMethodsLocalHost.java Log: refactored to seperate locahost from external-host test Revision Changes Path 1.4 +5 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java Index: TestAll.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestAll.java 2001/05/17 23:58:51 1.3 +++ TestAll.java 2001/07/27 22:52:25 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v 1.3 2001/05/17 23:58:51 rwaldhoff Exp $ - * $Revision: 1.3 $ - * $Date: 2001/05/17 23:58:51 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v 1.4 2001/07/27 22:52:25 rwaldhoff Exp $ + * $Revision: 1.4 $ + * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * @@ -65,7 +65,8 @@ /** * @author Remy Maucherat - * @version $Id: TestAll.java,v 1.3 2001/05/17 23:58:51 rwaldhoff Exp $ + * @author Rodney Waldhoff + * @version $Id: TestAll.java,v 1.4 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestAll extends TestCase { 1.2 +5 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java Index: TestHttps.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestHttps.java 2001/05/17 23:58:51 1.1 +++ TestHttps.java 2001/07/27 22:52:25 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java,v 1.1 2001/05/17 23:58:51 rwaldhoff Exp $ - * $Revision: 1.1 $ - * $Date: 2001/05/17 23:58:51 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java,v 1.2 2001/07/27 22:52:25 rwaldhoff Exp $ + * $Revision: 1.2 $ + * $Date: 2001/07/27 22:52:25 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -28,9 +28,10 @@ * (see build.xml) * * @author Rodney Waldhoff - * @version $Id: TestHttps.java,v 1.1 2001/05/17 23:58:51 rwaldhoff Exp $ + * @version $Id: TestHttps.java,v 1.2 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestHttps extends TestCase { + // ---------------------------------------------------------------- Members private URL _urlWithPort = null; private URL _urlWithoutPort = null; 1.6 +14 -224 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java Index: TestMethods.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TestMethods.java 2001/05/19 22:38:29 1.5 +++ TestMethods.java 2001/07/27 22:52:25 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v 1.5 2001/05/19 22:38:29 remm Exp $ - * $Revision: 1.5 $ - * $Date: 2001/05/19 22:38:29 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethods.java,v 1.6 2001/07/27 22:52:25 rwaldhoff Exp $ + * $Revision: 1.6 $ + * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * @@ -67,238 +67,28 @@ import org.apache.commons.httpclient.methods.*; /** - * Simple tests for the HTTP client. This test assumes the default - * configuration of Tomcat 4 is used as the server. + * A test-suite encompassing TestMethodsLocalHost and + * TestMethodsExtenralHost. * * @author Remy Maucherat - * @version $Id: TestMethods.java,v 1.5 2001/05/19 22:38:29 remm Exp $ + * @author Rodney Waldhoff + * @version $Id: TestMethods.java,v 1.6 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestMethods extends TestCase { - - // -------------------------------------------------------------- Constants - - - private static final String host = "127.0.0.1"; - private static final int port = 8080; - - // XXX fix me - // java.sun.com fails for some reason. We should figure out why, - // but in the interest of having a working test suite, - // I changed externalHost to jakarta instead. - private static final String externalHost = "java.sun.com"; - //private static final String externalHost = "jakarta.apache.org"; - private static final int externalPort = 80; - private static final String externalPath = "/index.html"; - - // ------------------------------------------------------------ Constructor - - public TestMethods(String testName) { super(testName); } - - // ------------------------------------------------------- TestCase Methods - - public static Test suite() { - return new TestSuite(TestMethods.class); + TestSuite suite = new TestSuite(); + suite.addTest(TestMethodsLocalHost.suite()); + suite.addTest(TestMethodsExternalHost.suite()); + return suite; } - - - // ----------------------------------------------------------- OPTIONS Test - - - public void testMethodsOptions() { - - HttpClient client = new HttpClient(); - OptionsMethod method = new OptionsMethod("/"); - try { - client.startSession(host, port); - client.executeMethod(method); - } catch (Throwable t) { - t.printStackTrace(); - fail("Unable to execute method : " + t.toString()); - } - - Enumeration methodsAllowed = method.getAllowedMethods(); - // This enumeration musn't be empty - assert("No HTTP method allowed : result of OPTIONS is incorrect.", - methodsAllowed.hasMoreElements()); - + public static void main(String args[]) { + String[] testCaseName = { TestMethods.class.getName() }; + junit.textui.TestRunner.main(testCaseName); } - - - public void testMethodsOptionsExternal() { - - HttpClient client = new HttpClient(); - client.startSession(externalHost, externalPort); - OptionsMethod method = new OptionsMethod(externalPath); - - try { - client.startSession(host, port); - client.executeMethod(method); - } catch (Throwable t) { - t.printStackTrace(); - fail("Unable to execute method : " + t.toString()); - } - - Enumeration methodsAllowed = method.getAllowedMethods(); - // This enumeration musn't be empty - assert("No HTTP method allowed : result of OPTIONS is incorrect.", - 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)); - - } - - public void testMethodsHeadExternal() { - - HttpClient client = new HttpClient(); - client.startSession(externalHost, externalPort); - - HeadMethod method = new HeadMethod(externalPath); - - try { - client.executeMethod(method); - } catch (Throwable t) { - t.printStackTrace(); - fail("Unable to execute method : " + t.toString()); - } - - assert("Method failed : " + method.getStatusCode(), - (method.getStatusCode() == 200)); - - } - - /** - * This test proves that bad urls throw an IOException, - * and not some other throwable like a NullPointerException. - */ - public void testIOException() { - - HttpClient client = new HttpClient(); - client.startSession("http://whaturl.com.org", externalPort); - - GetMethod method = new GetMethod(""); - - try { - client.executeMethod(method); - } catch (IOException e) { - return; // good - } catch (HttpException e) { - return; // also good - } - - fail("Should have thrown an exception"); - - } - - } 1.1 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAllExternal.java Index: TestAllExternal.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAllExternal.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ * $Revision: 1.1 $ * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.httpclient; import junit.framework.*; /** * @author Rodney Waldhoff * @version $Id: TestAllExternal.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestAllExternal extends TestCase { public TestAllExternal(String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(TestMethodsExternalHost.suite()); suite.addTest(TestCookie.suite()); suite.addTest(TestHttps.suite()); return suite; } public static void main(String args[]) { String[] testCaseName = { TestAllExternal.class.getName() }; junit.textui.TestRunner.main(testCaseName); } } 1.1 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAllLocal.java Index: TestAllLocal.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAllLocal.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ * $Revision: 1.1 $ * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.httpclient; import junit.framework.*; /** * @author Rodney Waldhoff * @version $Id: TestAllLocal.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestAllLocal extends TestCase { public TestAllLocal(String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(TestMethodsLocalHost.suite()); suite.addTest(TestCookie.suite()); return suite; } public static void main(String args[]) { String[] testCaseName = { TestAllLocal.class.getName() }; junit.textui.TestRunner.main(testCaseName); } } 1.1 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java Index: TestMethodsExternalHost.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ * $Revision: 1.1 $ * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.httpclient; import java.io.IOException; import java.util.Enumeration; import junit.framework.*; import org.apache.commons.httpclient.methods.*; /** * Simple tests for the HTTP client hitting an external webserver. * * This test suite assumes you have an internet connection that * can communicate with http://java.sun.com/. * * @author Remy Maucherat * @author Rodney Waldhoff * @version $Id: TestMethodsExternalHost.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestMethodsExternalHost extends TestCase { // -------------------------------------------------------------- Constants private static final String externalHost = "java.sun.com"; private static final int externalPort = 80; private static final String externalPath = "/index.html"; // ------------------------------------------------------------ Constructor public TestMethodsExternalHost(String testName) { super(testName); } // ------------------------------------------------------- TestCase Methods public static Test suite() { return new TestSuite(TestMethodsExternalHost.class); } // ----------------------------------------------------------- OPTIONS Test public void testMethodsOptionsExternal() { HttpClient client = new HttpClient(); client.startSession(externalHost, externalPort); OptionsMethod method = new OptionsMethod(externalPath); try { client.startSession(externalHost, externalPort); client.executeMethod(method); } catch (Throwable t) { t.printStackTrace(); fail("Unable to execute method : " + t.toString()); } Enumeration methodsAllowed = method.getAllowedMethods(); // This enumeration musn't be empty assert("No HTTP method allowed : result of OPTIONS is incorrect.", methodsAllowed.hasMoreElements()); } // --------------------------------------------------------------- GET Test public void testMethodsGetExternal() { HttpClient client = new HttpClient(); client.startSession(externalHost, externalPort); 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(externalPath); 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 testMethodsHeadExternal() { HttpClient client = new HttpClient(); client.startSession(externalHost, externalPort); HeadMethod method = new HeadMethod(externalPath); try { client.executeMethod(method); } catch (Throwable t) { t.printStackTrace(); fail("Unable to execute method : " + t.toString()); } assert("Method failed : " + method.getStatusCode(), (method.getStatusCode() == 200)); } /** * This test proves that bad urls throw an IOException, * and not some other throwable like a NullPointerException. */ public void testIOException() { HttpClient client = new HttpClient(); client.startSession("http://whaturl.com.org", externalPort); GetMethod method = new GetMethod(""); try { client.executeMethod(method); } catch (IOException e) { return; // good } catch (HttpException e) { return; // also good } fail("Should have thrown an exception"); } } 1.1 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java Index: TestMethodsLocalHost.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ * $Revision: 1.1 $ * $Date: 2001/07/27 22:52:25 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.httpclient; import java.io.IOException; import java.util.Enumeration; import junit.framework.*; import org.apache.commons.httpclient.methods.*; /** * Simple tests for the HTTP client hitting a local webserver. * * This test assumes a webserver is running on port 8080 on * the 127.0.0.1. * * The default configuration of Tomcat 4 will work fine. * * Tomcat 3.x will fail the OPTIONS test, because it * treats OPTIONS as a GET request. * * @author Remy Maucherat * @author Rodney Waldhoff * @version $Id: TestMethodsLocalHost.java,v 1.1 2001/07/27 22:52:25 rwaldhoff Exp $ */ public class TestMethodsLocalHost extends TestCase { // -------------------------------------------------------------- Constants private static final String host = "127.0.0.1"; private static final int port = 8080; // ------------------------------------------------------------ Constructor public TestMethodsLocalHost(String testName) { super(testName); } // ------------------------------------------------------- TestCase Methods public static Test suite() { return new TestSuite(TestMethodsLocalHost.class); } // ----------------------------------------------------------- OPTIONS Test /** * This test assumes that the webserver listening * on host/port will respond properly to an OPTIONS * request. Tomcat 4 is one such web server, * but Tomcat 3.x is not. */ public void testMethodsOptions() { HttpClient client = new HttpClient(); OptionsMethod method = new OptionsMethod("/"); try { client.startSession(host, port); client.executeMethod(method); } catch (Throwable t) { t.printStackTrace(); fail("Unable to execute method : " + t.toString()); } Enumeration methodsAllowed = method.getAllowedMethods(); // This enumeration musn't be empty assert("No HTTP method allowed : result of OPTIONS is incorrect " + "(make sure the webserver running on port " + port + " supports OPTIONS properly)", 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)); } }