01: package com.opensymphony.module.sitemesh.html.rules;
02:
03: import junit.framework.TestCase;
04:
05: import java.io.Reader;
06: import java.io.StringReader;
07: import java.io.Writer;
08: import java.io.StringWriter;
09: import java.io.IOException;
10:
11: import com.opensymphony.module.sitemesh.html.HTMLProcessor;
12:
13: public class RegexReplacementTextFilterTest extends TestCase {
14:
15: public void testReplacesTextContentMatchedByRegularExpression()
16: throws IOException {
17: Reader in = new StringReader(
18: "<hello>Today is DATE so hi</hello>");
19: Writer out = new StringWriter();
20:
21: HTMLProcessor processor = new HTMLProcessor(in, out);
22: processor.addTextFilter(new RegexReplacementTextFilter("DATE",
23: "1-jan-2009"));
24:
25: processor.process();
26: assertEquals("<hello>Today is 1-jan-2009 so hi</hello>", out
27: .toString());
28: }
29:
30: public void testAllowsMatchedGroupToBeUsedInSubsitution()
31: throws IOException {
32: Reader in = new StringReader(
33: "<hello>I think JIRA:SIM-1234 is the way forward</hello>");
34: Writer out = new StringWriter();
35:
36: HTMLProcessor processor = new HTMLProcessor(in, out);
37: processor
38: .addTextFilter(new RegexReplacementTextFilter(
39: "JIRA:([A-Z]+\\-[0-9]+)",
40: "<a href='http://jira.opensymhony.com/browse/$1'>$1</a>"));
41:
42: processor.process();
43: assertEquals(
44: "<hello>I think <a href='http://jira.opensymhony.com/browse/SIM-1234'>SIM-1234</a> is the way forward</hello>",
45: out.toString());
46: }
47:
48: }
|