001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.responders.editing;
004:
005: import fitnesse.http.*;
006: import fitnesse.wiki.*;
007: import fitnesse.*;
008: import fitnesse.testutil.*;
009: import java.util.List;
010:
011: public class SavePropertiesResponderTest extends RegexTest {
012: private WikiPage root;
013:
014: private MockRequest request;
015:
016: private WikiPage page;
017:
018: private PageCrawler crawler;
019:
020: private VirtualCouplingExtension extension;
021:
022: private WikiPage linker;
023:
024: public void setUp() throws Exception {
025: root = InMemoryPage.makeRoot("RooT");
026: crawler = root.getPageCrawler();
027: }
028:
029: private void createRequest() throws Exception {
030: page = crawler.addPage(root, PathParser.parse("PageOne"));
031:
032: request = new MockRequest();
033: request.addInput("Test", "on");
034: request.addInput("Properties", "on");
035: request.addInput("Search", "on");
036: request.addInput("RecentChanges", "on");
037: request.addInput(WikiPage.SECURE_READ, "on");
038: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
039: "http://www.fitnesse.org");
040: request.addInput("Suites", "Suite A, Suite B");
041: request.setResource("PageOne");
042: }
043:
044: public void tearDown() throws Exception {
045: }
046:
047: public void testClearChildrenWhenVWisCleared() throws Exception {
048: createSimpleVirtualLink();
049:
050: // new request to get rid of the virtual wiki link
051: SavePropertiesResponder responder = new SavePropertiesResponder();
052: request = new MockRequest();
053: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, "");
054: request.setResource("LinkerPage");
055: responder.makeResponse(new FitNesseContext(root), request);
056: assertEquals(0, linker.getChildren().size());
057: }
058:
059: private WikiPage createSimpleVirtualLink() throws Exception {
060: WikiPage linkee = crawler.addPage(root, PathParser
061: .parse("LinkeePage"));
062: crawler.addPage(linkee, PathParser.parse("ChildPageOne"));
063: WikiPage linkee2 = crawler.addPage(root, PathParser
064: .parse("LinkeePageTwo"));
065: crawler.addPage(linkee2, PathParser.parse("ChildPageTwo"));
066: linker = crawler.addPage(root, PathParser.parse("LinkerPage"));
067: FitNesseUtil.bindVirtualLinkToPage(linker, linkee);
068:
069: extension = (VirtualCouplingExtension) linker
070: .getExtension(VirtualCouplingExtension.NAME);
071: List children = extension.getVirtualCoupling().getChildren();
072: assertEquals(1, children.size());
073: WikiPage child = (WikiPage) children.get(0);
074: assertEquals("ChildPageOne", child.getName());
075: return linker;
076: }
077:
078: public void testClearChildrenChangingVW() throws Exception {
079: createSimpleVirtualLink();
080: assertTrue(!(extension.getVirtualCoupling() instanceof NullVirtualCouplingPage));
081:
082: // new request to get rid of the virtual wiki link
083: SavePropertiesResponder responder = new SavePropertiesResponder();
084: request = new MockRequest();
085: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
086: "http://localhost:" + FitNesseUtil.port
087: + "/LinkeePageTwo");
088: request.setResource("LinkerPage");
089: responder.makeResponse(new FitNesseContext(root), request);
090:
091: assertTrue(extension.getVirtualCoupling() instanceof NullVirtualCouplingPage);
092: }
093:
094: public void testResponse() throws Exception {
095: createRequest();
096:
097: Responder responder = new SavePropertiesResponder();
098: Response response = responder.makeResponse(new FitNesseContext(
099: root), request);
100:
101: PageData data = page.getData();
102: assertEquals(
103: "http://www.fitnesse.org",
104: data
105: .getAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE));
106: assertTrue(data.hasAttribute("Test"));
107: assertTrue(data.hasAttribute("Properties"));
108: assertTrue(data.hasAttribute("Search"));
109: assertFalse(data.hasAttribute("Edit"));
110: assertTrue(data.hasAttribute("RecentChanges"));
111: assertTrue(data.hasAttribute(WikiPage.SECURE_READ));
112: assertFalse(data.hasAttribute(WikiPage.SECURE_WRITE));
113: assertEquals("Suite A, Suite B", data.getAttribute("Suites"));
114:
115: assertEquals(303, response.getStatus());
116: assertEquals("PageOne", response.getHeader("Location"));
117: }
118:
119: }
|