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
Date Fri, 11 Oct 2002 13:03:34 GMT
oglueck     2002/10/11 06:03:34

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestMethodsNoHost.java
  Log:
  added test for auto close connections
  optimized imports
  
  Revision  Changes    Path
  1.9       +33 -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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestMethodsNoHost.java	11 Oct 2002 08:34:32 -0000	1.8
  +++ TestMethodsNoHost.java	11 Oct 2002 13:03:34 -0000	1.9
  @@ -63,14 +63,19 @@
   package org.apache.commons.httpclient;
   
   import java.io.IOException;
  +import java.io.InputStreamReader;
  +import java.io.Reader;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  -import org.apache.commons.httpclient.methods.*;
  +import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.methods.PostMethod;
   
   /**
    * @author Rodney Waldhoff
    * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
  + * @author Ortwin Glück
    * @version $Revision$ $Date$
    */
   public class TestMethodsNoHost extends TestCase {
  @@ -273,6 +278,29 @@
           String responseBody = method.getResponseBodyAsString();
           conn.close();
           assertEquals("1234567890123", responseBody);
  +    }
  +
  +    public void testConnectionAutoClose() throws Exception {
  +        SimpleHttpConnection conn = new SimpleHttpConnection();
  +        String headers = "HTTP/1.1 200 OK\r\n"
  +                       +"Date: Wed, 28 Mar 2001 05:05:04 GMT\r\n"
  +                       +"Connection: close\r\n";
  +        StringBuffer buffer = new StringBuffer(8200);
  +        for (int i = 0; i < 8200; i++) {
  +            buffer.append('A');
  +        }
  +        String body = buffer.toString();
  +
  +        conn.addResponse(headers, body);
  +        conn.open();
  +        HttpMethodBase method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        Reader response = new InputStreamReader(method.getResponseBodyAsStream());
  +        int c;
  +        while ((c = response.read()) != -1) {
  +           assertEquals((int) 'A', c);
  +        }
  +        assertTrue(!conn.isOpen());
       }
   
   
  
  
  

--
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