commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oglu...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestMethodsNoHost.java TestWebappMethods.java TestWebappParameters.java TestWebappRedirect.java
Date Mon, 21 Oct 2002 14:03:07 GMT
oglueck     2002/10/21 07:03:07

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestMethodsNoHost.java TestWebappMethods.java
                        TestWebappParameters.java TestWebappRedirect.java
  Log:
  fixed tests broken by recent modifcations to encoding
  added test for post redirects (buffered / unbufffered)
  
  Revision  Changes    Path
  1.10      +5 -5      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestMethodsNoHost.java	11 Oct 2002 13:03:34 -0000	1.9
  +++ TestMethodsNoHost.java	21 Oct 2002 14:03:07 -0000	1.10
  @@ -201,7 +201,7 @@
               post.getRequestBodyAsString());
   
           post.addParameter("hasSpace", "a b c d");
  -        assertEquals("name=value&name1=value1&name2=value2&hasSpace=a+b+c+d",

  +        assertEquals("name=value&name1=value1&name2=value2&hasSpace=a%20b%20c%20d",
               post.getRequestBodyAsString());
   
       }
  
  
  
  1.6       +5 -5      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestWebappMethods.java	23 Jul 2002 14:39:14 -0000	1.5
  +++ TestWebappMethods.java	21 Oct 2002 14:03:07 -0000	1.6
  @@ -305,8 +305,8 @@
               t.printStackTrace();
               fail("Unable to execute method : " + t.toString());
           }
  -        assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times.</tt>")
>= 0);
           assertEquals(200,method.getStatusCode());
  +        assertTrue(method.getResponseBodyAsString().indexOf("<tt>quote=It%20was%20the%20best%20of%20times,%20it%20was%20the%20worst%20of%20times.</tt>")
>= 0);
       }
   
       public void testPostBody() throws Exception {
  
  
  
  1.5       +5 -5      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappParameters.java
  
  Index: TestWebappParameters.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappParameters.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestWebappParameters.java	2 Sep 2002 14:52:48 -0000	1.4
  +++ TestWebappParameters.java	21 Oct 2002 14:03:07 -0000	1.5
  @@ -185,8 +185,8 @@
               t.printStackTrace();
               fail("Unable to execute method : " + t.toString());
           }
  -        assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet:
GET</title>") >= 0);
           assertEquals(200,method.getStatusCode());
  +        assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet:
GET</title>") >= 0);
           assertTrue(method.getResponseBodyAsString().indexOf("name=\"special-chars\";value=\":/?~.\"")
>= 0);
           assertTrue(method.getResponseBodyAsString().indexOf("name=\"param-one\";value=\"param-value\"")
>= 0);
           assertTrue(method.getResponseBodyAsString().indexOf("name=\"param-two\";value=\"param-value2\"")
>= 0);
  
  
  
  1.7       +47 -16    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestWebappRedirect.java	2 Sep 2002 14:52:48 -0000	1.6
  +++ TestWebappRedirect.java	21 Oct 2002 14:03:07 -0000	1.7
  @@ -62,9 +62,16 @@
   
   package org.apache.commons.httpclient;
   
  -import junit.framework.*;
  -import org.apache.commons.httpclient.methods.*;
  -import java.net.URLEncoder;
  +import java.io.ByteArrayInputStream;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.methods.PostMethod;
  +import org.apache.commons.httpclient.methods.PutMethod;
  +import org.apache.commons.httpclient.util.URIUtil;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   /**
    * This suite of tests depends upon the httpclienttest webapp,
  @@ -86,6 +93,7 @@
    * @version $Id$
    */
   public class TestWebappRedirect extends TestWebappBase {
  +    private static final Log log = LogFactory.getLog(TestWebappRedirect.class);
   
       public TestWebappRedirect(String testName) {
           super(testName);
  @@ -107,7 +115,7 @@
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           GetMethod method = new GetMethod("/" + context + "/redirect");
  -        method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port +
"/" + context + "/params"));
  +        method.setQueryString("to=http://" + host + ":" + port + "/" + context + "/params");
           method.setUseDisk(false);
           try {
               client.executeMethod(method);
  @@ -124,7 +132,7 @@
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           GetMethod method = new GetMethod("/" + context + "/redirect");
  -        method.setQueryString("to=" + URLEncoder.encode("/" + context + "/params"));
  +        method.setQueryString("to=/" + context + "/params");
           method.setUseDisk(false);
           try {
               client.executeMethod(method);
  @@ -140,7 +148,10 @@
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           GetMethod method = new GetMethod("/" + context + "/redirect");
  -        method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port +
"/" + context + "/params?foo=bar&bar=foo"));
  +        method.setQueryString(new NameValuePair[] {
  +            new NameValuePair("to", "http://" + host + ":" + port + "/" + context + "/params?foo=bar&bar=foo")
  +            }
  +        );
           method.setUseDisk(false);
           try {
               client.executeMethod(method);
  @@ -158,9 +169,9 @@
           client.startSession(host, port);
           GetMethod method = new GetMethod("/" + context + "/redirect");
   
  -        String qs = URLEncoder.encode("http://" + host + ":" + port + "/" + context + "/params?foo=bar&bar=foo");
  +        String qs = URIUtil.encodeQuery("http://" + host + ":" + port + "/" + context +
"/params?foo=bar&bar=foo");
           for(int i=0;i<10;i++) {
  -            qs = "to=" + URLEncoder.encode("http://" + host + ":" + port + "/" + context
+ "/redirect?to=" + qs);
  +            qs = "to=" + URIUtil.encodeQuery("http://" + host + ":" + port + "/" + context
+ "/redirect?to=" + qs);
           }
           method.setQueryString(qs);
           method.setUseDisk(false);
  @@ -190,15 +201,18 @@
           assertTrue(null != method.getResponseHeader("location"));
           assertTrue(null != (method.getResponseHeader("location")).getValue());
           assertEquals("http://" + host + (port == 80 ? "" : ":" + port) + "/" + context
+ "/redirect?loop=true",(method.getResponseHeader("location")).getValue());
  +        log.info("Previous redirect loop warining is okay");
       }
   
       public void testPostRedirect() throws Exception {
  +        String body = "Hello World";
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           PostMethod method = new PostMethod("/" + context + "/redirect");
  -        method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port +
"/" + context + "/params?foo=bar&bar=foo"));
  -        method.addParameter("param","eter");
  -        method.addParameter("para","meter");
  +        method.setQueryString("to=" + URIUtil.encodeQuery("http://" + host + ":" + port
+ "/" + context + "/params?foo=bar&bar=foo"));
  +        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  +        method.setRequestContentLength(body.length());  //unbuffered request
  +        method.setFollowRedirects(true);
           method.setUseDisk(false);
           try {
               client.executeMethod(method);
  @@ -206,14 +220,31 @@
               t.printStackTrace();
               fail("Unable to execute method : " + t.toString());
           }
  +        //unbuffered request can not be redirected
           assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode());
  +
  +        method = new PostMethod("/" + context + "/redirect");
  +        method.setQueryString("to=" + URIUtil.encodeQuery("http://" + host + ":" + port
+ "/" + context + "/params?foo=bar&bar=foo"));
  +        method.setRequestBody(new ByteArrayInputStream(body.getBytes()));
  +        method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); //buffered request
  +        method.setFollowRedirects(true);
  +        method.setUseDisk(false);
  +        try {
  +            client.executeMethod(method);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        //buffered request is okay to redirect
  +        assertEquals(HttpStatus.SC_OK,method.getStatusCode());
  +        client.endSession();
       }
   
       public void testPutRedirect() throws Exception {
           HttpClient client = new HttpClient();
           client.startSession(host, port);
           PutMethod method = new PutMethod("/" + context + "/redirect");
  -        method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port +
"/" + context + "/body?foo=bar&bar=foo"));
  +        method.setQueryString("to=" + URIUtil.encodeQuery("http://" + host + ":" + port
+ "/" + context + "/body?foo=bar&bar=foo"));
           method.setRequestBody("This is data to be sent in the body of an HTTP PUT.");
           try {
               client.executeMethod(method);
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message