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 fitnesse.testutil.AbstractRegex;
006: import fitnesse.responders.run.*;
007:
008: import java.util.*;
009: import java.text.SimpleDateFormat;
010:
011: public class PageDataTest extends AbstractRegex {
012: public WikiPage page;
013:
014: private WikiPage root;
015:
016: private PageCrawler crawler;
017:
018: public void setUp() throws Exception {
019: root = InMemoryPage.makeRoot("RooT");
020: crawler = root.getPageCrawler();
021: page = crawler.addPage(root, PathParser.parse("PagE"),
022: "some content");
023: }
024:
025: public void tearDown() throws Exception {
026: }
027:
028: public void testVariablePreprocessing() throws Exception {
029: PageData d = new PageData(InMemoryPage.makeRoot("RooT"),
030: "!define x {''italic''}\n${x}\n");
031: String preprocessedText = d.getContent();
032: assertHasRegexp("''italic''", preprocessedText);
033: }
034:
035: public void testVariablesRenderedFirst() throws Exception {
036: String text = "!define x {''italics''}\n${x}";
037: WikiPage root = InMemoryPage.makeRoot("RooT");
038: WikiPage page = crawler.addPage(root, PathParser
039: .parse("SomePage"), text);
040: String html = page.getData().getHtml();
041: assertHasRegexp("''italics''", html);
042: assertHasRegexp("<i>italics</i>", html);
043: }
044:
045: public void testThatSpecialCharsAreNotEscapedTwice()
046: throws Exception {
047: PageData d = new PageData(new MockWikiPage(), "<b>");
048: String html = d.getHtml();
049: assertEquals("<b>", html);
050: }
051:
052: public void testLiteral() throws Exception {
053: WikiPage root = InMemoryPage.makeRoot("RooT");
054: WikiPage page = crawler.addPage(root, PathParser
055: .parse("LiteralPage"), "!-literal-!");
056: String renderedContent = page.getData().getHtml();
057: assertHasRegexp("literal", renderedContent);
058: assertDoesntHaveRegexp("!-literal-!", renderedContent);
059: }
060:
061: public void testClasspath() throws Exception {
062: WikiPage root = InMemoryPage.makeRoot("RooT");
063: WikiPage page = crawler.addPage(root, PathParser
064: .parse("ClassPath"), "!path 123\n!path abc\n");
065: List paths = page.getData().getClasspaths();
066: assertTrue(paths.contains("123"));
067: assertTrue(paths.contains("abc"));
068: }
069:
070: public void testGetFixtureNames() throws Exception {
071: WikiPage root = InMemoryPage.makeRoot("RooT");
072: WikiPage page = crawler
073: .addPage(
074: root,
075: PathParser.parse("PageName"),
076: "!fixture FixtureOne\r\nNot.A.Fixture\r\n!fixture FixtureTwo\n\n!fixture FixtureThree");
077: List fixtureNames = page.getData().getFixtureNames();
078: assertEquals(3, fixtureNames.size());
079: assertEquals("FixtureOne", fixtureNames.get(0));
080: assertEquals("FixtureTwo", fixtureNames.get(1));
081: assertEquals("FixtureThree", fixtureNames.get(2));
082: }
083:
084: public void testGetCrossReferences() throws Exception {
085: WikiPage root = InMemoryPage.makeRoot("RooT");
086: WikiPage page = crawler.addPage(root, PathParser
087: .parse("PageName"), "!xref XrefPage\r\n");
088: List xrefs = page.getData().getXrefPages();
089: assertEquals("XrefPage", xrefs.get(0));
090: }
091:
092: public void testDefaultAttributes() throws Exception {
093: WikiPage normalPage = crawler.addPage(root, PathParser
094: .parse("NormalPage"));
095: WikiPage testPage = crawler.addPage(root, PathParser
096: .parse("TestPage"));
097: WikiPage suitePage = crawler.addPage(root, PathParser
098: .parse("SuitePage"));
099: WikiPage suiteSetupPage = crawler.addPage(root, PathParser
100: .parse(SuiteResponder.SUITE_SETUP_NAME));
101: WikiPage suiteTearDownPage = crawler.addPage(root, PathParser
102: .parse(SuiteResponder.SUITE_TEARDOWN_NAME));
103:
104: PageData data = new PageData(normalPage);
105: assertTrue(data.hasAttribute(WikiPage.ACTION_EDIT));
106:
107: data = new PageData(testPage);
108: assertTrue(data.hasAttribute(WikiPage.ACTION_TEST));
109: assertFalse(data.hasAttribute(WikiPage.ACTION_SUITE));
110:
111: data = new PageData(suitePage);
112: assertFalse(data.hasAttribute(WikiPage.ACTION_TEST));
113: assertTrue(data.hasAttribute(WikiPage.ACTION_SUITE));
114:
115: data = new PageData(suiteSetupPage);
116: assertFalse(data.hasAttribute(WikiPage.ACTION_SUITE));
117:
118: data = new PageData(suiteTearDownPage);
119: assertFalse(data.hasAttribute(WikiPage.ACTION_SUITE));
120: }
121:
122: public void testAttributesAreTruelyCopiedInCopyConstructor()
123: throws Exception {
124: PageData data = root.getData();
125: data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Joe");
126: PageData newData = new PageData(data);
127: newData.setAttribute(WikiPage.LAST_MODIFYING_USER, "Jane");
128:
129: assertEquals("Joe", data
130: .getAttribute(WikiPage.LAST_MODIFYING_USER));
131: }
132:
133: public void testLastModificationTime() throws Exception {
134: SimpleDateFormat format = PageData.makeVersionTimeFormat();
135: PageData data = new PageData(root);
136: assertEquals(format.format(new Date()), format.format(data
137: .getLastModificationTime()));
138: Date date = format.parse("20040101000001");
139: data.setLastModificationTime(date);
140: assertEquals("20040101000001", data.getProperties().get(
141: "LastModified"));
142: assertEquals(date, data.getLastModificationTime());
143: }
144: }
|