01: package fitnesse.responders;
02:
03: import java.io.FileNotFoundException;
04:
05: import junit.framework.TestCase;
06: import fitnesse.FitNesseContext;
07: import fitnesse.http.MockRequest;
08: import fitnesse.http.MockResponseSender;
09: import fitnesse.http.Response;
10: import fitnesse.wiki.InMemoryPage;
11:
12: public class ClasspathFileResponderTest extends TestCase {
13:
14: ClasspathFileResponder responder = null;
15:
16: public ClasspathFileResponderTest(String test) {
17: super (test);
18: }
19:
20: protected void setUp() throws Exception {
21: super .setUp();
22:
23: this .responder = new ClasspathFileResponder();
24: }
25:
26: protected void tearDown() throws Exception {
27: this .responder = null;
28:
29: super .tearDown();
30: }
31:
32: public void testMakeResponse() throws Exception {
33: FitNesseContext context = new FitNesseContext(InMemoryPage
34: .makeRoot("RooT"));
35: MockRequest request = new MockRequest();
36: request.setRequestUri("/stiq/TestRunner.hta");
37: Response response = this .responder.makeResponse(context,
38: request);
39: MockResponseSender sender = new MockResponseSender(response);
40: String result = sender.sentData();
41: assertTrue(result.indexOf("Content-Type") != -1);
42: assertTrue(result.indexOf("Content-Length") != -1);
43:
44: }
45:
46: public void testMakeResponseFileNotFound() throws Exception {
47: FitNesseContext context = new FitNesseContext(InMemoryPage
48: .makeRoot("RooT"));
49: MockRequest request = new MockRequest();
50: request.setRequestUri("/stiq/TestRunner.hta");
51: request.setResource("zzzNotFound");
52: try {
53: this .responder.makeResponse(context, request);
54: fail("Invalid resource passed");
55: } catch (FileNotFoundException e) {
56: assertEquals("/zzzNotFound", e.getMessage());
57: }
58: }
59:
60: }
|