View Javadoc

1   package org.apache.log4j.chainsaw.prefs;
2   
3   import java.net.URL;
4   
5   import junit.framework.TestCase;
6   
7   import com.thoughtworks.xstream.XStream;
8   import com.thoughtworks.xstream.io.xml.DomDriver;
9   
10  public class MRUFileListTest extends TestCase {
11      private static final String[] urls = new String[] {
12              "file://foo.bar.txt",
13              "http://www.cnn.com",
14              "file://uber.log",
15              "http://logging.apache.org/",
16              "https://something.com",
17              "file:///usr/local/tomcat/logs/catalina.out",
18              
19      };
20      
21      public static final String EXAMPLE_XML = "<org.apache.log4j.chainsaw.prefs.MRUFileList>\n" + 
22              "  <fileList>\n" + 
23              "    <url>file:/usr/local/tomcat/logs/catalina.out</url>\n" + 
24              "    <url>https://something.com</url>\n" + 
25              "    <url>http://logging.apache.org/</url>\n" + 
26              "    <url>file://uber.log</url>\n" + 
27              "    <url>http://www.cnn.com</url>\n" + 
28              "  </fileList>\n" + 
29              "  <size>5</size>\n" + 
30              "</org.apache.log4j.chainsaw.prefs.MRUFileList>";
31      
32      MRUFileList fl =  MRUFileList.log4jMRU();
33      
34      
35      public void testMRUFileList() throws Exception {
36          
37          assertEquals(fl.getMRUList().size(), 0);
38          
39          for (int i = 0; i < urls.length; i++) {
40              String url = urls[i];
41              fl.opened(new URL(url));
42          }
43          
44          assertEquals(5, fl.getMRUList().size());
45          assertEquals(new URL(urls[5]), fl.getMRUList().get(0));
46          
47          assertTrue(!fl.getMRUList().contains(new URL(urls[0])));
48          
49      }
50      
51      public void testSerialization() {
52          XStream xstream = new XStream(new DomDriver());
53          String string = xstream.toXML(fl);
54          System.out.println("toXML:");
55          System.out.println(string);
56          
57          MRUFileList newFL =   (MRUFileList) xstream.fromXML(string);
58          assertEquals(5, newFL.getMRUList().size());
59          
60          System.out.println("After object->xml->object:");
61          String string2 = xstream.toXML(newFL);
62          System.out.println(string2);
63          assertEquals(string, string2);
64          
65          
66      }
67  
68  }