1   /*
2    * Created on 29.09.2004
3    *
4    */
5   package org.w3c.tidy.servlet.util;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  import junit.framework.TestCase;
11  
12  
13  /***
14   * 
15   * 
16   */
17  public class HTMLEncodeTest extends TestCase
18  {
19  
20      public void validate(String expected, String input)
21      {
22          String r = HTMLEncode.encode(input);
23          assertEquals(expected, r);
24      }
25  
26      public void testEncode() throws Exception
27      {
28          validate("", null);
29          validate(">", ">");
30          validate("&lt;", "<");
31          validate("&lt;&gt;", "<>");
32          validate("&lt;\n&gt;", "<\n>");
33          validate("&lt;EOL", "<EOL");
34      }
35  
36      public void validateHREF(String expected, String[] input)
37      {
38          String r = HTMLEncode.encodeQuery("", input);
39          assertEquals(expected, r);
40      }
41  
42      public void testEncodeHREF() throws Exception
43      {
44          validateHREF("", null);
45          validateHREF("?p1", new String[]{"p1"});
46          validateHREF("?p1=p1v", new String[]{"p1", "p1v"});
47          validateHREF("?p1=p1v&p2", new String[]{"p1", "p1v", "p2"});
48      }
49  
50      public void validateHREFMap(String expected, Map input)
51      {
52          String r = HTMLEncode.encodeHREFQuery("", input, false);
53  
54          // @todo fails on ibm 1.3 jdk, since order of parameters is different
55          assertEquals(expected, r);
56      }
57  
58      public void testEncodeHREFMap() throws Exception
59      {
60          HashMap params = new HashMap();
61          params.put("np1", "vp1");
62          validateHREFMap("?np1=vp1", params);
63          params.put("np2", "vp2");
64          validateHREFMap("?np1=vp1&np2=vp2", params);
65      }
66  }