Package test.juju.reattore.protocol.http.impl

Source Code of test.juju.reattore.protocol.http.impl.HttpParserBase

/*  Reattore HTTP Server

    Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    $Id: HttpParserBase.java,v 1.4 2003/02/17 04:17:28 michaelh Exp $
*/

package test.juju.reattore.protocol.http.impl;

import junit.framework.*;

import java.util.*;
import java.io.IOException;

import juju.reattore.protocol.http.*;
import juju.reattore.protocol.http.impl.BasicHttpParser;
import juju.reattore.io.impl.ByteSourceSink;

public class HttpParserBase
    extends TestCase {

    private HttpParser pa = new BasicHttpParser();
    private List messages = new ArrayList();

    public void add(String in)
        throws ParseException, IOException {

        messages.addAll(pa.add(new ByteSourceSink(in.getBytes())));
    }

    public int getNumParsed() {
        return messages.size();
    }

    public String getBody(int off)
        throws IOException {

        byte[] ab = new byte[1024];
        int got = get(off).getBody().get(ab, 0, ab.length);

        return new String(ab, 0, got);
    }

    public String getBody()
        throws IOException {

        return getBody(0);
    }

    public void expect(String name, String val) {
        HttpRequest req = (HttpRequest)messages.get(0);
        assertEquals(val, req.getHeader(name));
    }

    public HttpRequest get(int off) {
        assertTrue(off < getNumParsed());

        return (HttpRequest)messages.get(off);
    }

    public HttpRequest get() {
        return get(0);
    }
}
TOP

Related Classes of test.juju.reattore.protocol.http.impl.HttpParserBase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.