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.refactoring;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.http.*;
07: import fitnesse.*;
08: import fitnesse.responders.AbstractResponderRegex;
09: import java.util.List;
10:
11: public class DeletePageResponderTest extends AbstractResponderRegex {
12: final String level1Name = "LevelOne";
13:
14: final WikiPagePath level1Path = PathParser.parse(level1Name);
15:
16: final String level2Name = "LevelTwo";
17:
18: final WikiPagePath level2Path = PathParser.parse(level2Name);
19:
20: final WikiPagePath level2FullPath = level1Path.copy().addName(
21: level2Name);
22:
23: final String qualifiedLevel2Name = PathParser
24: .render(level2FullPath);
25:
26: public void setUp() throws Exception {
27: super .setUp();
28: }
29:
30: public void testDeleteConfirmation() throws Exception {
31: WikiPage level1 = crawler.addPage(root, level1Path);
32: crawler.addPage(level1, level2Path);
33: MockRequest request = new MockRequest();
34: request.setResource(qualifiedLevel2Name);
35: request.addInput("deletePage", "");
36:
37: SimpleResponse response = (SimpleResponse) responder
38: .makeResponse(new FitNesseContext(root), request);
39: String content = response.getContent();
40: assertSubString("Are you sure you want to delete "
41: + qualifiedLevel2Name, content);
42: }
43:
44: public void testDeletePage() throws Exception {
45: WikiPage level1 = crawler.addPage(root, level1Path);
46: crawler.addPage(level1, level2Path);
47: assertTrue(crawler.pageExists(root, level1Path));
48: MockRequest request = new MockRequest();
49: request.setResource(level1Name);
50: request.addInput("confirmed", "yes");
51:
52: SimpleResponse response = (SimpleResponse) responder
53: .makeResponse(new FitNesseContext(root), request);
54: String page = response.getContent();
55: assertNotSubString("Are you sure you want to delete", page);
56: assertEquals(303, response.getStatus());
57: assertEquals("root", response.getHeader("Location"));
58: assertFalse(crawler.pageExists(root, PathParser
59: .parse(level1Name)));
60:
61: List children = root.getChildren();
62: assertEquals(0, children.size());
63: }
64:
65: public void testDontDeleteFrontPage() throws Exception {
66: crawler.addPage(root, PathParser.parse("FrontPage"), "Content");
67: request.setResource("FrontPage");
68: request.addInput("confirmed", "yes");
69: Response response = responder.makeResponse(new FitNesseContext(
70: root), request);
71: assertEquals(303, response.getStatus());
72: assertEquals("FrontPage", response.getHeader("Location"));
73: }
74:
75: protected Responder responderInstance() {
76: return new DeletePageResponder();
77: }
78: }
|