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.fixtures;
04:
05: import fit.ColumnFixture;
06: import fitnesse.http.*;
07: import fitnesse.wiki.*;
08: import fitnesse.*;
09: import fitnesse.wikitext.Utils;
10: import fitnesse.testutil.MockSocket;
11:
12: public class ResponseRequester extends ColumnFixture {
13: public String uri;
14: public String username;
15: public String password;
16:
17: protected MockRequest request;
18:
19: public boolean valid() throws Exception {
20: return status() == 200;
21: }
22:
23: public void execute() throws Exception {
24: request = new MockRequest();
25:
26: details();
27:
28: if (username != null)
29: request.setCredentials(username, password);
30:
31: request.parseRequestUri("/" + uri);
32: FitnesseFixtureContext.page = FitnesseFixtureContext.root
33: .getPageCrawler().getPage(FitnesseFixtureContext.root,
34: PathParser.parse(uri));
35: FitNesseExpediter expediter = new FitNesseExpediter(
36: new MockSocket(""), FitnesseFixtureContext.context);
37: FitnesseFixtureContext.response = expediter
38: .createGoodResponse(request);
39: FitnesseFixtureContext.sender = new MockResponseSender(
40: FitnesseFixtureContext.response);
41: }
42:
43: public int status() throws Exception {
44: int status = FitnesseFixtureContext.response.getStatus();
45: return status;
46: }
47:
48: public String contents() throws Exception {
49: return "<pre>"
50: + Utils.escapeText(FitnesseFixtureContext.sender
51: .sentData()) + "</pre>";
52: }
53:
54: protected void details() {
55: }
56: }
|