jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test HTTPParserImplTestCase.java,1.6,1.7

Leo Simons <[email protected]>
Newsgroups gmane.comp.java.jicarilla.cvs
Message-ID <[email protected]>
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1107/platform/components/http/impl/src/test/org/jicarilla/http/test

Modified Files:
	HTTPParserImplTestCase.java 
Log Message:
forgot to commit some of this. See weblog for TODO :D

Index: HTTPParserImplTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test/HTTPParserImplTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- HTTPParserImplTestCase.java	26 Feb 2004 16:51:55 -0000	1.6
+++ HTTPParserImplTestCase.java	3 Apr 2004 10:13:24 -0000	1.7
@@ -25,26 +25,25 @@
 ==================================================================== */
 package org.jicarilla.http.test;
 
-import org.jicarilla.http.HTTPParser;
-import org.jicarilla.http.HTTPHandler;
-import org.jicarilla.http.HTTPErrorHandler;
-import org.jicarilla.http.HTTPParserImpl;
+import junit.framework.TestCase;
+import org.easymock.MockControl;
 import org.jicarilla.http.HTTPEncoding;
+import org.jicarilla.http.HTTPErrorHandler;
 import org.jicarilla.http.HTTPException;
-import org.jicarilla.http.util.NioUtil;
+import org.jicarilla.http.HTTPHandler;
+import org.jicarilla.http.HTTPParser;
+import org.jicarilla.http.HTTPParserImpl;
 import org.jicarilla.http.util.Iso646;
-import org.easymock.MockControl;
-
-import junit.framework.TestCase;
+import org.jicarilla.http.util.NioUtil;
 
-import java.io.InputStream;
-import java.io.StringBufferInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.nio.channels.ReadableByteChannel;
+import java.io.InputStream;
+import java.io.StringBufferInputStream;
+import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.FileChannel;
-import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
 
 /**
  * 
@@ -1087,6 +1086,242 @@
         errorHandlerControl.verify();
         handlerControl.verify();
     }
+    
+    // ----------------------------------------------------------------------
+    //  Chunked transfer-coding tests
+    // ----------------------------------------------------------------------
+
+    public void testBasicChunkEncodedRequest()
+            throws Exception
+    {
+        String chunk1 = "test";
+        String chunk2 = "test" + HTTPEncoding.CR + HTTPEncoding.LF +
+                HTTPEncoding.CR + HTTPEncoding.LF;
+        String chunk3 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+        
+        String request =
+                "GET / HTTP/1.1" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Host: localhost" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Transfer-encoding: chunked"+
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk1.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk1 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk2.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk2 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk3.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk3 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                "0" + HTTPEncoding.CR + HTTPEncoding.LF;
+
+        handler.newMessage();
+        handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
+        handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
+        handler.foundStartLineThirdField( NioUtil.toByteBuffer( "HTTP/1.1" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Host" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "localhost" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Transfer-encoding" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "chunked" ) );
+        handler.getBodyType();
+        handlerControl.setReturnValue( HTTPParser.BODY_TYPE_CHUNKING );
+        handler.foundBody( NioUtil.toByteBuffer( chunk1 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk2 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk3 ) );
+        handler.hasTrailers();
+        handlerControl.setReturnValue( false );
+        handler.endMessage();
+        
+        handlerControl.replay();
+        errorHandlerControl.replay();
+
+        doParse( request );
+
+        errorHandlerControl.verify();
+        handlerControl.verify();
+    }
+
+    public void testMultiBufferChunkEncodedRequest() throws Exception
+    {
+        String chunk1 = "test";
+        String chunk2 = "test" + HTTPEncoding.CR + HTTPEncoding.LF +
+                HTTPEncoding.CR + HTTPEncoding.LF;
+        String chunk3firsthalf =
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+        String chunk3secondhalf = 
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+        
+        handler.newMessage();
+
+        handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
+        handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
+        handler.foundStartLineThirdField( NioUtil.toByteBuffer( "HTTP/1.1" ) );
+
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Host" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "localhost:8080" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "User-Agent" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Accept" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Accept-Language" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( " en-us,en;q=0.5" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Accept-Encoding" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "gzip,deflate" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Accept-Charset" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "ISO-8859-1,utf-8;q=0.7,*;q=0.7" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Keep-Alive" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "300" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Connection" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "keep-alive" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Cache-Control" ) );
+        handler.foundHeaderValue(NioUtil.toByteBuffer( "m_upto-age=0" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Transfer-encoding" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "chunked" ) );
+
+        handler.getBodyType();
+        handlerControl.setReturnValue( HTTPParser.BODY_TYPE_CHUNKING );
+
+        handler.foundBody( NioUtil.toByteBuffer( chunk1 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk2 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk3firsthalf ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk3secondhalf ) );
+        handler.hasTrailers();
+        handlerControl.setReturnValue( false );
+
+        handler.endMessage();
+        handlerControl.replay();
+
+        errorHandlerControl.replay();
+
+        final String[] request = new String[]
+        {
+            "GE", "T /", " HTT", "P", "/1.1",
+                ""+HTTPEncoding.CR,
+                ""+ HTTPEncoding.LF,
+                "Host: localhost:8080" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "User-Agent:      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624" + HTTPEncoding.CR + HTTPEncoding.LF,
+                "Acc",
+                "ept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Accept-Language:\t ",
+                "",
+                "" + HTTPEncoding.CR + HTTPEncoding.LF,
+                " en-us,en;q=0.5" + HTTPEncoding.CR + HTTPEncoding.LF,
+                //"Accept-Language: ",
+                //""+HTTPEncoding.CR + HTTPEncoding.LF,
+                //"en-us,en;q=0.5" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Accept-Encoding: gzip,deflate" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Keep-Alive: 300" + HTTPEncoding.CR + HTTPEncoding.LF,
+                "Connection: keep-alive" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Cache-Control: m_",
+                "upto-age=0" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Transfer-encoding: chunked" + HTTPEncoding.CR + HTTPEncoding.LF +
+                HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk1.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk1 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk2.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk2 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk3firsthalf.length()+chunk3secondhalf.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk3firsthalf,
+                chunk3secondhalf +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                "0" + HTTPEncoding.CR + HTTPEncoding.LF
+        };
+        for( int i = 0; i < request.length; i++ )
+        {
+            final String s = request[i];
+            doParse( s );
+        }
+
+        errorHandlerControl.verify();
+        handlerControl.verify();
+    }
+
+    public void testChunkEncodedRequestWithTrailers()
+            throws Exception
+    {
+        String chunk1 = "test";
+        String chunk2 = "test" + HTTPEncoding.CR + HTTPEncoding.LF +
+                HTTPEncoding.CR + HTTPEncoding.LF;
+        String chunk3 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+        
+        String request =
+                "GET / HTTP/1.1" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Host: localhost" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Transfer-encoding: chunked" +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                "Trailer: Content-Type" +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk1.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk1 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk2.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk2 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                Integer.toHexString( chunk3.length() ) +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                chunk3 +
+                    HTTPEncoding.CR + HTTPEncoding.LF +
+                "0" + HTTPEncoding.CR + HTTPEncoding.LF +
+                "Content-Type: text/html"
+                    + HTTPEncoding.CR + HTTPEncoding.LF;
+
+        handler.newMessage();
+        handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
+        handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
+        handler.foundStartLineThirdField( NioUtil.toByteBuffer( "HTTP/1.1" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Host" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "localhost" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Transfer-encoding" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "chunked" ) );
+        handler.foundHeaderName( NioUtil.toByteBuffer( "Trailer" ) );
+        handler.foundHeaderValue( NioUtil.toByteBuffer( "Content-Type" ) );
+        handler.getBodyType();
+        handlerControl.setReturnValue( HTTPParser.BODY_TYPE_CHUNKING );
+        handler.foundBody( NioUtil.toByteBuffer( chunk1 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk2 ) );
+        handler.foundBody( NioUtil.toByteBuffer( chunk3 ) );
+        handler.hasTrailers();
+        handlerControl.setReturnValue( true );
+        handler.getTrailerNames();
+        handlerControl.setReturnValue(
+                new String[]
+                {
+                    "Content-Type"
+                }
+        );
+        handler.foundTrailerName( NioUtil.toByteBuffer( "Content-Type" ) );
+        handler.foundTrailerValue( NioUtil.toByteBuffer( "text/html" ) );
+        handler.endMessage();
+        
+        handlerControl.replay();
+        errorHandlerControl.replay();
+
+        doParse( request );
+
+        errorHandlerControl.verify();
+        handlerControl.verify();
+    }
 
     // ----------------------------------------------------------------------
     //  Helper Methods



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.