01: package com.ecyrd.jspwiki.plugin;
02:
03: import java.io.IOException;
04: import java.io.StringReader;
05: import java.util.Properties;
06:
07: import javax.servlet.ServletException;
08:
09: import junit.framework.Test;
10: import junit.framework.TestCase;
11: import junit.framework.TestSuite;
12:
13: import com.ecyrd.jspwiki.NoRequiredPropertyException;
14: import com.ecyrd.jspwiki.TestEngine;
15: import com.ecyrd.jspwiki.WikiContext;
16: import com.ecyrd.jspwiki.WikiPage;
17: import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser;
18: import com.ecyrd.jspwiki.parser.MarkupParser;
19: import com.ecyrd.jspwiki.parser.WikiDocument;
20: import com.ecyrd.jspwiki.render.WikiRenderer;
21: import com.ecyrd.jspwiki.render.XHTMLRenderer;
22:
23: public class CounterPluginTest extends TestCase {
24: Properties props = new Properties();
25: TestEngine testEngine;
26:
27: public CounterPluginTest(String s) {
28: super (s);
29: }
30:
31: public void setUp() throws Exception {
32: props.load(TestEngine.findTestProperties());
33:
34: testEngine = new TestEngine(props);
35: }
36:
37: public void tearDown() {
38: }
39:
40: private String translate(String src) throws IOException,
41: NoRequiredPropertyException, ServletException {
42: WikiContext context = new WikiContext(testEngine, new WikiPage(
43: testEngine, "TestPage"));
44:
45: MarkupParser p = new JSPWikiMarkupParser(context,
46: new StringReader(src));
47:
48: WikiDocument dom = p.parse();
49:
50: WikiRenderer r = new XHTMLRenderer(context, dom);
51:
52: return r.getString();
53: }
54:
55: public void testSimpleCount() throws Exception {
56: String src = "[{Counter}], [{Counter}]";
57:
58: assertEquals("1, 2", translate(src));
59: }
60:
61: public void testSimpleVar() throws Exception {
62: String src = "[{Counter}], [{Counter}], [{$counter}]";
63:
64: assertEquals("1, 2, 2", translate(src));
65: }
66:
67: public void testTwinVar() throws Exception {
68: String src = "[{Counter}], [{Counter name=aa}], [{$counter-aa}]";
69:
70: assertEquals("1, 1, 1", translate(src));
71: }
72:
73: public static Test suite() {
74: return new TestSuite(CounterPluginTest.class);
75: }
76: }
|