01: package com.ecyrd.jspwiki.plugin;
02:
03: import java.util.Properties;
04:
05: import com.ecyrd.jspwiki.TestEngine;
06:
07: import junit.framework.Test;
08: import junit.framework.TestCase;
09: import junit.framework.TestSuite;
10:
11: public class InsertPageTest extends TestCase {
12: protected TestEngine testEngine;
13: protected Properties props = new Properties();
14:
15: protected void setUp() throws Exception {
16: props.load(TestEngine.findTestProperties());
17:
18: testEngine = new TestEngine(props);
19: }
20:
21: protected void tearDown() throws Exception {
22: TestEngine.deleteTestPage("ThisPage");
23: TestEngine.deleteTestPage("ThisPage2");
24: TestEngine.deleteTestPage("Test_Page");
25: }
26:
27: public void testRecursive() throws Exception {
28: String src = "[{InsertPage page='ThisPage'}] [{ALLOW view Anonymous}]";
29:
30: testEngine.saveText("ThisPage", src);
31:
32: // Just check that it contains a proper error message; don't bother do HTML
33: // checking.
34: String res = testEngine.getHTML("ThisPage");
35: assertTrue(res.indexOf("Circular reference") != -1);
36: }
37:
38: public void testRecursive2() throws Exception {
39: String src = "[{InsertPage page='ThisPage2'}]";
40: String src2 = "[{InsertPage page='ThisPage'}]";
41:
42: testEngine.saveText("ThisPage", src);
43: testEngine.saveText("ThisPage2", src2);
44:
45: // Just check that it contains a proper error message; don't bother do HTML
46: // checking.
47: assertTrue(testEngine.getHTML("ThisPage").indexOf(
48: "Circular reference") != -1);
49: }
50:
51: public void testMultiInvocation() throws Exception {
52: String src = "[{InsertPage page='ThisPage2'}] [{InsertPage page='ThisPage2'}]";
53: String src2 = "foo[{ALLOW view Anonymous}]";
54:
55: testEngine.saveText("ThisPage", src);
56: testEngine.saveText("ThisPage2", src2);
57:
58: assertTrue("got circ ref", testEngine.getHTML("ThisPage")
59: .indexOf("Circular reference") == -1);
60:
61: assertEquals(
62: "found != 2",
63: "<div style=\"\">foo\n</div> <div style=\"\">foo\n</div>\n",
64: testEngine.getHTML("ThisPage"));
65:
66: }
67:
68: public void testUnderscore() throws Exception {
69: String src = "[{InsertPage page='Test_Page'}]";
70: String src2 = "foo[{ALLOW view Anonymous}]";
71:
72: testEngine.saveText("ThisPage", src);
73: testEngine.saveText("Test_Page", src2);
74:
75: assertTrue("got circ ref", testEngine.getHTML("ThisPage")
76: .indexOf("Circular reference") == -1);
77:
78: assertEquals("found != 1", "<div style=\"\">foo\n</div>\n",
79: testEngine.getHTML("ThisPage"));
80: }
81:
82: public static Test suite() {
83: return new TestSuite(InsertPageTest.class);
84: }
85: }
|