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: TestHttpRequest.java,v 1.6 2003/02/17 04:17:28 michaelh Exp $
20 */
21
22 package test.juju.reattore.protocol.http.impl;
23
24 import java.io.IOException;
25
26 import junit.framework.*;
27
28 import juju.reattore.protocol.http.*;
29 import juju.reattore.protocol.http.impl.*;
30
31 public class TestHttpRequest
32 extends TestCase {
33
34 private static final String REQ =
35 "GET /foo/bar.html?billy=bob&yes=no HTTP/1.1\r\n"
36 + "Header-1: value\r\n"
37 + "Header-2: value2\r\n"
38 + "Content-Length: 12\r\n"
39 + "\r\n"
40 + "A dog, a cat";
41
42 private HttpRequest req;
43
44 public void setUp()
45 throws Exception {
46
47 req = HttpParserHelper.parseRequest(REQ);
48 }
49
50 private String getBody()
51 throws IOException {
52
53 byte[] ab = new byte[1024];
54 int got = req.getBody().get(ab, 0, ab.length);
55
56 return new String(ab, 0, got);
57 }
58
59 public void testGetMethod()
60 throws Exception {
61
62 assertEquals("GET", req.getMethod());
63 }
64
65 public void testGetPath() {
66 assertEquals("/foo/bar.html", req.getPath());
67 }
68
69 public void testGetQueryString() {
70 assertEquals("billy=bob&yes=no", req.getQueryString());
71 }
72
73 public void testGetBody()
74 throws Exception {
75
76 assertEquals("A dog, a cat", getBody());
77 }
78
79 public static Test suite() {
80 return new TestSuite(TestHttpRequest.class);
81 }
82 }
This page was automatically generated by Maven