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.wiki;
04:
05: import junit.framework.TestCase;
06: import java.util.List;
07:
08: public class SymbolicPageTest extends TestCase {
09: private PageCrawler crawler;
10:
11: private WikiPage root;
12:
13: private WikiPage pageOne;
14:
15: private WikiPage pageTwo;
16:
17: private SymbolicPage symPage;
18:
19: public void setUp() throws Exception {
20: root = InMemoryPage.makeRoot("RooT");
21: crawler = root.getPageCrawler();
22: pageOne = crawler.addPage(root, PathParser.parse("PageOne"),
23: "page one");
24: pageTwo = crawler.addPage(root, PathParser.parse("PageTwo"),
25: "page two");
26:
27: symPage = new SymbolicPage("SymPage", pageOne, pageTwo);
28: }
29:
30: public void testCreation() throws Exception {
31: assertEquals("SymPage", symPage.getName());
32: }
33:
34: public void testLinkage() throws Exception {
35: assertSame(pageOne, symPage.getRealPage());
36: }
37:
38: public void testData() throws Exception {
39: PageData data = symPage.getData();
40: assertEquals("page one", data.getContent());
41: assertSame(symPage, data.getWikiPage());
42: }
43:
44: public void testCommit() throws Exception {
45: PageData data = symPage.getData();
46: data.setContent("new content");
47: symPage.commit(data);
48:
49: data = pageOne.getData();
50: assertEquals("new content", data.getContent());
51:
52: data = symPage.getData();
53: assertEquals("new content", data.getContent());
54: }
55:
56: public void testGetChild() throws Exception {
57: WikiPage childPage = crawler.addPage(pageOne, PathParser
58: .parse("ChildPage"), "child page");
59: WikiPage page = symPage.getChildPage("ChildPage");
60: assertNotNull(page);
61: assertEquals(SymbolicPage.class, page.getClass());
62: SymbolicPage symChild = (SymbolicPage) page;
63: assertSame(childPage, symChild.getRealPage());
64: }
65:
66: public void testGetChildren() throws Exception {
67: crawler.addPage(pageOne, PathParser.parse("ChildOne"),
68: "child one");
69: crawler.addPage(pageOne, PathParser.parse("ChildTwo"),
70: "child two");
71: List children = symPage.getChildren();
72: assertEquals(2, children.size());
73: assertEquals(SymbolicPage.class, children.get(0).getClass());
74: assertEquals(SymbolicPage.class, children.get(1).getClass());
75: }
76:
77: public void testCyclicSymbolicLinks() throws Exception {
78: PageData data = pageOne.getData();
79: data.getProperties().addSymbolicLink("SymTwo",
80: PathParser.parse("PageTwo"));
81: pageOne.commit(data);
82:
83: data = pageTwo.getData();
84: data.getProperties().addSymbolicLink("SymOne",
85: PathParser.parse("PageOne"));
86: pageTwo.commit(data);
87:
88: WikiPage deepPage = crawler.getPage(root, PathParser
89: .parse("PageOne.SymTwo.SymOne.SymTwo.SymOne.SymTwo"));
90: List children = deepPage.getChildren();
91: assertEquals(1, children.size());
92: }
93: }
|