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.files;
04:
05: import fitnesse.*;
06: import fitnesse.testutil.AbstractRegex;
07: import fitnesse.http.*;
08:
09: public class DirectoryResponderTest extends AbstractRegex {
10: MockRequest request;
11:
12: private SimpleResponse response;
13:
14: private FitNesseContext context;
15:
16: public void setUp() throws Exception {
17: request = new MockRequest();
18: context = new FitNesseContext();
19: context.rootPagePath = SampleFileUtility.TEMP_TEST_DIR;
20: SampleFileUtility.makeSampleFiles();
21: }
22:
23: public void tearDown() throws Exception {
24: SampleFileUtility.deleteSampleFiles();
25: }
26:
27: public void testDirectotyListing() throws Exception {
28: request.setResource("files/testDir/");
29: Responder responder = FileResponder.makeResponder(request,
30: SampleFileUtility.TEMP_TEST_DIR);
31: response = (SimpleResponse) responder.makeResponse(context,
32: request);
33: assertHasRegexp("testDir", response.getContent());
34: assertHasRegexp("testFile2</a>", response.getContent());
35: assertHasRegexp("testFile3</a>", response.getContent());
36: assertHasRegexp("<a href=\"/", response.getContent());
37: }
38:
39: public void testButtons() throws Exception {
40: request.setResource("files/testDir/");
41: Responder responder = FileResponder.makeResponder(request,
42: SampleFileUtility.TEMP_TEST_DIR);
43: response = (SimpleResponse) responder.makeResponse(context,
44: request);
45:
46: assertHasRegexp("upload form", response.getContent());
47: assertHasRegexp("create directory form", response.getContent());
48: }
49:
50: public void testHtml() throws Exception {
51: request.setResource("files/testDir/");
52: Responder responder = FileResponder.makeResponder(request,
53: SampleFileUtility.TEMP_TEST_DIR);
54: response = (SimpleResponse) responder.makeResponse(context,
55: request);
56: assertHasRegexp("/files/", response.getContent());
57: }
58:
59: public void testRedirectForDirectory() throws Exception {
60: request.setResource("files/testDir");
61: Responder responder = FileResponder.makeResponder(request,
62: SampleFileUtility.TEMP_TEST_DIR);
63: Response response = responder.makeResponse(context, request);
64: assertEquals(303, response.getStatus());
65: assertEquals("/files/testDir/", response.getHeader("Location"));
66: }
67:
68: public void testFrontPageSidebarButtonPresent() throws Exception {
69: request.setResource("files/testDir/");
70: Responder responder = FileResponder.makeResponder(request,
71: SampleFileUtility.TEMP_TEST_DIR);
72: response = (SimpleResponse) responder.makeResponse(context,
73: request);
74:
75: assertHasRegexp("<div class=\"mainbar\"", response.getContent());
76: assertHasRegexp("<div class=\"actions\"", response.getContent());
77: assertHasRegexp("<a href=\"/FrontPage\" accesskey=\"f\"",
78: response.getContent());
79: }
80:
81: public void testSizeString() throws Exception {
82: assertEquals("", DirectoryResponder
83: .getSizeString(SampleFileUtility.testDir));
84: assertEquals("13 bytes", DirectoryResponder
85: .getSizeString(SampleFileUtility.testFile1));
86: }
87: }
|