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.responders.run;
04:
05: import fitnesse.testutil.*;
06: import fitnesse.http.*;
07: import fitnesse.FitNesseContext;
08:
09: public class SocketCatchingResponderTest extends AbstractRegex {
10: private SocketDealer dealer;
11:
12: private SimpleSocketSeeker seeker;
13:
14: private MockResponseSender sender;
15:
16: private SocketCatchingResponder responder;
17:
18: private FitNesseContext context;
19:
20: private MockRequest request;
21:
22: public void setUp() throws Exception {
23: dealer = new SocketDealer();
24: seeker = new SimpleSocketSeeker();
25: sender = new MockResponseSender();
26: responder = new SocketCatchingResponder();
27: context = new FitNesseContext();
28: context.socketDealer = dealer;
29: request = new MockRequest();
30: }
31:
32: public void tearDown() throws Exception {
33: }
34:
35: public void testSuccess() throws Exception {
36: int ticket = dealer.seekingSocket(seeker);
37: request.addInput("ticket", ticket + "");
38: Response response = responder.makeResponse(context, request);
39: response.readyToSend(sender);
40:
41: assertEquals("", sender.sentData());
42: }
43:
44: public void testMissingSeeker() throws Exception {
45: request.addInput("ticket", "123");
46: Response response = responder.makeResponse(context, request);
47: response.readyToSend(sender);
48:
49: assertHasRegexp(
50: "There are no clients waiting for a socket with ticketNumber 123",
51: sender.sentData());
52: assertTrue(sender.closed);
53: assertEquals(404, response.getStatus());
54: }
55:
56: }
|