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 AbstractRegex {
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(WikiPage.ACTION_TEST, "on");
034: request.addInput(WikiPage.ACTION_PROPERTIES, "on");
035: request.addInput(WikiPage.ACTION_SEARCH, "on");
036: request.addInput(WikiPage.ACTION_RECENT_CHANGES, "on");
037: request.addInput(WikiPage.SECURE_READ, "on");
038: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
039: "http://www.fitnesse.org");
040: request.setResource("PageOne");
041: }
042:
043: public void tearDown() throws Exception {
044: }
045:
046: public void testClearChildrenWhenVWisCleared() throws Exception {
047: createSimpleVirtualLink();
048:
049: // new request to get rid of the virtual wiki link
050: SavePropertiesResponder responder = new SavePropertiesResponder();
051: request = new MockRequest();
052: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, "");
053: request.setResource("LinkerPage");
054: responder.makeResponse(new FitNesseContext(root), request);
055: assertEquals(0, linker.getChildren().size());
056: }
057:
058: private WikiPage createSimpleVirtualLink() throws Exception {
059: WikiPage linkee = crawler.addPage(root, PathParser
060: .parse("LinkeePage"));
061: crawler.addPage(linkee, PathParser.parse("ChildPageOne"));
062: WikiPage linkee2 = crawler.addPage(root, PathParser
063: .parse("LinkeePageTwo"));
064: crawler.addPage(linkee2, PathParser.parse("ChildPageTwo"));
065: linker = crawler.addPage(root, PathParser.parse("LinkerPage"));
066: FitNesseUtil.bindVirtualLinkToPage(linker, linkee);
067:
068: extension = (VirtualCouplingExtension) linker
069: .getExtension(VirtualCouplingExtension.NAME);
070: List children = extension.getVirtualCoupling().getChildren();
071: assertEquals(1, children.size());
072: WikiPage child = (WikiPage) children.get(0);
073: assertEquals("ChildPageOne", child.getName());
074: return linker;
075: }
076:
077: public void testClearChildrenChangingVW() throws Exception {
078: createSimpleVirtualLink();
079: assertTrue(!(extension.getVirtualCoupling() instanceof NullVirtualCouplingPage));
080:
081: // new request to get rid of the virtual wiki link
082: SavePropertiesResponder responder = new SavePropertiesResponder();
083: request = new MockRequest();
084: request.addInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
085: "http://localhost:" + FitNesseUtil.port
086: + "/LinkeePageTwo");
087: request.setResource("LinkerPage");
088: responder.makeResponse(new FitNesseContext(root), request);
089:
090: assertTrue(extension.getVirtualCoupling() instanceof NullVirtualCouplingPage);
091: }
092:
093: public void testResponse() throws Exception {
094: createRequest();
095:
096: Responder responder = new SavePropertiesResponder();
097: Response response = responder.makeResponse(new FitNesseContext(
098: root), request);
099:
100: PageData data = page.getData();
101: assertEquals(
102: "http://www.fitnesse.org",
103: data
104: .getAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE));
105: assertTrue(data.hasAttribute(WikiPage.ACTION_TEST));
106: assertTrue(data.hasAttribute(WikiPage.ACTION_PROPERTIES));
107: assertTrue(data.hasAttribute(WikiPage.ACTION_SEARCH));
108: assertFalse(data.hasAttribute(WikiPage.ACTION_EDIT));
109: assertTrue(data.hasAttribute(WikiPage.ACTION_RECENT_CHANGES));
110: assertTrue(data.hasAttribute(WikiPage.SECURE_READ));
111: assertFalse(data.hasAttribute(WikiPage.SECURE_WRITE));
112:
113: assertEquals(303, response.getStatus());
114: assertEquals("PageOne", response.getHeader("Location"));
115: }
116:
117: }
|