1   /*
2    * Copyright 2000-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.apache.jetspeed.util.rewriter;
17  
18  import junit.framework.Test;
19  import junit.framework.TestSuite;
20  import java.io.Reader;
21  import java.io.StringReader;
22  import java.io.FileReader;
23  import java.io.BufferedReader;
24  
25  // Jetspeed imports
26  import org.apache.jetspeed.test.JetspeedTestCase;
27  
28  public class TestFrameRewriter extends JetspeedTestCase 
29  {
30      static public Test suite()
31      {
32          TestSuite suite = new TestSuite(TestFrameRewriter.class);
33          return(suite);
34      }
35  
36      public TestFrameRewriter(String name)
37      {
38          super(name);
39      }
40  
41      ///////////////////////////////////////////////////////////////////////////
42              
43      private String HTML = "";
44  
45      protected void setUp()
46      {
47          StringBuffer buffer = new StringBuffer("");
48          try
49          {
50              FileReader fr = new FileReader("test/testdata/html/frameTest.html");
51              BufferedReader br = new BufferedReader(fr);
52              buffer = new StringBuffer();          //Create the Buffer to store the HTML
53              String currentLine = br.readLine();
54              buffer.append( currentLine );
55              while (currentLine != null) 
56              {
57                  currentLine = br.readLine();
58                  if ( currentLine == null )
59                      continue;
60                  buffer.append( currentLine );       //Add the incoming lines to the buffer
61              }
62              br.close();            //Close the connection                
63          } catch (Exception e)
64          {
65              System.err.println("Exception reading test data:" + e);
66          }
67          HTML = buffer.toString();
68      }
69  
70      protected void tearDown()
71      {
72      }
73  
74  
75      ///////////////////////////////////////////////////////////////////////////
76  
77      public void testFrames()
78      {
79          Reader reader = null;
80  
81          try 
82          {
83                      
84              reader = new StringReader(HTML);                                           
85              HTMLRewriter rewriter = new HTMLRewriter();
86              String result = rewriter.rewrite(reader, null);
87              System.out.println(result);
88              reader.close();
89              reader = null;
90  
91          } catch (Exception e) 
92          {
93              System.err.println("Exception occurred:" + e.toString());
94              e.printStackTrace();
95          }
96          finally
97          {
98              try
99              {
100                 if (null != reader)
101                     reader.close();
102             }
103             catch (Exception e)
104             {}
105         }
106     }
107 
108     ///////////////////////////////////////////////////////////////////////////
109 
110     static public void main(String[] argv)
111     {
112         String[] testCaseName = {TestFrameRewriter.class.getName()};
113         junit.swingui.TestRunner.main(testCaseName);
114     }
115 
116 }