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 java.io.File;
006: import java.util.Arrays;
007: import java.util.Collections;
008: import java.util.Iterator;
009: import java.util.LinkedList;
010: import java.util.List;
011: import java.util.Set;
012:
013: import junit.framework.TestCase;
014: import fitnesse.util.FileUtil;
015:
016: public class FileSystemPageVersioningTest extends TestCase {
017: public FileSystemPage page;
018:
019: private VersionInfo firstVersion;
020:
021: private PageCrawler crawler;
022:
023: private WikiPage root;
024:
025: public void setUp() throws Exception {
026: root = FileSystemPage.makeRoot("testDir", "RooT");
027: crawler = root.getPageCrawler();
028: page = (FileSystemPage) crawler.addPage(root, PathParser
029: .parse("PageOne"), "original content");
030:
031: PageData data = page.getData();
032: firstVersion = page.commit(data);
033: }
034:
035: public void tearDown() throws Exception {
036: FileUtil.deleteFileSystemDirectory("testDir");
037: }
038:
039: public void XtestSave() throws Exception {
040: String dirPath = page.getFileSystemPath();
041: File dir = new File(dirPath);
042: String[] filenames = dir.list();
043:
044: List list = Arrays.asList(filenames);
045: assertTrue(list.contains(firstVersion + ".zip"));
046: }
047:
048: public void XtestLoad() throws Exception {
049: PageData data = page.getData();
050: data.setContent("new content");
051: VersionInfo version = page.commit(data);
052:
053: PageData loadedData = page.getDataVersion(version.getName());
054: assertEquals("original content", loadedData.getContent());
055: }
056:
057: public void XtestGetVersions() throws Exception {
058: Set versionNames = page.getData().getVersions();
059: assertEquals(1, versionNames.size());
060: assertTrue(versionNames.contains(firstVersion));
061: }
062:
063: public void testSubWikisDontInterfere() throws Exception {
064: crawler.addPage(page, PathParser.parse("SubPage"),
065: "sub page content");
066: try {
067: page.commit(page.getData());
068: } catch (Exception e) {
069: fail("this exception should not have been thrown: "
070: + e.getMessage());
071: }
072: }
073:
074: public void XtestTwoVersions() throws Exception {
075: PageData data = page.getData();
076: data.setContent("new content");
077: VersionInfo secondVersion = page.commit(data);
078: Set versionNames = page.getData().getVersions();
079: assertEquals(2, versionNames.size());
080: assertTrue(versionNames.contains(firstVersion));
081: assertTrue(versionNames.contains(secondVersion));
082: }
083:
084: public void XtestVersionsExpire() throws Exception {
085: PageVersionPruner.daysTillVersionsExpire = 3;
086: PageData data = page.makePageData();
087: Set versions = data.getVersions();
088: for (Iterator iterator = versions.iterator(); iterator
089: .hasNext();)
090: page.removeVersion(iterator.next().toString());
091:
092: data.setLastModificationTime(FileSystemPage.dateFormat().parse(
093: "20031213000000"));
094: page.makeVersion(data);
095: data.setLastModificationTime(FileSystemPage.dateFormat().parse(
096: "20031214000000"));
097: page.makeVersion(data);
098: data.setLastModificationTime(FileSystemPage.dateFormat().parse(
099: "20031215000000"));
100: page.makeVersion(data);
101: data.setLastModificationTime(FileSystemPage.dateFormat().parse(
102: "20031216000000"));
103: page.makeVersion(data);
104:
105: versions = page.makePageData().getVersions();
106: PageVersionPruner.pruneVersions(page, versions);
107: versions = page.makePageData().getVersions();
108: assertEquals(3, versions.size());
109:
110: List versionsList = new LinkedList(versions);
111: Collections.sort(versionsList);
112: assertTrue(versionsList.get(0).toString().endsWith(
113: "20031214000000"));
114: assertTrue(versionsList.get(1).toString().endsWith(
115: "20031215000000"));
116: assertTrue(versionsList.get(2).toString().endsWith(
117: "20031216000000"));
118: }
119:
120: public void testGetContent() throws Exception {
121: WikiPagePath alpha = PathParser.parse("AlphaAlpha");
122: WikiPage a = crawler.addPage(root, alpha, "a");
123:
124: PageData data = a.getData();
125: assertEquals("a", data.getContent());
126: }
127:
128: public void testReplaceContent() throws Exception {
129: WikiPagePath alpha = PathParser.parse("AlphaAlpha");
130: WikiPage page = crawler.addPage(root, alpha, "a");
131:
132: PageData data = page.getData();
133: data.setContent("b");
134: page.commit(data);
135: assertEquals("b", page.getData().getContent());
136: }
137:
138: public void testSetAttributes() throws Exception {
139: PageData data = root.getData();
140: data.setAttribute(WikiPage.ACTION_TEST, "true");
141: data.setAttribute(WikiPage.ACTION_SEARCH, "true");
142: root.commit(data);
143: assertTrue(root.getData().hasAttribute(WikiPage.ACTION_TEST));
144: assertTrue(root.getData().hasAttribute(WikiPage.ACTION_SEARCH));
145:
146: assertEquals("true", root.getData().getAttribute(
147: WikiPage.ACTION_TEST));
148: }
149:
150: public void XtestSimpleVersionTasks() throws Exception {
151: WikiPagePath path = PathParser.parse("MyPageOne");
152: WikiPage page = crawler.addPage(root, path, "old content");
153: PageData data = page.getData();
154: data.setContent("new content");
155: VersionInfo previousVersion = page.commit(data);
156:
157: data = page.getData();
158: Set versions = data.getVersions();
159: assertEquals(1, versions.size());
160: assertEquals(true, versions.contains(previousVersion));
161:
162: PageData loadedData = page.getDataVersion(previousVersion
163: .getName());
164: assertSame(page, loadedData.getWikiPage());
165: assertEquals("old content", loadedData.getContent());
166: }
167:
168: public void testUserNameIsInVersionName() throws Exception {
169: WikiPagePath testPagePath = PathParser.parse("TestPage");
170: WikiPage testPage = crawler.addPage(root, testPagePath,
171: "version1");
172:
173: PageData data = testPage.getData();
174: data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Aladdin");
175: VersionInfo record = testPage.commit(data);
176:
177: data = testPage.getData();
178: data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Joe");
179: record = testPage.commit(data);
180:
181: assertTrue(record.getName().startsWith("Aladdin"));
182: }
183:
184: public void testNoVersionException() throws Exception {
185: WikiPagePath pageOnePath = PathParser.parse("PageOne");
186: WikiPage page = crawler.addPage(root, pageOnePath,
187: "old content");
188: try {
189: page.getDataVersion("abc");
190: fail("a NoSuchVersionException should have been thrown");
191: } catch (NoSuchVersionException e) {
192: assertEquals("There is no version 'abc'", e.getMessage());
193: }
194: }
195: }
|