Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 74875 invoked from network); 23 Jul 2002 14:39:23 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 23 Jul 2002 14:39:23 -0000 Received: (qmail 29941 invoked by uid 97); 23 Jul 2002 14:39:38 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 29900 invoked by uid 97); 23 Jul 2002 14:39:37 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 29889 invoked by uid 97); 23 Jul 2002 14:39:37 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 23 Jul 2002 14:39:15 -0000 Message-ID: <20020723143915.5451.qmail@icarus.apache.org> From: dion@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestExternalHost.java TestHttps.java TestMethodsExternalHost.java TestMethodsNoHost.java TestWebappMethods.java TestWebappRedirect.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N dion 2002/07/23 07:39:15 Modified: httpclient/src/test/org/apache/commons/httpclient TestExternalHost.java TestHttps.java TestMethodsExternalHost.java TestMethodsNoHost.java TestWebappMethods.java TestWebappRedirect.java Log: Proxy authorisation patches submitted by Ortwin Gluck Revision Changes Path 1.3 +14 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestExternalHost.java Index: TestExternalHost.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestExternalHost.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestExternalHost.java 4 Oct 2001 17:49:13 -0000 1.2 +++ TestExternalHost.java 23 Jul 2002 14:39:14 -0000 1.3 @@ -68,7 +68,17 @@ * A suite composed of only those tests which * require an external Internet connection. * + * Optionally this test can be run using a proxy. If the proxy is not + * authenticating do not set user / password. + * + * System properties: + * httpclient.test.proxyHost - proxy host name + * httpclient.test.proxyPort - proxy port + * httpclient.test.proxyUser - proxy auth username + * httpclient.test.proxyPass - proxy auth password + * * @author Rodney Waldhoff + * @author Ortwin Gl�ck * @version $Id$ */ public class TestExternalHost extends TestCase { 1.5 +33 -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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestHttps.java 4 Feb 2002 15:26:43 -0000 1.4 +++ TestHttps.java 23 Jul 2002 14:39:14 -0000 1.5 @@ -78,6 +78,7 @@ * (see build.xml) * * @author Rodney Waldhoff + * @author Ortwin Gl�ck * @version $Id$ */ public class TestHttps extends TestCase { @@ -85,6 +86,10 @@ // ---------------------------------------------------------------- Members private URL _urlWithPort = null; private URL _urlWithoutPort = null; + private final String PROXY_HOST = System.getProperty("httpclient.test.proxyHost"); + private final String PROXY_PORT = System.getProperty("httpclient.test.proxyPort"); + private final String PROXY_USER = System.getProperty("httpclient.test.proxyUser"); + private final String PROXY_PASS = System.getProperty("httpclient.test.proxyPass"); // ------------------------------------------------------------ Constructor public TestHttps(String testName) { @@ -109,7 +114,19 @@ public void testHttpsGet() { HttpClient client = new HttpClient(); + if (PROXY_HOST == null) { client.startSession(_urlWithPort); + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(_urlWithPort.getHost(), _urlWithPort.getPort(), + PROXY_HOST, + Integer.parseInt(PROXY_PORT), + true); + } GetMethod method = new GetMethod("/"); method.setUseDisk(false); try { @@ -131,7 +148,19 @@ public void testHttpsGetNoPort() { HttpClient client = new HttpClient(); + if (PROXY_HOST == null) { client.startSession(_urlWithoutPort); + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(_urlWithoutPort.getHost(), 443, + PROXY_HOST, + Integer.parseInt(PROXY_PORT), + true); + } GetMethod method = new GetMethod("/"); method.setUseDisk(false); try { 1.4 +54 -8 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java Index: TestMethodsExternalHost.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsExternalHost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestMethodsExternalHost.java 4 Feb 2002 15:26:43 -0000 1.3 +++ TestMethodsExternalHost.java 23 Jul 2002 14:39:14 -0000 1.4 @@ -75,6 +75,7 @@ * * @author Remy Maucherat * @author Rodney Waldhoff + * @author Ortwin Gl�ck * @version $Id$ */ public class TestMethodsExternalHost extends TestCase { @@ -85,6 +86,10 @@ private static final String externalHost = "java.sun.com"; private static final int externalPort = 80; private static final String externalPath = "/index.html"; + private final String PROXY_HOST = System.getProperty("httpclient.test.proxyHost"); + private final String PROXY_PORT = System.getProperty("httpclient.test.proxyPort"); + private final String PROXY_USER = System.getProperty("httpclient.test.proxyUser"); + private final String PROXY_PASS = System.getProperty("httpclient.test.proxyPass"); // ------------------------------------------------------------ Constructor @@ -113,6 +118,17 @@ try { client.startSession(externalHost, externalPort); + if (PROXY_HOST == null) { + client.startSession(externalHost, externalPort); + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(externalHost, externalPort, + PROXY_HOST, Integer.parseInt(PROXY_PORT), false); + } client.executeMethod(method); } catch (Throwable t) { t.printStackTrace(); @@ -133,8 +149,17 @@ public void testMethodsGetExternal() { HttpClient client = new HttpClient(); + if (PROXY_HOST == null) { client.startSession(externalHost, externalPort); - + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(externalHost, externalPort, + PROXY_HOST, Integer.parseInt(PROXY_PORT), false); + } GetMethod method = new GetMethod("/"); method.setUseDisk(false); @@ -184,8 +209,17 @@ public void testMethodsHeadExternal() { HttpClient client = new HttpClient(); + if (PROXY_HOST == null) { client.startSession(externalHost, externalPort); - + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(externalHost, externalPort, + PROXY_HOST, Integer.parseInt(PROXY_PORT), false); + } HeadMethod method = new HeadMethod(externalPath); try { @@ -207,12 +241,24 @@ public void testIOException() { HttpClient client = new HttpClient(); - client.startSession("http://whaturl.com.org", externalPort); - + String host = "whaturl.com.org"; + int port = 80; + if (PROXY_HOST == null) { + client.startSession(host, port); + } else { + if (PROXY_USER != null) { + HttpState state = client.getState(); + state.setProxyCredentials(null, new UsernamePasswordCredentials( + PROXY_USER, PROXY_PASS)); + } + client.startSession(host, port, + PROXY_HOST, Integer.parseInt(PROXY_PORT), false); + } GetMethod method = new GetMethod(""); try { client.executeMethod(method); + if ((PROXY_HOST != null) && (method.getStatusCode() >= 400)) return; } catch (IOException e) { return; // good } catch (HttpException e) { 1.4 +15 -10 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java Index: TestMethodsNoHost.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestMethodsNoHost.java 10 Jul 2002 11:33:40 -0000 1.3 +++ TestMethodsNoHost.java 23 Jul 2002 14:39:14 -0000 1.4 @@ -62,7 +62,10 @@ package org.apache.commons.httpclient; -import junit.framework.*; +import java.io.IOException; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; import org.apache.commons.httpclient.methods.*; /** @@ -182,16 +185,18 @@ assertEquals(pairs[0], pairs[1]); } - public void testPostParametersEncoding(){ + public void testPostParametersEncoding() throws IOException { PostMethod post = new PostMethod(); post.addParameter(PAIR); - assertEquals("name=value", post.getRequestBody()); + assertEquals("name=value", post.getRequestBodyAsString()); post.addParameters(new NameValuePair[]{ PAIR1, PAIR2 }); - assertEquals("name=value&name1=value1&name2=value2", post.getRequestBody()); + assertEquals("name=value&name1=value1&name2=value2", + post.getRequestBodyAsString()); post.addParameter("hasSpace", "a b c d"); - assertEquals("name=value&name1=value1&name2=value2&hasSpace=a+b+c+d", post.getRequestBody()); + assertEquals("name=value&name1=value1&name2=value2&hasSpace=a+b+c+d", + post.getRequestBodyAsString()); } @@ -199,7 +204,7 @@ PostMethod post = new PostMethod("/foo"); String body = "this+is+the+body"; post.setRequestBody(body); - assertEquals(body, post.getRequestBody()); + assertEquals(body, post.getRequestBodyAsString()); } 1.5 +66 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java Index: TestWebappMethods.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestWebappMethods.java 24 Apr 2002 14:44:50 -0000 1.4 +++ TestWebappMethods.java 23 Jul 2002 14:39:14 -0000 1.5 @@ -62,6 +62,7 @@ package org.apache.commons.httpclient; +import java.io.ByteArrayInputStream; import junit.framework.*; import org.apache.commons.httpclient.methods.*; @@ -82,6 +83,7 @@ * "httpclient.test.webappContext" property. * * @author Rodney Waldhoff + * @author Ortwin Gl�ck * @version $Id$ */ public class TestWebappMethods extends TestWebappBase { @@ -322,6 +324,66 @@ assertTrue(method.getResponseBodyAsString().indexOf("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.") >= 0); assertEquals(200,method.getStatusCode()); } + + + public void testPostBodyCustomLength() throws Exception { + HttpClient client = new HttpClient(); + client.startSession(host, port); + PostMethod method = new PostMethod("/" + context + "/body"); + method.setUseDisk(false); + String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times."; + method.setRequestBody(new ByteArrayInputStream(body.getBytes())); + method.setRequestContentLength(body.length()); + try { + client.executeMethod(method); + } catch (Throwable t) { + t.printStackTrace(); + fail("Unable to execute method : " + t.toString()); + } + assertTrue(method.getResponseBodyAsString().indexOf("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.") >= 0); + assertEquals(200,method.getStatusCode()); + } + + + public void testPostBodyAutoLength() throws Exception { + HttpClient client = new HttpClient(); + client.startSession(host, port); + PostMethod method = new PostMethod("/" + context + "/body"); + method.setUseDisk(false); + String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times."; + method.setRequestBody(new ByteArrayInputStream(body.getBytes())); + method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); + try { + client.executeMethod(method); + } catch (Throwable t) { + t.printStackTrace(); + fail("Unable to execute method : " + t.toString()); + } + assertTrue(method.getResponseBodyAsString().indexOf("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.") >= 0); + assertEquals(200,method.getStatusCode()); + } + + /* + //enable this when chunked requests are properly implemented + //note: only few servers support this + public void testPostBodyChunked() throws Exception { + HttpClient client = new HttpClient(); + client.startSession(host, port); + PostMethod method = new PostMethod("/" + context + "/body"); + method.setUseDisk(false); + String body = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times."; + method.setRequestBody(new ByteArrayInputStream(body.getBytes())); + method.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED); + try { + client.executeMethod(method); + } catch (Throwable t) { + t.printStackTrace(); + fail("Unable to execute method : " + t.toString()); + } + assertTrue(method.getResponseBodyAsString().indexOf("quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.") >= 0); + assertEquals(200,method.getStatusCode()); + } + */ public void testPutBody() throws Exception { HttpClient client = new HttpClient(); 1.5 +6 -11 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java Index: TestWebappRedirect.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestWebappRedirect.java 4 Feb 2002 15:26:43 -0000 1.4 +++ TestWebappRedirect.java 23 Jul 2002 14:39:14 -0000 1.5 @@ -206,11 +206,7 @@ t.printStackTrace(); fail("Unable to execute method : " + t.toString()); } - assertEquals(200,method.getStatusCode()); - assertTrue(method.getResponseBodyAsString().indexOf("Param Servlet: POST") >= 0); - assertTrue(method.getResponseBodyAsString().indexOf("

QueryString=\"foo=bar&bar=foo\"

") >= 0); - assertTrue(method.getResponseBodyAsString().indexOf("name=\"para\";value=\"meter\"") >= 0); - assertTrue(method.getResponseBodyAsString().indexOf("name=\"param\";value=\"eter\"") >= 0); + assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode()); } public void testPutRedirect() throws Exception { @@ -226,8 +222,7 @@ t.printStackTrace(); fail("Unable to execute method : " + t.toString()); } - assertTrue(method.getResponseBodyAsString(),method.getResponseBodyAsString().indexOf("This is data to be sent in the body of an HTTP PUT.") >= 0); - assertEquals(200,method.getStatusCode()); + assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode()); } } -- To unsubscribe, e-mail: For additional commands, e-mail: