01: package com.ecyrd.jspwiki.plugin;
02:
03: import java.util.Properties;
04:
05: import junit.framework.TestCase;
06: import junit.framework.TestSuite;
07: import junit.framework.Test;
08:
09: import com.ecyrd.jspwiki.TestEngine;
10: import com.ecyrd.jspwiki.WikiContext;
11: import com.ecyrd.jspwiki.WikiPage;
12:
13: public class UndefinedPagesPluginTest extends TestCase {
14: Properties props = new Properties();
15: TestEngine engine;
16: WikiContext context;
17: PluginManager manager;
18:
19: public UndefinedPagesPluginTest(String s) {
20: super (s);
21: }
22:
23: public void setUp() throws Exception {
24: props.load(TestEngine.findTestProperties());
25:
26: engine = new TestEngine(props);
27:
28: engine.saveText("TestPage", "Reference to [Foobar].");
29: engine.saveText("Foobar", "Reference to [Foobar 2], [Foobars]");
30:
31: context = new WikiContext(engine, new WikiPage(engine,
32: "TestPage"));
33: manager = new PluginManager(engine, props);
34: }
35:
36: public void tearDown() {
37: TestEngine.deleteTestPage("TestPage");
38: TestEngine.deleteTestPage("Foobar");
39: TestEngine.emptyWorkDir();
40: }
41:
42: private String wikitize(String s) {
43: return engine.textToHTML(context, s);
44: }
45:
46: /**
47: * Tests that only correct undefined links are found.
48: * We also check against plural forms here, which should not
49: * be listed as non-existant.
50: */
51: public void testSimpleUndefined() throws Exception {
52: WikiContext context2 = new WikiContext(engine, new WikiPage(
53: engine, "Foobar"));
54:
55: String res = manager
56: .execute(context2,
57: "{INSERT com.ecyrd.jspwiki.plugin.UndefinedPagesPlugin");
58:
59: String exp = "[Foobar 2]\\\\";
60:
61: assertEquals(wikitize(exp), res);
62: }
63:
64: public static Test suite() {
65: return new TestSuite(UndefinedPagesPluginTest.class);
66: }
67: }
|