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       * Test method for
21       * 'org.portletbridge.portlet.RegexContentRewriter.rewrite(String,
22       * LinkRewriter)'
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       * Test method for
41       * 'org.portletbridge.portlet.RegexContentRewriter.rewrite(String,
42       * LinkRewriter)'
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  }