001: package com.ecyrd.jspwiki.plugin;
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 com.ecyrd.jspwiki.TestEngine;
010: import com.ecyrd.jspwiki.WikiContext;
011: import com.ecyrd.jspwiki.WikiEngine;
012: import com.ecyrd.jspwiki.WikiPage;
013: import com.ecyrd.jspwiki.providers.ProviderException;
014:
015: public class PluginManagerTest extends TestCase {
016: public static final String NAME1 = "Test1";
017:
018: Properties props = new Properties();
019:
020: WikiEngine engine;
021:
022: WikiContext context;
023:
024: PluginManager manager;
025:
026: public PluginManagerTest(String s) {
027: super (s);
028: }
029:
030: public void setUp() throws Exception {
031: props.load(TestEngine.findTestProperties());
032:
033: engine = new TestEngine(props);
034: context = new WikiContext(engine, new WikiPage(engine,
035: "Testpage"));
036: manager = new PluginManager(engine, props);
037: }
038:
039: public void tearDown() throws ProviderException {
040: engine.deletePage("Testpage");
041: }
042:
043: public void testSimpleInsert() throws Exception {
044: String res = manager
045: .execute(context,
046: "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text=foobar}");
047:
048: assertEquals("foobar", res);
049: }
050:
051: public void testSimpleInsertNoPackage() throws Exception {
052: String res = manager.execute(context,
053: "{INSERT SamplePlugin WHERE text=foobar}");
054:
055: assertEquals("foobar", res);
056: }
057:
058: public void testSimpleInsertNoPackage2() throws Exception {
059: props.setProperty(PluginManager.PROP_SEARCHPATH, "com.foo");
060: PluginManager m = new PluginManager(engine, props);
061: String res = m.execute(context,
062: "{INSERT SamplePlugin2 WHERE text=foobar}");
063:
064: assertEquals("foobar", res);
065: }
066:
067: public void testSimpleInsertNoPackage3() throws Exception {
068: props.setProperty(PluginManager.PROP_SEARCHPATH, "com.foo");
069: PluginManager m = new PluginManager(engine, props);
070: String res = m.execute(context,
071: "{INSERT SamplePlugin3 WHERE text=foobar}");
072:
073: assertEquals("foobar", res);
074: }
075:
076: /** Check that in all cases com.ecyrd.jspwiki.plugin is searched. */
077: public void testSimpleInsertNoPackage4() throws Exception {
078: props.setProperty(PluginManager.PROP_SEARCHPATH,
079: "com.foo,blat.blaa");
080: PluginManager m = new PluginManager(engine, props);
081: String res = m.execute(context,
082: "{INSERT SamplePlugin WHERE text=foobar}");
083:
084: assertEquals("foobar", res);
085: }
086:
087: public void testSimpleInsert2() throws Exception {
088: String res = manager
089: .execute(
090: context,
091: "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text = foobar2, moo=blat}");
092:
093: assertEquals("foobar2", res);
094: }
095:
096: /** Missing closing brace */
097: public void testSimpleInsert3() throws Exception {
098: String res = manager
099: .execute(
100: context,
101: "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text = foobar2, moo=blat");
102:
103: assertEquals("foobar2", res);
104: }
105:
106: public void testQuotedArgs() throws Exception {
107: String res = manager.execute(context,
108: "{INSERT SamplePlugin WHERE text='this is a space'}");
109:
110: assertEquals("this is a space", res);
111: }
112:
113: public void testQuotedArgs2() throws Exception {
114: String res = manager
115: .execute(context,
116: "{INSERT SamplePlugin WHERE text='this \\'is a\\' space'}");
117:
118: assertEquals("this 'is a' space", res);
119: }
120:
121: public void testNumberArgs() throws Exception {
122: String res = manager.execute(context,
123: "{INSERT SamplePlugin WHERE text=15}");
124:
125: assertEquals("15", res);
126: }
127:
128: public void testNoInsert() throws Exception {
129: String res = manager.execute(context,
130: "{SamplePlugin WHERE text=15}");
131:
132: assertEquals("15", res);
133: }
134:
135: // This should be read from tests/etc/ini/jspwiki_module.xml
136: public void testAlias() throws Exception {
137: String res = manager.execute(context, "{samplealias text=15}");
138:
139: assertEquals("15", res);
140: }
141:
142: public void testAlias2() throws Exception {
143: String res = manager.execute(context,
144: "{samplealias2 text=xyzzy}");
145:
146: assertEquals("xyzzy", res);
147: }
148:
149: public void testInitPlugin() throws Exception {
150: manager.execute(context, "{JavaScriptPlugin}");
151:
152: assertTrue(JavaScriptPlugin.c_inited);
153: }
154:
155: public void testParserPlugin() throws Exception {
156: engine.saveText(context, "[{SamplePlugin render=true}]");
157:
158: engine.getHTML("Testpage");
159:
160: assertTrue(SamplePlugin.c_rendered);
161: }
162:
163: public static Test suite() {
164: return new TestSuite(PluginManagerTest.class);
165: }
166: }
|