1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.portletbridge.rewriter;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import junit.framework.TestCase;
22  
23  import org.portletbridge.PortletBridgeException;
24  import org.portletbridge.UrlRewriter;
25  
26  /***
27   * @author JMcCrindle
28   */
29  public class RegExStyleSheetRewriterTest extends TestCase {
30  
31      /*
32       * @see TestCase#setUp()
33       */
34      protected void setUp() throws Exception {
35          super.setUp();
36      }
37      
38      /*
39       * @see TestCase#tearDown()
40       */
41      protected void tearDown() throws Exception {
42          super.tearDown();
43      }
44  
45      /***
46       * Constructor for RegExStyleSheetRewriterTest.
47       * @param name
48       */
49      public RegExStyleSheetRewriterTest(String name) {
50          super(name);
51      }
52  
53      public void testRewrite() throws PortletBridgeException {
54          
55          final List urls = new ArrayList();
56          
57          RegExStyleSheetRewriter rewriter = new RegExStyleSheetRewriter(new UrlRewriter() {
58              public String rewrite(String url) {
59                  urls.add(url);
60                  System.out.println(url);
61                  return "" + urls.size();
62              }
63          });
64          
65          String rewritten = rewriter.rewrite("@import url(\"blah.css\")\n" +
66                  "body {\n" +
67                  "background-color: #FFF;\n" +
68                  "background-image: url(/Design/graphics/Reg_default/one.png);\n" +
69                  "background-image: url(\"/Design/graphics/Reg_default/two.png\");\n" +
70                  "background-repeat: repeat-y;\n" +
71                  "}");
72          
73          assertEquals(3, urls.size());
74          
75          System.out.println(rewritten);
76          
77      }
78  
79      public void testRewriteImports() throws PortletBridgeException {
80          
81          final List urls = new ArrayList();
82          
83          RegExStyleSheetRewriter rewriter = new RegExStyleSheetRewriter(new UrlRewriter() {
84              public String rewrite(String url) {
85                  urls.add(url);
86                  System.out.println("url");
87                  return "" + urls.size();
88              }
89          });
90          
91          StringBuffer rewritten = rewriter.rewriteImports(new StringBuffer("@import 'blah.css'\n" +
92                  "body {\n" +
93                  "background-color: #FFF;\n" +
94                  "background-image: url(/Design/graphics/Reg_default/red_left_edge.png);\n" +
95                  "background-repeat: repeat-y;\n" +
96                  "}"));
97          
98          assertEquals(1, urls.size());
99          
100         System.out.println(rewritten);
101         
102     }
103 
104 }