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: HttpParserBase.java,v 1.4 2003/02/17 04:17:28 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.protocol.http.impl; 23 24 import junit.framework.*; 25 26 import java.util.*; 27 import java.io.IOException; 28 29 import juju.reattore.protocol.http.*; 30 import juju.reattore.protocol.http.impl.BasicHttpParser; 31 import juju.reattore.io.impl.ByteSourceSink; 32 33 public class HttpParserBase 34 extends TestCase { 35 36 private HttpParser pa = new BasicHttpParser(); 37 private List messages = new ArrayList(); 38 39 public void add(String in) 40 throws ParseException, IOException { 41 42 messages.addAll(pa.add(new ByteSourceSink(in.getBytes()))); 43 } 44 45 public int getNumParsed() { 46 return messages.size(); 47 } 48 49 public String getBody(int off) 50 throws IOException { 51 52 byte[] ab = new byte[1024]; 53 int got = get(off).getBody().get(ab, 0, ab.length); 54 55 return new String(ab, 0, got); 56 } 57 58 public String getBody() 59 throws IOException { 60 61 return getBody(0); 62 } 63 64 public void expect(String name, String val) { 65 HttpRequest req = (HttpRequest)messages.get(0); 66 assertEquals(val, req.getHeader(name)); 67 } 68 69 public HttpRequest get(int off) { 70 assertTrue(off < getNumParsed()); 71 72 return (HttpRequest)messages.get(off); 73 } 74 75 public HttpRequest get() { 76 return get(0); 77 } 78 }

This page was automatically generated by Maven