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.html;
004:
005: import fitnesse.FitNesseContext;
006: import fitnesse.runner.SuiteExporter;
007: import fitnesse.testutil.AbstractRegex;
008: import fitnesse.util.FileUtil;
009: import fitnesse.wiki.InMemoryPage;
010: import fitnesse.wiki.PageCrawler;
011: import fitnesse.wiki.PageData;
012: import fitnesse.wiki.PathParser;
013: import fitnesse.wiki.WikiPage;
014: import fitnesse.wiki.WikiPagePath;
015:
016: public class StiqTestTest extends AbstractRegex {
017: private static final String TEST_NAME = "TypicalTest";
018: private static final String SUITE_PAGE_NAME = "SuiTe";
019: private static final String TEST_DIR = "testDir";
020: private WikiPage root;
021: private PageCrawler crawler;
022: private String TITLE_BEGIN = "<title>";
023: private String TITLE_END = "</title>";
024:
025: public void setUp() throws Exception {
026: root = InMemoryPage.makeRoot("RooT");
027: crawler = root.getPageCrawler();
028: }
029:
030: public void testWrite() throws Exception {
031: String pagePath = SUITE_PAGE_NAME + "." + TEST_NAME;
032: WikiPagePath wikiPagePath = PathParser.parse(pagePath);
033: StiqTest stiqTest = new StiqTest(getTypicalTestContext(),
034: wikiPagePath);
035:
036: FileUtil.makeDir(TEST_DIR);
037: String outputFilePath = TEST_DIR + "/" + pagePath
038: + SuiteExporter.FILE_EXTENSION;
039:
040: stiqTest.writeHtml(TEST_DIR);
041: String fileContent = FileUtil.getFileContent(outputFilePath);
042: String pageTitle = TITLE_BEGIN + pagePath + "</title>";
043: assertSubString(pageTitle, fileContent);
044: FileUtil.deleteFileSystemDirectory(TEST_DIR);
045: }
046:
047: public void testGetWikiPageName() throws Exception {
048: String pagePath = SUITE_PAGE_NAME + "." + TEST_NAME;
049: WikiPagePath wikiPagePath = PathParser.parse(pagePath);
050:
051: StiqTest stiqTest = new StiqTest(getTypicalTestContext(),
052: wikiPagePath);
053: assertEquals(pagePath, stiqTest.getWikiPageName());
054: }
055:
056: public void testGetHtml() throws Exception {
057: String pagePath = SUITE_PAGE_NAME + "." + TEST_NAME;
058: WikiPagePath wikiPagePath = PathParser.parse(pagePath);
059:
060: StiqTest stiqTest = new StiqTest(getTypicalTestContext(),
061: wikiPagePath);
062: String testHtml = stiqTest.getHtml();
063: String pageTitle = TITLE_BEGIN + pagePath + TITLE_END;
064: assertSubString(pageTitle, testHtml);
065: }
066:
067: public void testPrepareHtmlForExport() throws Exception {
068: String pagePath = SUITE_PAGE_NAME + "." + TEST_NAME;
069: WikiPagePath wikiPagePath = PathParser.parse(pagePath);
070: StiqTest stiqTest = new StiqTest(getTypicalTestContext(),
071: wikiPagePath);
072:
073: FileUtil.makeDir(TEST_DIR);
074: String outputFilePath = TEST_DIR + "/" + pagePath
075: + SuiteExporter.FILE_EXTENSION;
076: stiqTest.writeHtml(TEST_DIR);
077: String testContents = FileUtil.getFileContent(outputFilePath);
078:
079: // Verify the stuff we expect is there
080: String pageTitle = TITLE_BEGIN + pagePath + TITLE_END;
081: assertSubString(pageTitle, testContents);
082:
083: // All the stuff we don't want should be gone
084: String docType = "<!DOCTYPE HTML PUBLIC ";
085: assertNotSubString(docType, testContents);
086:
087: String linkTags = "<link rel=\"stylesheet";
088: assertNotSubString(linkTags, testContents);
089:
090: String scriptTags = "<script src=\"/files/";
091: assertNotSubString(scriptTags, testContents);
092:
093: String actionsStart = "<div class=\"actions\"";
094: assertNotSubString(actionsStart, testContents);
095:
096: String actionsEnd = "id=\"RefreshTool\" class=\"toolbarImage\"/></a></div>";
097: assertNotSubString(actionsEnd, testContents);
098:
099: FileUtil.deleteFileSystemDirectory(TEST_DIR);
100: }
101:
102: //
103: // Helper methods
104: //
105:
106: private FitNesseContext getTypicalTestContext() throws Exception {
107: String parentName = SUITE_PAGE_NAME;
108: WikiPage parentOne = crawler.addPage(root, PathParser
109: .parse(parentName), "!suite");
110: setSTIQTestProperty(crawler.addPage(parentOne, PathParser
111: .parse(TEST_NAME), "a test"));
112: setSTIQTestProperty(crawler.addPage(parentOne, PathParser
113: .parse("ChildTwo"), "a test"));
114: crawler.addPage(parentOne, PathParser.parse("ChildThree"),
115: "nothing");
116: return new FitNesseContext(root);
117: }
118:
119: private WikiPage setSTIQTestProperty(WikiPage page)
120: throws Exception {
121: PageData pageDataToModify = page.getData();
122: pageDataToModify.getProperties().set(WikiPage.STIQ_TEST);
123: page.commit(pageDataToModify);
124: assertTrue(page.isSTIQTest());
125: return page;
126: }
127: }
|