01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.testutil.AbstractRegex;
07:
08: public class WidgetRootTest extends AbstractRegex {
09: private WikiPage rootPage;
10:
11: protected void setUp() throws Exception {
12: rootPage = InMemoryPage.makeRoot("RooT");
13: }
14:
15: public void testVariablesOneTheRootPage() throws Exception {
16: WikiPage root = InMemoryPage.makeRoot("RooT");
17: PageData data = root.getData();
18: data.setContent("!define v1 {Variable #1}\n");
19: root.commit(data);
20: WikiPage page = root.getPageCrawler().addPage(root,
21: PathParser.parse("SomePage"),
22: "!define v2 {blah}\n${v1}\n");
23: data = page.getData();
24: assertEquals("Variable #1", data.getVariable("v1"));
25: }
26:
27: public void testVariablesFromSystemProperties() throws Exception {
28: WikiPage root = InMemoryPage.makeRoot("RooT");
29: PageData data = root.getData();
30: System.getProperties().setProperty("widgetRootTestKey",
31: "widgetRootTestValue");
32: root.commit(data);
33: WikiPage page = root.getPageCrawler().addPage(root,
34: PathParser.parse("SomePage"),
35: "!define v2 {blah}\n${v1}\n");
36: data = page.getData();
37: assertEquals("widgetRootTestValue", data
38: .getVariable("widgetRootTestKey"));
39: }
40:
41: public void testProcessLiterals() throws Exception {
42: WidgetRoot root = new WidgetRoot("", rootPage);
43: assertEquals(0, root.getLiterals().size());
44: String result = root
45: .processLiterals("With a !-literal-! in the middle");
46: assertNotSubString("!-", result);
47: assertEquals(1, root.getLiterals().size());
48: assertEquals("literal", root.getLiteral(0));
49: }
50:
51: public void testProcessLiteralsCalledWhenConstructed()
52: throws Exception {
53: WidgetRoot root = new WidgetRoot(
54: "With !-another literal-! in the middle", rootPage);
55: assertEquals(1, root.getLiterals().size());
56: assertEquals("another literal", root.getLiteral(0));
57: }
58:
59: public void testLiteralsInConstructionAndAfterwards()
60: throws Exception {
61: WidgetRoot root = new WidgetRoot("the !-first-! literal",
62: rootPage);
63: String result = root.processLiterals("the !-second-! literal");
64:
65: assertEquals("the first literal", root.render());
66: assertEquals("the !lit(1) literal", result);
67: assertEquals(2, root.getLiterals().size());
68: assertEquals("first", root.getLiteral(0));
69: assertEquals("second", root.getLiteral(1));
70: }
71: }
|