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 TestStreams.java
Date Mon, 23 Sep 2002 14:01:40 GMT
oglueck     2002/09/23 07:01:40

  Modified:    httpclient/src/examples TrivialApp.java
               httpclient/src/java/org/apache/commons/httpclient
                        ChunkedInputStream.java HttpConnection.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestStreams.java
  Log:
  Patches by Martin Elwin fixing bug #12607 and some more.
  
  Revision  Changes    Path
  1.4       +4 -4      jakarta-commons/httpclient/src/examples/TrivialApp.java
  
  Index: TrivialApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/TrivialApp.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TrivialApp.java	23 Sep 2002 13:31:08 -0000	1.3
  +++ TrivialApp.java	23 Sep 2002 14:01:40 -0000	1.4
  @@ -79,7 +79,7 @@
   
       private static final void printUsage()
       {
  -        System.out.println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>]
SimpleApp <url>");
  +        System.out.println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>]
TrivialApp <url>");
           System.out.println("<classpath> - must contain the commons-httpclient.jar
and commons-logging.jar");
           System.out.println("<loglevel> - one of error, warn, info, debug, trace");
           System.out.println("<url> - some valid URL");
  
  
  
  1.4       +4 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java
  
  Index: ChunkedInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ChunkedInputStream.java	12 Sep 2002 11:36:45 -0000	1.3
  +++ ChunkedInputStream.java	23 Sep 2002 14:01:40 -0000	1.4
  @@ -134,7 +134,7 @@
               nextChunk();
               if (eof) return -1;
           }
  -        len = Math.min(len, chunkSize);
  +        len = Math.min(len, chunkSize - pos);
           int count = in.read(b, off, len);
           pos += count;
           return count;
  
  
  
  1.21      +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- HttpConnection.java	8 Sep 2002 05:35:09 -0000	1.20
  +++ HttpConnection.java	23 Sep 2002 14:01:40 -0000	1.21
  @@ -455,7 +455,7 @@
        */
       public InputStream getResponseInputStream(HttpMethod method) 
       throws IOException, IllegalStateException {
  -        log.trace("enter HttpConnection.getRequestOutputStream(HttpMethod)");
  +        log.trace("enter HttpConnection.getResponseInputStream(HttpMethod)");
           assertOpen();
           return _input;
       }
  
  
  
  1.2       +22 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStreams.java
  
  Index: TestStreams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStreams.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestStreams.java	2 Sep 2002 14:52:48 -0000	1.1
  +++ TestStreams.java	23 Sep 2002 14:01:40 -0000	1.2
  @@ -13,9 +13,12 @@
       }
   
       public void testChunkedInputStream() throws IOException {
  -        String correct = "10; this is comments\r\n1234567890123456\r\n5\r\n12345\r\n0\r\nFooter1:
abcde\r\nFooter2: fghij\r\n";
  +        String correctInput = "10; this is comments\r\n1234567890123456\r\n5\r\n12345\r\n0\r\nFooter1:
abcde\r\nFooter2: fghij\r\n";
  +        String correctResult = "123456789012345612345";
           HttpMethod method = new SimpleHttpMethod();
  -        InputStream in = new ChunkedInputStream(new ByteArrayInputStream(correct.getBytes()),
method);
  +
  +        //Test for when buffer is larger than chunk size
  +        InputStream in = new ChunkedInputStream(new ByteArrayInputStream(correctInput.getBytes()),
method);
           byte[] buffer = new byte[300];
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           int len;
  @@ -23,11 +26,26 @@
               out.write(buffer, 0, len);
           }
           String result = new String(out.toByteArray());
  -        assertEquals(result, "123456789012345612345");
  +        assertEquals(result, correctResult);
           Header footer = method.getResponseFooter("footer1");
           assertEquals(footer.getValue(), "abcde");
           footer = method.getResponseFooter("footer2");
           assertEquals(footer.getValue(), "fghij");
  +
  +
  +        //Test for when buffer is smaller than chunk size.
  +        in = new ChunkedInputStream(new ByteArrayInputStream(correctInput.getBytes()),
method);
  +        buffer = new byte[7];
  +        out = new ByteArrayOutputStream();
  +        while ((len = in.read(buffer)) > 0) {
  +            out.write(buffer, 0, len);
  +        }
  +        result = new String(out.toByteArray());
  +        assertEquals(result, correctResult);
  +        footer = method.getResponseFooter("footer1");
  +        assertEquals(footer.getValue(), "abcde");
  +        footer = method.getResponseFooter("footer2");
  +        assertEquals(footer.getValue(), "fghij");
       }
   
       public void testContentLengthInputStream() throws IOException {
  @@ -44,7 +62,7 @@
       // ------------------------------------------------------- TestCase Methods
   
       public static Test suite() {
  -        return new TestSuite(TestHeader.class);
  +        return new TestSuite(TestStreams.class);
       }
   
       // ------------------------------------------------------------------- Main
  
  
  

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