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.wiki;
004:
005: import junit.framework.*;
006: import fitnesse.testutil.*;
007: import java.util.List;
008:
009: public class VirtualCouplingExtensionTest extends TestCase {
010: public WikiPage root;
011:
012: public BaseWikiPage page1;
013:
014: public WikiPage page2;
015:
016: private PageCrawler crawler;
017:
018: public void setUp() throws Exception {
019: root = InMemoryPage.makeRoot("RooT");
020: crawler = root.getPageCrawler();
021: FitNesseUtil.startFitnesse(root);
022:
023: page2 = crawler.addPage(root, PathParser.parse("PageTwo"),
024: "page two");
025: crawler.addPage(page2, PathParser.parse("PageTwoChild"),
026: "page two child");
027: page1 = (BaseWikiPage) crawler.addPage(root, PathParser
028: .parse("PageOne"), "page one content\n!contents\n");
029: crawler.addPage(page1, PathParser.parse("SomeOtherPage"),
030: "some other page");
031:
032: setVirtualWiki(page1, "http://localhost:" + FitNesseUtil.port
033: + "/PageTwo");
034: }
035:
036: public static void setVirtualWiki(WikiPage page,
037: String virtualWikiURL) throws Exception {
038: PageData data = page.getData();
039: data.setAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE,
040: virtualWikiURL);
041: page.commit(data);
042: }
043:
044: public void tearDown() throws Exception {
045: FitNesseUtil.stopFitnesse();
046: }
047:
048: public void testGetChildren() throws Exception {
049: List children = page1.getChildren();
050: assertEquals(1, children.size());
051: assertEquals("SomeOtherPage", ((WikiPage) children.get(0))
052: .getName());
053:
054: VirtualCouplingExtension extension = (VirtualCouplingExtension) page1
055: .getExtension(VirtualCouplingExtension.NAME);
056: children = extension.getVirtualCoupling().getChildren();
057: assertEquals(1, children.size());
058: assertTrue(children.get(0) instanceof ProxyPage);
059: assertEquals("PageTwoChild", ((WikiPage) children.get(0))
060: .getName());
061: }
062:
063: public void testNewProxyChildrenAreFound() throws Exception {
064: CachingPage.cacheTime = 0;
065: BaseWikiPage realChild = (BaseWikiPage) page2
066: .getChildPage("PageTwoChild");
067:
068: PageCrawler crawler = page2.getPageCrawler();
069: crawler.setDeadEndStrategy(new VirtualEnabledPageCrawler());
070: ProxyPage childProxy = (ProxyPage) crawler.getPage(page1,
071: PathParser.parse("PageTwoChild"));
072: assertNull(childProxy.getChildPage("AnotherChild"));
073:
074: crawler.addPage(realChild, PathParser.parse("AnotherChild"),
075: "another child");
076: assertNotNull(childProxy.getChildPage("AnotherChild"));
077: }
078:
079: public void testProxyChildrenAreFoundOnStartUp() throws Exception {
080: WikiPage page3 = crawler.addPage(root, PathParser
081: .parse("PageThree"), "page three content");
082: setVirtualWiki(page3, "http://localhost:" + FitNesseUtil.port
083: + "/PageTwo");
084:
085: assertTrue(page3.hasExtension(VirtualCouplingExtension.NAME));
086:
087: VirtualCouplingExtension extension = (VirtualCouplingExtension) page3
088: .getExtension(VirtualCouplingExtension.NAME);
089: List children = extension.getVirtualCoupling().getChildren();
090: assertEquals(1, children.size());
091: assertEquals("PageTwoChild", ((WikiPage) children.get(0))
092: .getName());
093: }
094:
095: // FIXME
096: public void XtestGetChildrenOnlyAsksOnce() throws Exception {
097: CachingPage.cacheTime = 10000;
098: ProxyPage.retrievalCount = 0;
099: SimpleCachinePage page = new SimpleCachinePage("RooT", null);
100: setVirtualWiki(page, "http://localhost:" + FitNesseUtil.port
101: + "/PageTwo");
102: VirtualCouplingExtension extension = (VirtualCouplingExtension) page
103: .getExtension(VirtualCouplingExtension.NAME);
104: extension.getVirtualCoupling().getChildren();
105: assertEquals(1, ProxyPage.retrievalCount);
106: }
107:
108: public void testNoNastyExceptionIsThrownWhenVirutalChildrenAreLoaded()
109: throws Exception {
110: WikiPage page3 = crawler.addPage(root, PathParser
111: .parse("PageThree"), "page three content");
112: setVirtualWiki(page3, "http://google.com/SomePage");
113: try {
114: VirtualCouplingExtension extension = (VirtualCouplingExtension) page3
115: .getExtension(VirtualCouplingExtension.NAME);
116: extension.getVirtualCoupling().getChildren();
117: assertNotNull(page3.getChildPage("VirtualWikiNetworkError"));
118: } catch (Exception e) {
119: e.printStackTrace();
120: fail("an exception was thrown");
121: }
122: }
123:
124: }
|