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.components;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.testutil.*;
07: import java.util.*;
08:
09: public class WhereUsedTest extends AbstractRegex implements
10: SearchObserver {
11: private WikiPage root;
12:
13: private InMemoryPage pageOne;
14:
15: private WikiPage pageTwo;
16:
17: private WikiPage pageThree;
18:
19: private WhereUsed whereUsed;
20:
21: private List hits = new ArrayList();
22:
23: private PageCrawler crawler;
24:
25: public void hit(WikiPage page) throws Exception {
26: hits.add(page);
27: }
28:
29: public void setUp() throws Exception {
30: root = InMemoryPage.makeRoot("RooT");
31: crawler = root.getPageCrawler();
32: pageOne = (InMemoryPage) crawler.addPage(root, PathParser
33: .parse("PageOne"), "this is page one ^ChildPage");
34: pageTwo = crawler
35: .addPage(root, PathParser.parse("PageTwo"),
36: "I am Page Two my brother is PageOne . SomeMissingPage");
37: pageThree = crawler.addPage(root,
38: PathParser.parse("PageThree"),
39: "This is !-PageThree-!, I Have \n!include PageTwo");
40: crawler.addPage(pageTwo, PathParser.parse("ChildPage"),
41: "I will be a virtual page to .PageOne ");
42:
43: whereUsed = new WhereUsed(root);
44: }
45:
46: public void testFindReferencingPages() throws Exception {
47: List resultList = whereUsed.findReferencingPages(pageOne);
48: assertEquals(2, resultList.size());
49: assertEquals(pageTwo, resultList.get(0));
50:
51: resultList = whereUsed.findReferencingPages(pageTwo);
52: assertEquals(1, resultList.size());
53:
54: resultList = whereUsed.findReferencingPages(pageThree);
55: assertEquals(0, resultList.size());
56: }
57:
58: public void testObserving() throws Exception {
59: clearPreviousSearchResults();
60: whereUsed.searchForReferencingPages(pageOne, this );
61: assertEquals(2, hits.size());
62: }
63:
64: public void testOnlyOneReferencePerPage() throws Exception {
65: WikiPage newPage = crawler
66: .addPage(root, PathParser.parse("NewPage"),
67: "one reference to PageThree. Two reference to PageThree");
68: List resultList = whereUsed.findReferencingPages(pageThree);
69: assertEquals(1, resultList.size());
70: assertEquals(newPage, resultList.get(0));
71: }
72:
73: public void testWordsNotFoundInPreprocessedText() throws Exception {
74: crawler.addPage(root, PathParser.parse("NewPage"),
75: "{{{ PageThree }}}");
76: List resultList = whereUsed.findReferencingPages(pageThree);
77: assertEquals(0, resultList.size());
78: }
79:
80: public void testDontLookForReferencesInVirtualPages()
81: throws Exception {
82: clearPreviousSearchResults();
83: FitNesseUtil.bindVirtualLinkToPage(pageOne, pageTwo);
84: whereUsed = new WhereUsed(pageOne);
85: whereUsed.searchForReferencingPages(pageOne, this );
86: assertEquals(0, hits.size());
87: }
88:
89: private void clearPreviousSearchResults() {
90: hits.clear();
91: }
92:
93: }
|