001: package com.ecyrd.jspwiki;
002:
003: import junit.framework.*;
004: import java.io.*;
005: import java.util.*;
006: import org.apache.log4j.*;
007:
008: public class VariableManagerTest extends TestCase {
009: VariableManager m_variableManager;
010: WikiContext m_context;
011:
012: static final String PAGE_NAME = "TestPage";
013:
014: public VariableManagerTest(String s) {
015: super (s);
016: }
017:
018: public void setUp() throws Exception {
019: Properties props = new Properties();
020: try {
021: props.load(TestEngine.findTestProperties());
022: PropertyConfigurator.configure(props);
023:
024: m_variableManager = new VariableManager(props);
025: TestEngine testEngine = new TestEngine(props);
026: m_context = new WikiContext(testEngine, new WikiPage(
027: testEngine, PAGE_NAME));
028:
029: } catch (IOException e) {
030: }
031: }
032:
033: public void tearDown() {
034: }
035:
036: public void testIllegalInsert1() throws Exception {
037: try {
038: m_variableManager.parseAndGetValue(m_context, "");
039: fail("Did not fail");
040: } catch (IllegalArgumentException e) {
041: // OK.
042: }
043: }
044:
045: public void testIllegalInsert2() throws Exception {
046: try {
047: m_variableManager.parseAndGetValue(m_context, "{$");
048: fail("Did not fail");
049: } catch (IllegalArgumentException e) {
050: // OK.
051: }
052: }
053:
054: public void testIllegalInsert3() throws Exception {
055: try {
056: m_variableManager.parseAndGetValue(m_context, "{$pagename");
057: fail("Did not fail");
058: } catch (IllegalArgumentException e) {
059: // OK.
060: }
061: }
062:
063: public void testIllegalInsert4() throws Exception {
064: try {
065: m_variableManager.parseAndGetValue(m_context, "{$}");
066: fail("Did not fail");
067: } catch (IllegalArgumentException e) {
068: // OK.
069: }
070: }
071:
072: public void testNonExistantVariable() {
073: try {
074: m_variableManager.parseAndGetValue(m_context,
075: "{$no_such_variable}");
076: fail("Did not fail");
077: } catch (NoSuchVariableException e) {
078: // OK.
079: }
080: }
081:
082: public void testPageName() throws Exception {
083: String res = m_variableManager.getValue(m_context, "pagename");
084:
085: assertEquals(PAGE_NAME, res);
086: }
087:
088: public void testPageName2() throws Exception {
089: String res = m_variableManager.parseAndGetValue(m_context,
090: "{$ pagename }");
091:
092: assertEquals(PAGE_NAME, res);
093: }
094:
095: public void testMixedCase() throws Exception {
096: String res = m_variableManager.parseAndGetValue(m_context,
097: "{$PAGeNamE}");
098:
099: assertEquals(PAGE_NAME, res);
100: }
101:
102: public void testExpand1() throws Exception {
103: String res = m_variableManager.expandVariables(m_context,
104: "Testing {$pagename}...");
105:
106: assertEquals("Testing " + PAGE_NAME + "...", res);
107: }
108:
109: public void testExpand2() throws Exception {
110: String res = m_variableManager.expandVariables(m_context,
111: "{$pagename} tested...");
112:
113: assertEquals(PAGE_NAME + " tested...", res);
114: }
115:
116: public void testExpand3() throws Exception {
117: String res = m_variableManager.expandVariables(m_context,
118: "Testing {$pagename}, {$applicationname}");
119:
120: assertEquals("Testing " + PAGE_NAME + ", JSPWiki", res);
121: }
122:
123: public void testExpand4() throws Exception {
124: String res = m_variableManager.expandVariables(m_context,
125: "Testing {}, {{{}");
126:
127: assertEquals("Testing {}, {{{}", res);
128: }
129:
130: public static Test suite() {
131: return new TestSuite(VariableManagerTest.class);
132: }
133: }
|