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: TestHeaderParser.java,v 1.3 2003/02/18 04:11:48 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.protocol.http.impl; 23 24 import java.io.IOException; 25 import java.util.*; 26 27 import junit.framework.*; 28 import org.apache.commons.logging.*; 29 30 import juju.reattore.io.impl.*; 31 import juju.reattore.protocol.http.impl.*; 32 import juju.reattore.protocol.http.*; 33 34 public class TestHeaderParser 35 extends TestCase 36 implements HeaderParser.Callback { 37 38 private HeaderParser pa = new HeaderParser(); 39 private BaseHttpRequest req = new BaseHttpRequest(); 40 41 public void onHeader(String name, String value) { 42 req.addHeader(name, value); 43 } 44 45 private boolean add(String in) 46 throws ParseException, IOException { 47 48 pa.setCallback(this); 49 return pa.add(new PushbackByteSource(new ByteSourceSink(in.getBytes()))); 50 } 51 52 private void expect(String name, String val) { 53 assertEquals(val, req.getHeader(name)); 54 } 55 56 public void testReset() 57 throws Exception { 58 59 assertEquals(true, add("Trailer: 123\r\n" 60 + "\r\n")); 61 62 expect(HttpConstants.TRAILER, "123"); 63 64 pa.reset(); 65 /* PENDING */ 66 } 67 68 public void testPlain() 69 throws Exception { 70 71 add("Trailer: 123\r\n" 72 + "\r\n"); 73 74 expect(HttpConstants.TRAILER, "123"); 75 } 76 77 public void testFolding() 78 throws Exception { 79 80 add("Trailer: 123\r\n" 81 + " 456\r\n" 82 + "\r\n"); 83 84 expect(HttpConstants.TRAILER, "123 456"); 85 } 86 87 public void testCase1() 88 throws Exception { 89 90 add("trailer: 123\r\n" 91 + "\r\n"); 92 93 expect(HttpConstants.TRAILER, "123"); 94 } 95 96 public void testCase2() 97 throws Exception { 98 99 add("traILer: 1234\r\n" 100 + "\r\n"); 101 102 expect(HttpConstants.TRAILER, "1234"); 103 } 104 105 public void testExtraLWS() 106 throws Exception { 107 108 add("Trailer: 1234 \r\n" 109 + "\r\n"); 110 111 expect(HttpConstants.TRAILER, "1234"); 112 } 113 114 public void testPipeline() 115 throws Exception { 116 117 add("Trailer: 123\r\n" 118 + "\r\n"); 119 120 expect(HttpConstants.TRAILER, "123"); 121 122 add("Pragma: 123\r\n" 123 + "\r\n"); 124 125 expect(HttpConstants.PRAGMA, "123"); 126 } 127 128 public static Test suite() { 129 return new TestSuite(TestHeaderParser.class); 130 } 131 }

This page was automatically generated by Maven