01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.http;
04:
05: import junit.framework.*;
06: import junit.swingui.TestRunner;
07:
08: import java.io.*;
09:
10: public class ResponseParserTest extends TestCase {
11: private String response;
12:
13: private InputStream input;
14:
15: public static void main(String[] args) {
16: TestRunner.main(new String[] { "ResponseParserTest" });
17: }
18:
19: public void setUp() throws Exception {
20: }
21:
22: public void tearDown() throws Exception {
23: }
24:
25: public void testParsing() throws Exception {
26: response = "HTTP/1.1 200 OK\r\n"
27: + "Content-Type: text/html\r\n"
28: + "Content-Length: 12\r\n"
29: + "Cache-Control: max-age=0\r\n" + "\r\n"
30: + "some content";
31: input = new ByteArrayInputStream(response.getBytes());
32:
33: ResponseParser parser = new ResponseParser(input);
34: assertEquals(200, parser.getStatus());
35: assertEquals("text/html", parser.getHeader("Content-Type"));
36: assertEquals("some content", parser.getBody());
37: }
38:
39: public void testChunkedResponse() throws Exception {
40: response = "HTTP/1.1 200 OK\r\n"
41: + "Content-Type: text/html\r\n"
42: + "Transfer-Encoding: chunked\r\n" + "\r\n" + "3\r\n"
43: + "123\r\n" + "7\r\n" + "4567890\r\n" + "0\r\n"
44: + "Tail-Header: TheEnd!\r\n";
45: input = new ByteArrayInputStream(response.getBytes());
46:
47: ResponseParser parser = new ResponseParser(input);
48: assertEquals(200, parser.getStatus());
49: assertEquals("text/html", parser.getHeader("Content-Type"));
50: assertEquals("1234567890", parser.getBody());
51: assertEquals("TheEnd!", parser.getHeader("Tail-Header"));
52: }
53: }
|