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 fitnesse.testutil.AbstractRegex;
06: import java.net.Socket;
07:
08: public class SimpleResponseTest extends AbstractRegex implements
09: ResponseSender {
10: private String text;
11:
12: private boolean closed = false;
13:
14: public void send(byte[] bytes) throws Exception {
15: text = new String(bytes, "UTF-8");
16: }
17:
18: public void close() {
19: closed = true;
20: }
21:
22: public Socket getSocket() throws Exception {
23: return null;
24: }
25:
26: public void setUp() throws Exception {
27: }
28:
29: public void tearDown() throws Exception {
30: }
31:
32: public void testSimpleResponse() throws Exception {
33: SimpleResponse response = new SimpleResponse();
34: response.setContent("some content");
35: response.readyToSend(this );
36: assertTrue(text.startsWith("HTTP/1.1 200 OK\r\n"));
37: assertHasRegexp("Content-Length: 12", text);
38: assertHasRegexp("Content-Type: text/html", text);
39: assertTrue(text.endsWith("some content"));
40: assertTrue(closed);
41: }
42:
43: public void testPageNotFound() throws Exception {
44: SimpleResponse response = new SimpleResponse(404);
45: response.readyToSend(this );
46: assertHasRegexp("404 Not Found", text);
47: }
48:
49: public void testRedirect() throws Exception {
50: SimpleResponse response = new SimpleResponse();
51: response.redirect("some url");
52: response.readyToSend(this );
53: assertEquals(303, response.getStatus());
54: assertHasRegexp("Location: some url\r\n", text);
55: }
56:
57: public void testUnicodeCharacters() throws Exception {
58: SimpleResponse response = new SimpleResponse();
59: response.setContent("\uba80\uba81\uba82\uba83");
60: response.readyToSend(this );
61:
62: assertSubString("\uba80\uba81\uba82\uba83", text);
63: }
64: }
|