001: package com.ecyrd.jspwiki.render;
002:
003: import java.util.Properties;
004:
005: import junit.framework.Test;
006: import junit.framework.TestCase;
007: import junit.framework.TestSuite;
008:
009: import org.apache.commons.lang.time.StopWatch;
010:
011: import com.ecyrd.jspwiki.TestEngine;
012: import com.ecyrd.jspwiki.WikiContext;
013: import com.ecyrd.jspwiki.WikiPage;
014: import com.ecyrd.jspwiki.parser.MarkupParser;
015: import com.ecyrd.jspwiki.parser.WikiDocument;
016:
017: public class RenderingManagerTest extends TestCase {
018: RenderingManager m_manager;
019: TestEngine m_engine;
020:
021: protected void setUp() throws Exception {
022: Properties props = new Properties();
023: props.load(TestEngine.findTestProperties());
024:
025: m_engine = new TestEngine(props);
026:
027: m_manager = new RenderingManager();
028: m_manager.initialize(m_engine, props);
029: }
030:
031: protected void tearDown() throws Exception {
032: m_engine.deletePage("TestPage");
033: }
034:
035: /**
036: * Tests the relative speed of the DOM cache with respect to
037: * page being parsed every single time.
038: * @throws Exception
039: */
040: public void testCache() throws Exception {
041: m_engine.saveText("TestPage", TEST_TEXT);
042:
043: StopWatch sw = new StopWatch();
044:
045: System.out.println("DOM cache speed test:");
046: sw.start();
047:
048: for (int i = 0; i < 100; i++) {
049: WikiPage page = m_engine.getPage("TestPage");
050: String pagedata = m_engine.getPureText(page);
051:
052: WikiContext context = new WikiContext(m_engine, page);
053:
054: MarkupParser p = m_manager.getParser(context, pagedata);
055:
056: WikiDocument d = p.parse();
057:
058: String html = m_manager.getHTML(context, d);
059: assertNotNull("noncached got null response", html);
060: }
061:
062: sw.stop();
063: System.out.println(" Nocache took " + sw);
064:
065: long nocachetime = sw.getTime();
066:
067: sw.reset();
068: sw.start();
069:
070: for (int i = 0; i < 100; i++) {
071: WikiPage page = m_engine.getPage("TestPage");
072: String pagedata = m_engine.getPureText(page);
073:
074: WikiContext context = new WikiContext(m_engine, page);
075:
076: String html = m_manager.getHTML(context, pagedata);
077:
078: assertNotNull("cached got null response", html);
079: }
080:
081: sw.stop();
082: System.out.println(" Cache took " + sw);
083:
084: long speedup = nocachetime / sw.getTime();
085: System.out.println(" Approx speedup: " + speedup + "x");
086: }
087:
088: public static Test suite() {
089: TestSuite suite = new TestSuite(RenderingManagerTest.class);
090:
091: return suite;
092: }
093:
094: private static final String TEST_TEXT = "Please ''check [RecentChanges].\n"
095: + "\n"
096: + "Testing. fewfwefe\n"
097: + "\n"
098: + "CHeck [testpage]\n"
099: + "\n"
100: + "More testing.\n"
101: + "dsadsadsa''\n"
102: + "Is this {{truetype}} or not?\n"
103: + "What about {{{This}}}?\n"
104: + "How about {{this?\n"
105: + "\n"
106: + "{{{\n"
107: + "{{text}}\n"
108: + "}}}\n"
109: + "goo\n"
110: + "\n"
111: + "<b>Not bold</b>\n"
112: + "\n"
113: + "motto\n"
114: + "\n"
115: + "* This is a list which we\n"
116: + "shall continue on a other line.\n"
117: + "* There is a list item here.\n"
118: + "* Another item.\n"
119: + "* More stuff, which continues\n"
120: + "on a second line. And on\n"
121: + "a third line as well.\n"
122: + "And a fourth line.\n"
123: + "* Third item.\n"
124: + "\n"
125: + "Foobar.\n"
126: + "\n"
127: + "----\n"
128: + "\n"
129: + "!!!Really big heading\n"
130: + "Text.\n"
131: + "!! Just a normal heading [with a hyperlink|Main]\n"
132: + "More text.\n"
133: + "!Just a small heading.\n"
134: + "\n"
135: + "This should be __bold__ text.\n"
136: + "\n"
137: + "__more bold text continuing\n"
138: + "on the next line.__\n"
139: + "\n"
140: + "__more bold text continuing\n"
141: + "\n"
142: + "on the next paragraph.__\n"
143: + "\n"
144: + "\n"
145: + "This should be normal.\n"
146: + "\n"
147: + "Now, let's try ''italic text''.\n"
148: + "\n"
149: + "Bulleted lists:\n"
150: + "* One\n"
151: + "Or more.\n"
152: + "* Two\n"
153: + "\n"
154: + "** Two.One\n"
155: + "\n"
156: + "*** Two.One.One\n"
157: + "\n"
158: + "* Three\n"
159: + "\n"
160: + "Numbered lists.\n"
161: + "# One\n"
162: + "# Two\n"
163: + "# Three\n"
164: + "## Three.One\n"
165: + "## Three.Two\n"
166: + "## Three.Three\n"
167: + "### Three.Three.One\n"
168: + "# Four\n"
169: + "\n"
170: + "End?\n"
171: + "\n"
172: + "No, let's {{break}} things.\\ {{{ {{{ {{text}} }}} }}}\n"
173: + "\n"
174: + "More breaking.\n"
175: + "\n"
176: + "{{{\n"
177: + "code.}}\n"
178: + "----\n"
179: + "author: [Asser], [Ebu], [JanneJalkanen], [Jarmo|mailto:jarmo@regex.com.au]\n";
180: }
|