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.editing;
04:
05: import fitnesse.http.*;
06: import fitnesse.wiki.*;
07: import fitnesse.*;
08: import fitnesse.testutil.AbstractRegex;
09:
10: public class SymbolicLinkResponderTest extends AbstractRegex {
11: private WikiPage root;
12:
13: private WikiPage pageOne;
14:
15: private MockRequest request;
16:
17: private Responder responder;
18:
19: public void setUp() throws Exception {
20: root = InMemoryPage.makeRoot("RooT");
21: pageOne = root.addChildPage("PageOne");
22: root.addChildPage("PageTwo");
23:
24: request = new MockRequest();
25: request.setResource("PageOne");
26: responder = new SymbolicLinkResponder();
27: }
28:
29: public void testSubmitGoodForm() throws Exception {
30: request.addInput("linkName", "SymLink");
31: request.addInput("linkPath", "PageTwo");
32: Response response = responder.makeResponse(new FitNesseContext(
33: root), request);
34:
35: checkRedirectToProperties(response);
36:
37: WikiPage symLink = pageOne.getChildPage("SymLink");
38: assertNotNull(symLink);
39: assertEquals(SymbolicPage.class, symLink.getClass());
40: }
41:
42: public void testRemoval() throws Exception {
43: PageData data = pageOne.getData();
44: data.getProperties().addSymbolicLink("SymLink",
45: PathParser.parse("PageTwo"));
46: pageOne.commit(data);
47: assertNotNull(pageOne.getChildPage("SymLink"));
48:
49: request.addInput("removal", "SymLink");
50: Response response = responder.makeResponse(new FitNesseContext(
51: root), request);
52: checkRedirectToProperties(response);
53:
54: assertNull(pageOne.getChildPage("SymLink"));
55: }
56:
57: public void testNoPageAtPath() throws Exception {
58: request.addInput("linkName", "SymLink");
59: request.addInput("linkPath", "NonExistingPage");
60: Response response = responder.makeResponse(new FitNesseContext(
61: root), request);
62:
63: assertEquals(404, response.getStatus());
64: String content = ((SimpleResponse) response).getContent();
65: assertSubString("doesn't exist", content);
66: assertSubString("Error Occured", content);
67: }
68:
69: public void testAddFailWhenPageAlreadyHasChild() throws Exception {
70: pageOne.addChildPage("SymLink");
71: request.addInput("linkName", "SymLink");
72: request.addInput("linkPath", "PageTwo");
73: Response response = responder.makeResponse(new FitNesseContext(
74: root), request);
75:
76: assertEquals(412, response.getStatus());
77: String content = ((SimpleResponse) response).getContent();
78: assertSubString("already has a child named SymLink", content);
79: assertSubString("Error Occured", content);
80: }
81:
82: private void checkRedirectToProperties(Response response) {
83: assertEquals(303, response.getStatus());
84: assertEquals(response.getHeader("Location"),
85: "PageOne?properties");
86: }
87: }
|