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.testutil.*;
06: import fitnesse.http.MockRequest;
07: import fitnesse.http.Response;
08: import fitnesse.FitNesseContext;
09: import fitnesse.util.FileUtil;
10:
11: import java.io.File;
12:
13: public class DeleteFileResponderTest extends AbstractRegex {
14: public MockRequest request;
15:
16: private FitNesseContext context;
17:
18: public void setUp() {
19: FileUtil.makeDir("testdir");
20: request = new MockRequest();
21: context = new FitNesseContext();
22: context.rootPagePath = "testdir";
23: }
24:
25: public void tearDown() throws Exception {
26: FileUtil.deleteFileSystemDirectory("testdir");
27: }
28:
29: public void testDelete() throws Exception {
30: File file = new File("testdir/testfile");
31: assertTrue(file.createNewFile());
32: DeleteFileResponder responder = new DeleteFileResponder();
33: request.addInput("filename", "testfile");
34: request.setResource("");
35: Response response = responder.makeResponse(context, request);
36: assertFalse(file.exists());
37: assertEquals(303, response.getStatus());
38: assertEquals("/", response.getHeader("Location"));
39: }
40:
41: public void testDeleteDirectory() throws Exception {
42: File dir = new File("testdir/dir");
43: assertTrue(dir.mkdir());
44: File file = new File(dir, "testChildFile");
45: assertTrue(file.createNewFile());
46: DeleteFileResponder responder = new DeleteFileResponder();
47: request.addInput("filename", "dir");
48: request.setResource("");
49: responder.makeResponse(context, request);
50: assertFalse(file.exists());
51: assertFalse(dir.exists());
52:
53: }
54: }
|