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 junit.framework.TestCase;
06: import fitnesse.http.MockRequest;
07: import fitnesse.http.Response;
08: import fitnesse.responders.files.RenameFileResponder;
09: import fitnesse.FitNesseContext;
10: import fitnesse.util.FileUtil;
11: import java.io.File;
12:
13: public class RenameFileResponderTest extends TestCase {
14: private 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 testMakeResponse() throws Exception {
30: File file = new File("testdir/testfile");
31: assertTrue(file.createNewFile());
32: RenameFileResponder responder = new RenameFileResponder();
33: request.addInput("filename", "testfile");
34: request.addInput("newName", "newName");
35: request.setResource("");
36: Response response = responder.makeResponse(context, request);
37: assertFalse(file.exists());
38: assertTrue(new File("testdir/newName").exists());
39: assertEquals(303, response.getStatus());
40: assertEquals("/", response.getHeader("Location"));
41: }
42:
43: public void testRenameWithTrailingSpace() throws Exception {
44: File file = new File("testdir/testfile");
45: assertTrue(file.createNewFile());
46: RenameFileResponder responder = new RenameFileResponder();
47: request.addInput("filename", "testfile");
48: request.addInput("newName", "new Name With Space ");
49: request.setResource("");
50: responder.makeResponse(context, request);
51: assertFalse(file.exists());
52: assertTrue(new File("testdir/new Name With Space").exists());
53: }
54: }
|