1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: TestHttpParser.java,v 1.6 2003/02/09 02:20:39 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.protocol.http.impl; 23 24 import junit.framework.*; 25 import org.apache.commons.logging.*; 26 27 import juju.reattore.protocol.http.HttpParser; 28 import juju.reattore.protocol.http.HttpConstants; 29 import juju.reattore.io.impl.ByteSourceSink; 30 31 public class TestHttpParser 32 extends HttpParserBase { 33 34 public void testNoContentLength() 35 throws Exception { 36 37 add("GET / HTTP/1.1\r\nAccept: */*\r\n\r\n"); 38 39 assertTrue(getNumParsed() == 1); 40 41 assertEquals(1, get().getNumHeaders()); 42 43 assertEquals("*/*", get().getHeader(HttpConstants.ACCEPT)); 44 } 45 46 public void testPartial() 47 throws Exception { 48 49 add("GET /"); 50 assertTrue(getNumParsed() == 0); 51 52 add(" HTTP/1.1\r\nFoo: Bar\r\n"); 53 assertTrue(getNumParsed() == 0); 54 55 add("\r"); 56 assertTrue(getNumParsed() == 0); 57 add("\n"); 58 assertTrue(getNumParsed() == 1); 59 } 60 61 public void testBody() 62 throws Exception { 63 64 String body = "This is the body.\r\nYeah!"; 65 66 add("GET / HTTP/1.1\r\nContent-Length: " + body.length() + "\r\n\r\n" + body); 67 68 assertTrue(getNumParsed() == 1); 69 assertEquals(body, getBody()); 70 } 71 72 public void testPartialBody() 73 throws Exception { 74 75 String body = "This is the body.\r\nYeah!"; 76 77 add("GET / HTTP/1.1\r\nContent-Length: " + body.length() + "\r\n\r\n"); 78 assertTrue(getNumParsed() == 0); 79 80 add(body.substring(0, body.length()-1)); 81 assertTrue(getNumParsed() == 0); 82 83 add(body.substring(body.length() - 1)); 84 assertTrue(getNumParsed() == 1); 85 assertEquals(body, getBody()); 86 } 87 88 public static Test suite() { 89 return new TestSuite(TestHttpParser.class); 90 } 91 }

This page was automatically generated by Maven