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.components;
004:
005: import fitnesse.testutil.AbstractRegex;
006: import fitnesse.wiki.*;
007:
008: public class PageReferenceRenamerTest extends AbstractRegex {
009: WikiPage root;
010:
011: WikiPage subWiki;
012:
013: WikiPage subWiki_pageOne;
014:
015: WikiPage subWiki_pageTwo;
016:
017: WikiPage subWiki_pageTwo_pageTwoChild;
018:
019: PageReferenceRenamer renamer;
020:
021: private PageCrawler crawler;
022:
023: public void setUp() throws Exception {
024: root = InMemoryPage.makeRoot("RooT");
025: crawler = root.getPageCrawler();
026: subWiki = crawler
027: .addPage(root, PathParser.parse("SubWiki"), "");
028: renamer = new PageReferenceRenamer(root);
029: subWiki_pageTwo = crawler.addPage(subWiki, PathParser
030: .parse("PageTwo"), "");
031: subWiki_pageTwo_pageTwoChild = crawler.addPage(subWiki_pageTwo,
032: PathParser.parse("PageTwoChild"), "");
033: }
034:
035: public void testReferencesOnPageOne_1() throws Exception {
036: checkChangesOnPageOne("Stuff PageTwo Stuff\n",
037: "Stuff PageThree Stuff\n");
038: }
039:
040: public void testReferencesOnPageOne_2() throws Exception {
041: checkChangesOnPageOne("Stuff !-PageTwo-! Stuff\n",
042: "Stuff !-PageTwo-! Stuff\n");
043: }
044:
045: public void testReferencesOnPageOne_3() throws Exception {
046: checkChangesOnPageOne("Stuff PageOne.PageTwo Stuff\n",
047: "Stuff PageOne.PageTwo Stuff\n");
048: }
049:
050: public void testReferencesOnPageOne_4() throws Exception {
051: checkChangesOnPageOne(
052: "Stuff .SubWiki.PageTwo.PageTwoChild Stuff\n",
053: "Stuff .SubWiki.PageThree.PageTwoChild Stuff\n");
054: }
055:
056: public void testReferencesOnPageOne_5() throws Exception {
057: checkChangesOnPageOne("Stuff ^PageTwo Stuff\n",
058: "Stuff ^PageTwo Stuff\n");
059: }
060:
061: public void testReferencesOnPageOne_6() throws Exception {
062: checkChangesOnPageOne("# Stuff PageTwo Stuff\n",
063: "# Stuff PageTwo Stuff\n");
064: }
065:
066: public void testReferencesOnPageOne_7() throws Exception {
067: checkChangesOnPageOne("{{{Stuff PageTwo Stuff}}}\n",
068: "{{{Stuff PageTwo Stuff}}}\n");
069: }
070:
071: public void testReferencesOnPageOne_8() throws Exception {
072: checkChangesOnPageOne("Stuff .SubWiki.PageTwo Stuff\n",
073: "Stuff .SubWiki.PageThree Stuff\n");
074: }
075:
076: public void testReferencesOnPageOne_9() throws Exception {
077: checkChangesOnPageOne("Stuff .SubWiki.PageTwo.NoPage Stuff\n",
078: "Stuff .SubWiki.PageThree.NoPage Stuff\n");
079: }
080:
081: public void testTestReferencesToSubWiki_1() throws Exception {
082: PageData data = subWiki.getData();
083: data.setContent("Stuff ^PageTwo Stuff\n");
084: subWiki.commit(data);
085:
086: renamer.renameReferences(subWiki_pageTwo, "PageThree");
087: String updatedSubWikiContent = subWiki.getData().getContent();
088: assertEquals("Stuff ^PageThree Stuff\n", updatedSubWikiContent);
089: }
090:
091: public void testTestReferencesToSubWiki_2() throws Exception {
092: PageData data = subWiki.getData();
093: data.setContent("Stuff ^PageTwo.DeepPage Stuff\n");
094: subWiki.commit(data);
095:
096: renamer.renameReferences(subWiki_pageTwo, "PageThree");
097: String updatedSubWikiContent = subWiki.getData().getContent();
098: assertEquals("Stuff ^PageThree.DeepPage Stuff\n",
099: updatedSubWikiContent);
100: }
101:
102: private void checkChangesOnPageOne(String beforeText,
103: String expectedAfterText) throws Exception {
104: subWiki_pageOne = crawler.addPage(subWiki, PathParser
105: .parse("PageOne"), beforeText);
106: renamer.renameReferences(subWiki_pageTwo, "PageThree");
107: subWiki_pageOne = subWiki.getChildPage("PageOne");
108: String updatedPageOneContent = subWiki_pageOne.getData()
109: .getContent();
110: assertEquals(expectedAfterText, updatedPageOneContent);
111: }
112:
113: public void testRenameParentPage() throws Exception {
114: PageData pageTwoChildData = subWiki_pageTwo_pageTwoChild
115: .getData();
116: pageTwoChildData.setContent("gunk .SubWiki.PageTwo gunk");
117: subWiki_pageTwo_pageTwoChild.commit(pageTwoChildData);
118: renamer.renameReferences(subWiki_pageTwo, "PageThree");
119: String updatedContent = subWiki_pageTwo_pageTwoChild.getData()
120: .getContent();
121: assertEquals("gunk .SubWiki.PageThree gunk", updatedContent);
122: }
123:
124: public void testRenameParentWithReferenceOnSibling()
125: throws Exception {
126: WikiPage pageOne = crawler.addPage(subWiki, PathParser
127: .parse("PageOne"), "gunk ^SubPage gunk");
128: renamer.renameReferences(subWiki, "RenamedSubWiki");
129: String updatedContent = pageOne.getData().getContent();
130: assertEquals("gunk ^SubPage gunk", updatedContent);
131: }
132:
133: public void testRenameParentWithSubPageReferenceOnSibling()
134: throws Exception {
135: WikiPage pageOne = crawler.addPage(subWiki, PathParser
136: .parse("PageOne"), "gunk PageTwo gunk");
137: renamer.renameReferences(subWiki, "RenamedSubWiki");
138: String updatedContent = pageOne.getData().getContent();
139: assertEquals("gunk PageTwo gunk", updatedContent);
140: }
141:
142: public void testRenameSiblingOfRoot() throws Exception {
143: WikiPage source = crawler.addPage(root, PathParser
144: .parse("SourcePage"), "gunk TargetPage gunk");
145: WikiPage target = crawler.addPage(root, PathParser
146: .parse("TargetPage"));
147: renamer.renameReferences(target, "RenamedPage");
148: String updatedSourceContent = source.getData().getContent();
149: assertEquals("gunk RenamedPage gunk", updatedSourceContent);
150: }
151:
152: public void testRenameSubpageOfRoot() throws Exception {
153: WikiPage source = crawler.addPage(root, PathParser
154: .parse("SourcePage"), "gunk ^TargetPage gunk");
155: WikiPage target = crawler.addPage(source, PathParser
156: .parse("TargetPage"));
157: renamer.renameReferences(target, "RenamedPage");
158: String updatedSourceContent = source.getData().getContent();
159: assertEquals("gunk ^RenamedPage gunk", updatedSourceContent);
160: }
161:
162: public void testImageNotChanged() throws Exception {
163: final String IMAGE_WIDGET = "!img http://PageTwo.jpg";
164: checkChangesOnPageOne(IMAGE_WIDGET, IMAGE_WIDGET);
165: }
166:
167: public void testLinkNotChanged() throws Exception {
168: final String LINK_WIDGET = "http://PageTwo";
169: checkChangesOnPageOne(LINK_WIDGET, LINK_WIDGET);
170: }
171:
172: public void testPathNotChanged() throws Exception {
173: final String PATH_WIDGET = "!path PageTwo";
174: checkChangesOnPageOne(PATH_WIDGET, PATH_WIDGET);
175: }
176:
177: public void testFixtureNotChanged() throws Exception {
178: final String FIXTURE_WIDGET = "!fixture PageTwo";
179: checkChangesOnPageOne(FIXTURE_WIDGET, FIXTURE_WIDGET);
180: }
181:
182: public void testAliasTagNotChanged() throws Exception {
183: final String ALIAS_LINK = "[[PageTwo][MyPageTwo]]";
184: checkChangesOnPageOne(ALIAS_LINK, ALIAS_LINK);
185: }
186:
187: public void testAliasLinkRenamed() throws Exception {
188: checkChangesOnPageOne("gunk [[gunk][PageTwo]] gunk",
189: "gunk [[gunk][PageThree]] gunk");
190: }
191:
192: public void testAliasLinWithLiteralDoesntGetCorrupted()
193: throws Exception {
194: checkChangesOnPageOne("gunk [[!-gunk-!][PageTwo]] gunk",
195: "gunk [[!-gunk-!][PageThree]] gunk");
196: }
197:
198: public void testXrefWidgetRenamed() throws Exception {
199: checkChangesOnPageOne("!see PageTwo", "!see PageThree");
200: }
201: }
|