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 java.util.regex.Pattern;
06:
07: import fitnesse.wiki.InMemoryPage;
08: import fitnesse.wiki.PageCrawler;
09: import fitnesse.wiki.PathParser;
10: import fitnesse.wiki.WikiPage;
11:
12: public class RandomVariableWidgetTest extends AbstractWidget {
13: private WikiPage root;
14:
15: private WikiPage parent;
16:
17: private PageCrawler crawler;
18:
19: public void setUp() throws Exception {
20: root = InMemoryPage.makeRoot("RooT");
21: crawler = root.getPageCrawler();
22: parent = crawler.addPage(root, PathParser.parse("PareNt"),
23: "parent");
24: }
25:
26: public void testRegExSimpleMatch() throws Exception {
27: assertTrue("Match 1", Pattern.matches(
28: RandomVariableWidget.REGEXP, "!random"));
29: }
30:
31: public void testSimpleRendering() throws Exception {
32: RandomVariableWidget randomWidget = new RandomVariableWidget(
33: null, "!random");
34: String randomValue = randomWidget.render().trim();
35: assertTrue(String.valueOf(randomValue.length()), randomValue
36: .length() == 11);
37: }
38:
39: public void testRenderingWithSurroundingText() throws Exception {
40: WikiPage child = crawler.addPage(parent, PathParser
41: .parse("ChiLd"), "before !random after");
42: String childHtml = child.getData().getHtml();
43: assertTrue(childHtml, childHtml.startsWith("before") == true);
44: assertTrue(childHtml, childHtml.endsWith("after") == true);
45: }
46:
47: public void testRenderingWithConjointText() throws Exception {
48: WikiPage child = crawler.addPage(parent, PathParser
49: .parse("ChiLd"), "!randomafter");
50: String childHtml = child.getData().getHtml();
51: assertTrue(childHtml, childHtml.endsWith("after") == true);
52: assertTrue(childHtml, childHtml.indexOf(" ") == -1);
53: }
54:
55: public void testRenderingWithMultilineSurroundingText()
56: throws Exception {
57: String content = "before !random after\r\n!random \r\n!random \r\nsomething !random";
58: WikiPage child = crawler.addPage(parent, PathParser
59: .parse("ChiLd"), content);
60: String childHtml = child.getData().getHtml();
61: assertTrue(childHtml, childHtml.startsWith("before") == true);
62: assertTrue(childHtml, childHtml.indexOf("something") != -1);
63: }
64:
65: protected String getRegexp() {
66: return RandomVariableWidget.REGEXP;
67: }
68: }
|