1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/tests/test/org/dbforms/util/TestUtil.java,v 1.9 2005/09/14 19:43:22 hkollmann Exp $
3    * $Revision: 1.9 $
4    * $Date: 2005/09/14 19:43:22 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.util;
25  
26  
27  
28  /***
29   *  Test the Util.java class
30   *
31   * @author     epugh
32   * @created    May 3, 2002
33   */
34  public class TestUtil extends AbstractTestCase {
35     /***
36      * DOCUMENT ME!
37      *
38      * @throws Exception DOCUMENT ME!
39      */
40     public void testDecode() throws Exception {
41        String SOURCE  = "http://www.sun.com?some bogus=value";
42        String ENCODED = "http%3A%2F%2Fwww.sun.com%3Fsome+bogus%3Dvalue";
43  
44        String s = ENCODED;
45        s = Util.decode(s, null);
46        assertTrue("Encoded String:" + s, s.equals(SOURCE));
47  
48        s = null;
49        s = Util.encode(s, null);
50        assertTrue("S must be null", s == null);
51     }
52  
53  
54     /***
55      * DOCUMENT ME!
56      *
57      * @throws  Exception  DOCUMENT ME!
58      */
59     public void testEncode() throws Exception {
60        String SOURCE = "http://www.sun.com?some bogus=value";
61  
62        String ENCODED = "http%3A%2F%2Fwww.sun.com%3Fsome+bogus%3Dvalue";
63  
64        String s = SOURCE;
65  
66        s = Util.encode(s, null);
67  
68        assertTrue("Encoded String:" + s, s.equals(ENCODED));
69  
70        s = null;
71  
72        s = Util.encode(s, null);
73  
74        assertTrue("S must be null", s == null);
75     }
76  
77  
78     /***
79      * DOCUMENT ME!
80      *
81      * @throws Exception DOCUMENT ME!
82      */
83     public void testEncodeDecode() throws Exception {
84        String s = "0%3A7%3A%8A%E1%92%86%82%C9%82%A8%82%A9%82%C8%82%A2-1%3A8%3A%82%AA%82%F1%82%BF%82%E3%82%A4%82%AA%82%C8%82%A2";
85        s = Util.decode(s, "Shift-JIS");
86        System.out.println(s.length() + " " + s);
87        s = "0%3A7%3A%E7%9C%BC%E4%B8%AD%E3%81%AB%E3%81%8A%E3%81%8B%E3%81%AA%E3%81%84-1%3A8%3A%E3%81%8C%E3%82%93%E3%81%A1%E3%82%85%E3%81%86%E3%81%8C%E3%81%AA%E3%81%84";
88        s = Util.decode(s, "UTF-8");
89        System.out.println(s.length() + " " + s);
90     }
91  
92  
93     /***
94      *  A unit test for JUnit
95      *
96      * @exception  Exception  Description of the Exception
97      */
98     public void testIsNull() throws Exception {
99        boolean result = Util.isNull((String) null);
100       assertTrue("Must be null", result);
101       result = Util.isNull("");
102       assertTrue("Must be null", result);
103       result = Util.isNull("not null");
104       assertTrue("Must not be null", !result);
105    }
106 
107 
108 }