1 package org.portletbridge.portlet;
2
3 import junit.framework.TestCase;
4
5 public class RegexContentRewriterTest extends TestCase {
6
7 public RegexContentRewriterTest(String arg0) {
8 super(arg0);
9 }
10
11 protected void setUp() throws Exception {
12 super.setUp();
13 }
14
15 protected void tearDown() throws Exception {
16 super.tearDown();
17 }
18
19
20
21
22
23
24 public void testRewriteCss() {
25 RegexContentRewriter rewriter = new RegexContentRewriter(
26 "(?:url//((?:'|\")?(.*?)(?:'|\")?//))|(?:@import//s+[^url](?:'|\")?(.*?)(?:'|\")|;|//s+|$)");
27 String string = "" + "@import 'one';\n" + "@import url('two');\n"
28 + "url('three');\n";
29 String result = rewriter.rewrite(null, string, new LinkRewriter() {
30 public String link(String baseUrl, String link) {
31 return "MATCHED_URL(" + link + ")";
32 }
33 });
34 assertEquals("@import 'MATCHED_URL(one)';\n"
35 + "@import url('MATCHED_URL(two)');\n"
36 + "url('MATCHED_URL(three)');\n", result);
37 }
38
39
40
41
42
43
44 public void testRewriteJavascript() {
45 RegexContentRewriter rewriter = new RegexContentRewriter(
46 "open//('([^']*)'|open//(\"([^\"]*)\"");
47 String string = "open('http://www.blah.com')";
48 String result = rewriter.rewrite(null, string, new LinkRewriter() {
49 public String link(String baseUrl, String link) {
50 return "MATCHED_URL(" + link + ")";
51 }
52 });
53 assertEquals("open('MATCHED_URL(http://www.blah.com)')", result);
54 }
55
56 }